def test_get_modified_items_mult_dev_results(self): def mock_list_files(*args, **kwargs): linfo = LsInfo(directories=[], files=[self.file1, self.file2]) out_dict = {self.dev1_id: linfo, self.dev2_id: linfo} return out_dict with mock.patch.object(self.fss_api, 'list_files', side_effect=mock_list_files) as m: out_dict = self.fss_api.get_modified_items(self.target, '/a/path/', self.file1.last_modified - 1) expected_out_dict = { self.dev1_id: LsInfo(files=[self.file1], directories=[]), self.dev2_id: LsInfo(files=[self.file1], directories=[]) } self.assertDictEqual(expected_out_dict, out_dict)
def test_parse(self): fss_api = mock.Mock() dev_id = 'my_dev_id' file1 = FileInfo(fss_api, dev_id, '/a/path/file1.txt', 1436276773, 7989, "967FDA522517B9CE0C3E056EDEB485BB", 'md5') file2 = FileInfo(fss_api, dev_id, '/a/path/file2.py', 1434377919, 181, "DEA17715739E46079C1A6DDCB38344DF", 'md5') dir1 = DirectoryInfo(fss_api, dev_id, '/a/path/dir', 1436203917) linfo = LsCommand.parse_response(ET.fromstring(LS_BLOCK), device_id=dev_id, fssapi=fss_api) self.assertEqual(linfo, LsInfo(directories=[dir1], files=[file1, file2]))
def test_list_contents(self): file1 = FileInfo(self.fss_api, self.dev_id, '/a/path/file1.txt', 1436276773, 7989, "967FDA522517B9CE0C3E056EDEB485BB", 'md5') file2 = FileInfo(self.fss_api, self.dev_id, '/a/path/file1.txt', 1436276773, 7989, "967FDA522517B9CE0C3E056EDEB485BB", 'md5') self.fss_api.list_files.side_effect = ({self.dev_id: LsInfo([], [file1, file2])},) dir1 = DirectoryInfo(self.fss_api, self.dev_id, '/a/path/dir1', 1436276773) dirs, files = dir1.list_contents() self.assertEqual(0, len(dirs)) self.assertListEqual([file1, file2], files) self.assertEqual(1, self.fss_api.list_files.call_count) call_name, call_args, call_kwargs = self.fss_api.list_files.mock_calls[0] self.assertEqual(call_args[0]._device_id, self.dev_id) self.assertEqual(call_args[1], '/a/path/dir1')
def test_list_dir(self): fsr = FileSystemResponse() fsr.add_device_block(self.dev1_id, LS_BLOCK) fsr.add_device_block(self.dev2_id, LS_BLOCK) self.prep_sci_response(fsr) list_dict = self.fss_api.list_files(self.target, '/a/path/') files_dev1 = [self.file1, self.file2] dirs_dev1 = [self.dir1] file1 = self.clone_file(self.file1) file1.device_id = self.dev2_id file2 = self.clone_file(self.file2) file2.device_id = self.dev2_id files_dev2 = [file1, file2] dir1 = self.clone_dir(self.dir1) dir1.device_id = self.dev2_id dirs_dev2 = [dir1] expected_dict = {self.dev1_id: LsInfo(dirs_dev1, files_dev1), self.dev2_id: LsInfo(dirs_dev2, files_dev2)} self.assertDictEqual(expected_dict, list_dict)
def mock_list_files(*args, **kwargs): linfo = LsInfo(directories=[], files=[self.file1]) out_dict = {self.dev1_id: linfo, self.dev2_id: self.errinfo} return out_dict
def mock_list_files(*args, **kwargs): linfo = LsInfo(directories=[self.dir1], files=[]) out_dict = {self.dev1_id: linfo, self.dev2_id: LsInfo([], [])} return out_dict