From 284e191e1d82681f76c830902948f5249ebd5800 Mon Sep 17 00:00:00 2001 From: gecong1973 Date: Sun, 23 Dec 2018 22:54:24 -0800 Subject: [PATCH] Add rsync compute checksums regfile false unit test the patch add rsync compute checksums regfile false unit test Change-Id: I75f730fcc1d62e5d80a1efe9b428a2e756daa1f6 --- .../tests/unit/engines/rsync/test_rsync.py | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/freezer/tests/unit/engines/rsync/test_rsync.py b/freezer/tests/unit/engines/rsync/test_rsync.py index 30b6ee3f..e26010ce 100644 --- a/freezer/tests/unit/engines/rsync/test_rsync.py +++ b/freezer/tests/unit/engines/rsync/test_rsync.py @@ -1596,20 +1596,60 @@ class TestRsyncEngine(unittest.TestCase): rel_path = 'rel_path' fake_rsync = self.mock_rsync - files_meta = {'files': {'rel_path': {'signature': (1, 2)}}} - files_meta1 = {'files': {'rel_path': {'signature': (3, 4)}}} + files_meta = {'files': {'rel_path': {'signature': [1, 2]}}} + files_meta1 = {'files': {'rel_path': {'signature': [3, 4]}}} file_path_fd = mock.MagicMock() file_path_fd.return_value = 'fakehandle' - # mock_open = mock.MagicMock() mock_open.return_value = file_path_fd mock_blockchecksums.return_value = mock.MagicMock() - mock_blockchecksums.return_value = (3, 4) + mock_blockchecksums.return_value = [3, 4] ret = fake_rsync.compute_checksums(rel_path=rel_path, files_meta=files_meta, reg_file=True) self.assertEqual(ret, files_meta1) + + @patch('os.path.lexists') + @patch('os.path.exists') + def test_compute_checksums_regfile_False(self, mock_os_path_exists, + mock_os_path_lexists): + rel_path = 'rel_path' + fake_rsync = self.mock_rsync + + files_meta = {'files': {'rel_path': {'signature': [1, 2]}}} + files_meta1 = {'files': {'rel_path': {'signature': [[], []]}}} + + mock_os_path_lexists.return_value = mock.MagicMock() + mock_os_path_lexists.return_value = True + + mock_os_path_exists.return_value = mock.MagicMock() + mock_os_path_exists.return_value = True + + ret = fake_rsync.compute_checksums(rel_path=rel_path, + files_meta=files_meta, + reg_file=False) + + self.assertEqual(ret, files_meta1) + + @patch('os.path.lexists') + @patch('os.path.exists') + def test_compute_checksums_regfile_raise(self, mock_os_path_exists, + mock_os_path_lexists): + rel_path = 'rel_path' + fake_rsync = self.mock_rsync + reg_file = False + + mock_os_path_lexists.return_value = mock.MagicMock() + mock_os_path_lexists.return_value = True + + mock_os_path_exists.return_value = mock.MagicMock() + mock_os_path_exists.return_value = False + + self.assertRaises(IOError, + fake_rsync.compute_checksums, + rel_path, + reg_file)