class TestSyncRepo(unittest.TestCase): def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.repo.repo_obj = model.Repository(repo_id=self.repo.id) self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter() @mock.patch('pulp_docker.plugins.importers.sync.SyncStep') @mock.patch( 'pulp.plugins.util.publish_step.common_utils.get_working_directory', mock.MagicMock(return_value='/a/b/c')) def test_calls_sync_step(self, mock_sync_step, mock_rmtree, mock_mkdtemp): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.assert_called_once_with(repo=self.repo, conduit=self.sync_conduit, config=self.config) @mock.patch('pulp_docker.plugins.importers.sync.SyncStep') @mock.patch( 'pulp.plugins.util.publish_step.common_utils.get_working_directory', mock.MagicMock(return_value='/a/b/c')) def test_calls_sync(self, mock_sync_step, mock_rmtree, mock_mkdtemp): """ Assert that the sync_repo() method calls sync() on the SyncStep. """ self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.return_value.process_lifecycle.assert_called_once_with()
class TestSyncRepo(unittest.TestCase): def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.repo.repo_obj = model.Repository(repo_id=self.repo.id) self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter() @mock.patch('pulp_docker.plugins.importers.sync.SyncStep') @mock.patch('pulp.plugins.util.publish_step.common_utils.get_working_directory', mock.MagicMock(return_value='/a/b/c')) def test_calls_sync_step(self, mock_sync_step, mock_rmtree, mock_mkdtemp): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.assert_called_once_with( repo=self.repo, conduit=self.sync_conduit, config=self.config) @mock.patch('pulp_docker.plugins.importers.sync.SyncStep') @mock.patch('pulp.plugins.util.publish_step.common_utils.get_working_directory', mock.MagicMock(return_value='/a/b/c')) def test_calls_sync(self, mock_sync_step, mock_rmtree, mock_mkdtemp): """ Assert that the sync_repo() method calls sync() on the SyncStep. """ self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.return_value.process_lifecycle.assert_called_once_with()
class TestSyncRepo(unittest.TestCase): def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter() def test_calls_sync_step(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.assert_called_once_with(repo=self.repo, conduit=self.sync_conduit, config=self.config, working_dir=mock_mkdtemp.return_value) def test_calls_sync(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.return_value.sync.assert_called_once_with() @mock.patch('pulp_docker.plugins.importers.v1_sync.SyncStep') def test_fall_back_to_v1(self, v1_sync_step, mock_rmtree, mock_mkdtemp, mock_sync_step): """ Ensure that the sync_repo() method falls back to Docker v1 if Docker v2 isn't available. """ # Simulate the v2 API being unavailable mock_sync_step.side_effect = NotImplementedError() self.importer.sync_repo(self.repo, self.sync_conduit, self.config) v1_sync_step.assert_called_once_with( repo=self.repo, conduit=self.sync_conduit, config=self.config, working_dir=mock_mkdtemp.return_value) v1_sync_step.return_value.sync.assert_called_once_with() def test_makes_temp_dir(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_mkdtemp.assert_called_once_with(dir=self.repo.working_dir) def test_removes_temp_dir(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_rmtree.assert_called_once_with(mock_mkdtemp.return_value, ignore_errors=True) def test_removes_temp_dir_after_exception(self, mock_rmtree, mock_mkdtemp, mock_sync_step): class MyError(Exception): pass mock_sync_step.return_value.sync.side_effect = MyError self.assertRaises(MyError, self.importer.sync_repo, self.repo, self.sync_conduit, self.config) mock_rmtree.assert_called_once_with(mock_mkdtemp.return_value, ignore_errors=True)
def test_calls_process_lifecycle(self, m_repo_objects, mock_sync_step): repo = mock.Mock(id='repo1') sync_conduit = mock.MagicMock() config = mock.MagicMock() importer = DockerImporter() repo_instance = Repository() m_repo_objects.get_repo_or_missing_resource.return_value = repo_instance importer.sync_repo(repo, sync_conduit, config) mock_sync_step.assert_called_once_with(repo=repo_instance, conduit=sync_conduit, config=config) mock_sync_step.return_value.process_lifecycle.assert_called_once_with()
class TestSyncRepo(unittest.TestCase): def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter() def test_calls_sync_step(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.assert_called_once_with( repo=self.repo, conduit=self.sync_conduit, config=self.config, working_dir=mock_mkdtemp.return_value) def test_calls_sync(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.return_value.sync.assert_called_once_with() def test_makes_temp_dir(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_mkdtemp.assert_called_once_with(dir=self.repo.working_dir) def test_removes_temp_dir(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_rmtree.assert_called_once_with(mock_mkdtemp.return_value, ignore_errors=True) def test_removes_temp_dir_after_exception(self, mock_rmtree, mock_mkdtemp, mock_sync_step): class MyError(Exception): pass mock_sync_step.return_value.sync.side_effect = MyError self.assertRaises(MyError, self.importer.sync_repo, self.repo, self.sync_conduit, self.config) mock_rmtree.assert_called_once_with(mock_mkdtemp.return_value, ignore_errors=True)
class TestSyncRepo(unittest.TestCase): def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter() def test_calls_sync_step(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.assert_called_once_with(repo=self.repo, conduit=self.sync_conduit, config=self.config, working_dir=mock_mkdtemp.return_value) def test_calls_sync(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_sync_step.return_value.sync.assert_called_once_with() def test_makes_temp_dir(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_mkdtemp.assert_called_once_with(dir=self.repo.working_dir) def test_removes_temp_dir(self, mock_rmtree, mock_mkdtemp, mock_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) mock_rmtree.assert_called_once_with(mock_mkdtemp.return_value, ignore_errors=True) def test_removes_temp_dir_after_exception(self, mock_rmtree, mock_mkdtemp, mock_sync_step): class MyError(Exception): pass mock_sync_step.return_value.sync.side_effect = MyError self.assertRaises(MyError, self.importer.sync_repo, self.repo, self.sync_conduit, self.config) mock_rmtree.assert_called_once_with(mock_mkdtemp.return_value, ignore_errors=True)
class TestSyncRepo(unittest.TestCase): def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter() @mock.patch('pulp.plugins.util.publish_step.common_utils.get_working_directory', mock.MagicMock(return_value='/a/b/c')) def test_calls_sync_step(self, objects, mock_rmtree, mock_mkdtemp, v1_sync_step): self.importer.sync_repo(self.repo, self.sync_conduit, self.config) v1_sync_step.assert_called_once_with( repo=objects.get_repo_or_missing_resource.return_value, conduit=self.sync_conduit, config=self.config) objects.get_repo_or_missing_resource.assert_called_once_with(self.repo.id) @mock.patch('pulp.plugins.util.publish_step.common_utils.get_working_directory', mock.MagicMock(return_value='/a/b/c')) def test_calls_sync(self, objects, mock_rmtree, mock_mkdtemp, v1_sync_step): """ Assert that the sync_repo() method calls sync() on the SyncStep. """ self.importer.sync_repo(self.repo, self.sync_conduit, self.config) objects.get_repo_or_missing_resource.assert_called_once_with(self.repo.id) v1_sync_step.return_value.process_lifecycle.assert_called_once_with() @mock.patch('pulp_docker.plugins.importers.sync.SyncStep') def test_fall_back_to_v1(self, sync_step, objects, mock_rmtree, mock_mkdtemp, v1_sync_step): """ Ensure that the sync_repo() method falls back to Docker v1 if Docker v2 isn't available. """ # Simulate the v2 API being unavailable sync_step.side_effect = NotImplementedError() self.importer.sync_repo(self.repo, self.sync_conduit, self.config) objects.get_repo_or_missing_resource.assert_called_once_with(self.repo.id) v1_sync_step.assert_called_once_with( repo=objects.get_repo_or_missing_resource.return_value, conduit=self.sync_conduit, config=self.config) v1_sync_step.return_value.process_lifecycle.assert_called_once_with()