Пример #1
0
 def test_rename_not_both_subdirs_exist(self):
     check_call("mkdir -p canonical/sclupture", shell=True)
     with self.assertRaises(ValueError) as ar:
         main(['backup.json', 'rename', 'basic:', 'sclupture', 'sculpture'])
     self.assertIn("Directory 'cache/sclupture/' is not present",
                   str(ar.exception))
     self.assertFalse(os.path.exists('canonical/sculpture'))
Пример #2
0
 def test_sync_thorough(self):
     main(['backup.json', 'sync', 'basic', '--thorough'])
     output = sys.stdout.getvalue()
     lines = [l for l in output.split('\n') if l.startswith('rsync')]
     self.assertEqual(lines, [
         'rsync --dry-run --checksum --archive --verbose --delete canonical/ cache/',
     ])
Пример #3
0
 def test_sync_dry_run(self):
     main(['backup.json', 'sync', 'basic:'])
     self.assertFalse(os.path.exists('cache/thing'))
     output = sys.stdout.getvalue()
     self.assertEqual(
         output.split('\n')[0],
         'rsync --dry-run --archive --verbose --delete canonical/ cache/')
     self.assertIn('DRY RUN', output)
Пример #4
0
 def test_list(self):
     main(['backup.json', 'list'])
     output = sys.stdout.getvalue()
     self.assertEqual(output.split('\n'), [
         'basic: canonical => cache',
         'other: canonical3 => cache3',
         '',
     ])
Пример #5
0
 def test_sync_multiple_streams(self):
     main(['backup.json', 'sync', 'other', 'basic'])
     output = sys.stdout.getvalue()
     lines = [l for l in output.split('\n') if l.startswith('rsync')]
     self.assertEqual(lines, [
         'rsync --dry-run --archive --verbose --delete canonical3/ cache3/',
         'rsync --dry-run --archive --verbose --delete canonical/ cache/',
     ])
Пример #6
0
 def test_sync_apply(self):
     main(['backup.json', 'sync', 'basic:', '--apply'])
     self.assertTrue(os.path.exists('cache/thing'))
     output = sys.stdout.getvalue()
     self.assertEqual(
         output.split('\n')[:4], [
             'rsync --archive --verbose --delete canonical/ cache/',
             'sending incremental file list', 'thing', ''
         ])
Пример #7
0
 def test_sync_subdirectory(self):
     check_call("mkdir -p canonical/subdir", shell=True)
     check_call("mkdir -p cache/subdir", shell=True)
     check_call("touch canonical/subdir/stuff", shell=True)
     main(['backup.json', 'sync', 'basic:subdir', '--apply'])
     self.assertTrue(os.path.exists('cache/subdir/stuff'))
     self.assertFalse(os.path.exists('cache/thing'))
     output = sys.stdout.getvalue()
     self.assertEqual(
         output.split('\n')[:4], [
             'rsync --archive --verbose --delete canonical/subdir/ cache/subdir/',
             'sending incremental file list', 'stuff', ''
         ])
Пример #8
0
 def test_sync_with_spaces_in_dirnames(self):
     check_call("mkdir -p 'can onical'", shell=True)
     check_call("mkdir -p 'ca che'", shell=True)
     router = {
         'spaced': {
             'from': 'can onical',
             'to': 'ca che',
         },
     }
     with open('backup.json', 'w') as f:
         f.write(json.dumps(router))
     main(['backup.json', 'sync', 'spaced'])
     output = sys.stdout.getvalue()
     lines = [l for l in output.split('\n') if l.startswith('rsync')]
     self.assertEqual(lines, [
         'rsync --dry-run --archive --verbose --delete "can onical/" "ca che/"',
     ])
Пример #9
0
 def test_failure(self):
     with self.assertRaises(SystemExit):
         main(['backup.json'])
Пример #10
0
 def test_rename(self):
     check_call("mkdir -p canonical/sclupture", shell=True)
     check_call("mkdir -p cache/sclupture", shell=True)
     main(['backup.json', 'rename', 'basic:', 'sclupture', 'sculpture'])
     self.assertTrue(os.path.exists('canonical/sculpture'))
     self.assertTrue(os.path.exists('cache/sculpture'))
Пример #11
0
 def test_sync_stream_does_not_exist(self):
     with self.assertRaises(ValueError) as ar:
         main(['backup.json', 'sync', 'notfound', '--apply'])
     self.assertIn("Directory 'canonical2/' is not present",
                   str(ar.exception))