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_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 setUp(self): HttpTestBase.setUp(self) self.fss_api = self.dc.get_fss_api() self.sci_api = mock.Mock() self.fss_api._sci_api = self.sci_api self.target = AllTarget() self.dev1_id = '00000000-00000000-18A905FF-FF2F1BBD' self.dev2_id = '00000000-00000000-18A905FF-FF2F1BBE' # Create some file, directory, and error info objects to use in tests self.file1 = FileInfo(self.fss_api, self.dev1_id, '/a/path/file1.txt', 1436276773, 7989, "967FDA522517B9CE0C3E056EDEB485BB", 'md5') self.file2 = FileInfo(self.fss_api, self.dev1_id, '/a/path/file2.py', 1434377919, 181, "DEA17715739E46079C1A6DDCB38344DF", 'md5') self.dir1 = DirectoryInfo(self.fss_api, self.dev1_id, '/a/path/dir', 1436203917) self.errinfo = ErrorInfo(errno=1, message="an error message")
def test_get_modified_directory_results(self): dir2 = DirectoryInfo(self.fss_api, self.dev1_id, '/a/path/dir2', self.dir1.last_modified - 2) def mock_list_files(*args, **kwargs): linfo = LsInfo(directories=[self.dir1, dir2], files=[]) out_dict = {self.dev1_id: linfo, self.dev2_id: LsInfo([], [])} 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.dir1.last_modified - 1) expected_out_dict = { self.dev1_id: LsInfo(files=[], directories=[self.dir1]), self.dev2_id: LsInfo([], []) } self.assertDictEqual(expected_out_dict, out_dict)
def clone_dir(self, orig_dir): return DirectoryInfo(orig_dir._fssapi, orig_dir.device_id, orig_dir.path, orig_dir.last_modified)
def test_eq(self): dir1 = DirectoryInfo(self.fss_api, self.dev_id, '/a/path/dir1', 1436276773) dir2 = DirectoryInfo(self.fss_api, self.dev_id, '/a/path/dir1', 1436276773) self.assertEqual(dir1, dir2) self.assertFalse(dir1 is dir2)
def test_eq_not_eq(self): dir1 = DirectoryInfo(self.fss_api, self.dev_id, '/a/path/dir1', 1436276773) dir2 = DirectoryInfo(self.fss_api, self.dev_id, '/a/path/dir2', 1434377919) self.assertNotEqual(dir1, dir2)