def test_includes(self, mock_exec): testutils.create_dir_struct({ 'simple.file': None, 'simple folder': {}, 'special * folder': {}, r'''!"#$%&'()*+,-.012:;<=>?@ABC[\]^_`abc{|}~''': None }) sync = rsync.rsync() sync.sync(rsync.Path(context.TARGET_DIR), [ 'simple.file', 'simple folder', 'special * folder', 'not found * folder', r'test\ \*\ folder/*.pattern', r'''!"#$%&'()*+,-.012:;<=>?@ABC[\]^_`abc{|}~''', ]) cmd = mock_exec.call_args[0][0] assert b'simple.file' in cmd assert b"'simple folder'" in cmd assert b"'special * folder'" in cmd assert b'not found * folder' in cmd assert rb'test\ \*\ folder/*.pattern' in cmd assert b"'!" #$%&' "'" '()*+,-.012:;<=>?@ABC[\]^_`abc{|}~'" in cmd
def test_success(self): sync = rsync.rsync() sync.dry_run = False target = rsync.Path(context.TMP_DIR) status = sync.sync(target, [context.TEST_DIR]) assert status.exit_code == 0
def test_link_dest(self, mock_exec): sync = rsync.rsync() sync.sync(rsync.Path('/'), [], link_dest='/special * path/previous_backup') cmd = mock_exec.call_args[0][0] assert b'--delete' in cmd assert b"--link-dest '/special * path/previous_backup'" in cmd
def test_options_original(self, mock_exec): sync = rsync.rsync() sync.sync(rsync.Path('/'), []) cmd = mock_exec.call_args[0][0] assert b'--acls' in cmd assert b'--xattrs' in cmd assert b'--prune-empty-dirs' in cmd assert b"--out-format '%t %i %n'" in cmd assert b'--dry-run' in cmd
def test_ssh_wrapper(self): sync = rsync.rsync() sync.ssh_bin = '{} root {}'.format(const.SSH_WRAPPER_SCRIPT, sync.ssh_bin) sync.dry_run = False # Send the files target = rsync.Path(context.TMP_DIR, context.SSH_HOST) status = sync.sync(target, [context.DATA_DIR]) assert status.exit_code == 0
def test_excludes(self, mock_exec): sync = rsync.rsync() sync.sync(rsync.Path(context.TARGET_DIR), ['/'], [ '/tmp', 'simple folder', '*.mkv', ]) cmd = mock_exec.call_args[0][0] assert b"--exclude /tmp" in cmd assert b"--exclude 'simple folder'" in cmd assert b"--exclude '*.mkv'" in cmd
def test_remote_simple(self): sync = rsync.rsync() sync.dry_run = False # Define the structure we expect after synchronizing expected_data = self.data_dir_struct del expected_data['test.dir']['dir2'] # Send the files target = rsync.Path(context.TMP_DIR, context.SSH_HOST) sync.sync(target, [context.TEST_DIR, context.TEST_FILE], excludes=['**/dir2/.gitkeep']) # Get and compare the structure of our sync target synced_data = testutils.get_dir_struct(self.real_target) assert expected_data == synced_data
def test_remote_special_char(self): sync = rsync.rsync() sync.dry_run = False # Define the structure we expect after synchronizing expected_data = self.data_dir_struct del expected_data[b'test.dir'] del expected_data[b'test.file'] # Send the files target = rsync.Path(context.TMP_DIR, context.SSH_HOST) sync.sync(target, [context.SPECIAL_FILE.decode()]) # Get and compare the structure of our sync target synced_data = test_utils.get_dir_struct(self.real_target.encode()) self.assertEqual(expected_data, synced_data)
def test_local_simple(self): sync = rsync.rsync() sync.dry_run = False # Define the structure we expect after synchronizing expected_data = self.data_dir_struct del expected_data[b'test.dir'][b'dir2'] del expected_data[context.SPECIAL_NAME] # Send the files target = rsync.Path(context.TMP_DIR) sync.sync(target, [context.TEST_DIR, context.TEST_FILE], excludes=['**/dir2/.gitkeep']) # Get and compare the structure of our sync target synced_data = test_utils.get_dir_struct(self.real_target.encode()) self.assertEqual(expected_data, synced_data)
def test_options_modified(self, mock_exec): sync = rsync.rsync() sync.acls = False sync.xattrs = False sync.prune_empty_dirs = False sync.out_format = "%t %i %f %''b" sync.dry_run = False sync.sync(rsync.Path('/'), []) cmd = mock_exec.call_args[0][0] assert b'--acls' not in cmd assert b'--xattrs' not in cmd assert b'--prune-empty-dirs' not in cmd assert '--out-format {}'.format( shlex.quote("%t %i %f %''b")).encode() in cmd assert b'--dry-run' not in cmd
def test_target_local(self, mock_exec): sync = rsync.rsync() sync.sync(rsync.Path('/backup-target'), []) cmd = mock_exec.call_args[0][0] assert cmd.endswith(b'/backup-target')