1 from unittest import TestCase, skipIf
3 from StringIO import StringIO
4 from htsworkflow.automation.solexa import is_runfolder
7 from htsworkflow.automation import copier
8 BENDERJAB_UNAVAILABLE = False
9 except ImportError as e:
10 BENDERJAB_UNAVAILABLE = True
12 @skipIf(BENDERJAB_UNAVAILABLE, "Can't test copier daemon without a working benderjab")
13 class testCopier(TestCase):
14 def test_empty_config(self):
15 cfg = StringIO("""[fake]
18 bot = copier.CopierBot('fake', configfile=cfg)
19 self.failUnlessRaises(RuntimeError, bot.read_config)
21 def test_full_config(self):
22 cfg = StringIO("""[copier]
23 jid: copier@example.fake
25 authorized_users: user1@example.fake user2@example.fake
26 rsync_password_file: ~/.sequencer
27 rsync_sources: rsync://localhost/tmp/sequencer_source rsync://user@server:1234/other_sequencer
28 rsync_destination: /tmp/sequencer_destination
29 notify_users: user3@example.fake
33 c = copier.CopierBot("copier", configfile=cfg)
36 self.failUnlessEqual(c.jid, 'copier@example.fake')
37 self.failUnlessEqual(c.cfg['password'], 'badpassword')
38 self.failUnlessEqual(len(c.authorized_users), 2)
39 self.failUnlessEqual(c.authorized_users[0], 'user1@example.fake')
40 self.failUnlessEqual(c.authorized_users[1], 'user2@example.fake')
41 self.failUnlessEqual(c.rsync.source_base_list[0],
42 'rsync://localhost/tmp/sequencer_source/')
43 self.failUnlessEqual(c.rsync.dest_base, '/tmp/sequencer_destination')
44 self.failUnlessEqual(len(c.notify_users), 1)
45 self.failUnlessEqual(c.notify_users[0], 'user3@example.fake')
46 self.failUnlessEqual(c.validate_url('rsync://other/tmp'), None)
47 self.failUnlessEqual(c.validate_url('http://localhost/tmp'), None)
48 # In the rsync process the URL gets a trailing '/' added to it
49 # But in the bot config its still slash-less.
50 # It is debatable when to add the trailing slash.
52 c.validate_url('rsync://localhost/tmp/sequencer_source'),
53 'rsync://localhost/tmp/sequencer_source')
55 c.validate_url('rsync://localhost/tmp/sequencer_source/'),
56 'rsync://localhost/tmp/sequencer_source/')
58 c.validate_url('rsync://localhost/tmp/sequencer_source/bleem'),
59 'rsync://localhost/tmp/sequencer_source/bleem')
61 c.validate_url('rsync://user@server:1234/other_sequencer'),
62 'rsync://user@server:1234/other_sequencer')
65 def test_dirlist_filter(self):
67 test our dir listing parser
69 # everyone should have a root dir, and since we're not
70 # currently writing files... it should all be good
71 r = copier.rsync('/', '/', '/')
74 'drwxrwxr-x 0 2007/12/29 12:34:56 071229_USI-EAS229_001_FC1234\n',
75 '-rwxrw-r-- 123268 2007/12/29 17:39:31 2038EAAXX.rtf\n',
76 '-rwxrw-r-- 6 2007/12/29 15:10:29 New Text Document.txt\n',
79 result = r.list_filter(listing)
80 self.failUnlessEqual(len(result), 1)
81 self.failUnlessEqual(result[0][-1], '4')
85 from unittest2 import TestSuite, defaultTestLoader
87 suite.addTests(defaultTestLoader.loadTestsFromTestCase(testCopier))
91 if __name__ == "__main__":
92 from unittest2 import main
93 main(defaultTest="suite")