class DistributorScratchpadMixinTests(base.PulpServerTests): def clean(self): super(DistributorScratchpadMixinTests, self).clean() types_database.clean() Repo.get_collection().remove() def setUp(self): super(DistributorScratchpadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.distributor_manager = RepoDistributorManager() repo_id = 'repo-1' self.repo_manager.create_repo(repo_id) self.distributor_manager.add_distributor( repo_id, 'mock-distributor', {}, True, distributor_id='test-distributor') self.conduit = DistributorScratchPadMixin(repo_id, 'test-distributor') def tearDown(self): super(DistributorScratchpadMixinTests, self).tearDown() manager_factory.reset() def test_get_set_scratchpad(self): """ Tests scratchpad calls. """ # Test - get no scratchpad self.assertTrue(self.conduit.get_scratchpad() is None) # Test - set scrathpad value = 'dragon' self.conduit.set_scratchpad(value) # Test - get updated value self.assertEqual(value, self.conduit.get_scratchpad()) def test_scratchpad_with_error(self): # Setup mock_distributor_manager = mock.Mock() mock_distributor_manager.get_distributor_scratchpad.side_effect = Exception( ) mock_distributor_manager.set_distributor_scratchpad.side_effect = Exception( ) manager_factory._INSTANCES[ manager_factory.TYPE_REPO_DISTRIBUTOR] = mock_distributor_manager # Test self.assertRaises(DistributorConduitException, self.conduit.get_scratchpad) self.assertRaises(DistributorConduitException, self.conduit.set_scratchpad, 'foo')
def setUp(self): super(ImporterScratchPadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.importer_manager = RepoImporterManager() self.repo_id = 'repo-1' self.repo_manager.create_repo(self.repo_id) self.conduit = ImporterScratchPadMixin(self.repo_id, 'test-importer')
class DistributorScratchpadMixinTests(base.PulpServerTests): def clean(self): super(DistributorScratchpadMixinTests, self).clean() types_database.clean() Repo.get_collection().remove() @mock.patch('pulp.server.managers.repo._common.get_working_directory', return_value="/var/cache/pulp/mock_worker/mock_task_id") def setUp(self, mock_get_working_directory): super(DistributorScratchpadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.distributor_manager = RepoDistributorManager() repo_id = 'repo-1' self.repo_manager.create_repo(repo_id) self.distributor_manager.add_distributor(repo_id, 'mock-distributor', {}, True, distributor_id='test-distributor') self.conduit = mixins.DistributorScratchPadMixin(repo_id, 'test-distributor') def tearDown(self): super(DistributorScratchpadMixinTests, self).tearDown() manager_factory.reset() mock_plugins.reset() def test_get_set_scratchpad(self): """ Tests scratchpad calls. """ # Test - get no scratchpad self.assertTrue(self.conduit.get_scratchpad() is None) # Test - set scrathpad value = 'dragon' self.conduit.set_scratchpad(value) # Test - get updated value self.assertEqual(value, self.conduit.get_scratchpad()) def test_scratchpad_with_error(self): # Setup mock_distributor_manager = mock.Mock() mock_distributor_manager.get_distributor_scratchpad.side_effect = Exception() mock_distributor_manager.set_distributor_scratchpad.side_effect = Exception() manager_factory._INSTANCES[manager_factory.TYPE_REPO_DISTRIBUTOR] = mock_distributor_manager # Test self.assertRaises(mixins.DistributorConduitException, self.conduit.get_scratchpad) self.assertRaises(mixins.DistributorConduitException, self.conduit.set_scratchpad, 'foo')
class ImporterScratchPadMixinTests(base.PulpServerTests): def clean(self): super(ImporterScratchPadMixinTests, self).clean() types_database.clean() Repo.get_collection().remove() def setUp(self): super(ImporterScratchPadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.importer_manager = RepoImporterManager() self.repo_id = 'repo-1' self.repo_manager.create_repo(self.repo_id) self.conduit = ImporterScratchPadMixin(self.repo_id, 'test-importer') def tearDown(self): super(ImporterScratchPadMixinTests, self).tearDown() manager_factory.reset() mock_plugins.reset() def test_get_set_scratchpad(self): """ Tests scratchpad calls. """ # Setup self.importer_manager.set_importer(self.repo_id, 'mock-importer', {}) # Test - get no scratchpad self.assertTrue(self.conduit.get_scratchpad() is None) # Test - set scrathpad value = 'dragon' self.conduit.set_scratchpad(value) # Test - get updated value self.assertEqual(value, self.conduit.get_scratchpad()) def test_scratchpad_with_error(self): # Setup mock_manager = mock.Mock() mock_manager.get_importer_scratchpad.side_effect = Exception() mock_manager.set_importer_scratchpad.side_effect = Exception() manager_factory._INSTANCES[manager_factory.TYPE_REPO_IMPORTER] = mock_manager # Test self.assertRaises(ImporterConduitException, self.conduit.get_scratchpad) self.assertRaises(ImporterConduitException, self.conduit.set_scratchpad, 'foo')
def setUp(self, mock_get_working_directory): super(DistributorScratchpadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.distributor_manager = RepoDistributorManager() repo_id = 'repo-1' self.repo_manager.create_repo(repo_id) self.distributor_manager.add_distributor(repo_id, 'mock-distributor', {}, True, distributor_id='test-distributor') self.conduit = mixins.DistributorScratchPadMixin(repo_id, 'test-distributor')
def setUp(self): super(ImporterScratchPadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.importer_manager = RepoImporterManager() self.repo_id = 'repo-1' self.repo_manager.create_repo(self.repo_id) self.conduit = mixins.ImporterScratchPadMixin(self.repo_id, 'test-importer') manager_factory.initialize() self.importer_id = 'isp-importer' self.mixin = mixins.ImporterScratchPadMixin(self.repo_id, self.importer_id)
def setUp(self): super(ImporterScratchPadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.importer_manager = RepoImporterManager() self.repo_id = "repo-1" self.repo_manager.create_repo(self.repo_id) self.conduit = ImporterScratchPadMixin(self.repo_id, "test-importer")
def setUp(self): super(DistributorScratchpadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.distributor_manager = RepoDistributorManager() repo_id = 'repo-1' self.repo_manager.create_repo(repo_id) self.distributor_manager.add_distributor(repo_id, 'mock-distributor', {}, True, distributor_id='test-distributor') self.conduit = DistributorScratchPadMixin(repo_id, 'test-distributor')
def migrate(*args, **kwargs): """ Regenerates the 'content_unit_counts' attribute of each repository, and removes the obsolete attribute 'content_unit_count'. The normal use case will be that the 'content_unit_counts' attribute does not yet exist, but this migration is idempotent just in case. """ RepoManager().rebuild_content_unit_counts() repo_collection = Repo.get_collection() repo_collection.update({}, {'$unset': { 'content_unit_count': 1 }}, safe=True)
class ImporterScratchPadMixinTests(base.PulpServerTests): def setUp(self): super(ImporterScratchPadMixinTests, self).setUp() mock_plugins.install() self.repo_manager = RepoManager() self.importer_manager = RepoImporterManager() self.repo_id = 'repo-1' self.repo_manager.create_repo(self.repo_id) self.conduit = mixins.ImporterScratchPadMixin(self.repo_id, 'test-importer') manager_factory.initialize() self.importer_id = 'isp-importer' self.mixin = mixins.ImporterScratchPadMixin(self.repo_id, self.importer_id) def clean(self): super(ImporterScratchPadMixinTests, self).clean() types_database.clean() Repo.get_collection().remove() def tearDown(self): super(ImporterScratchPadMixinTests, self).tearDown() manager_factory.reset() mock_plugins.reset() def test_get_set_scratchpad(self): """ Tests scratchpad calls. """ # Setup self.importer_manager.set_importer(self.repo_id, 'mock-importer', {}) # Test - get no scratchpad self.assertTrue(self.conduit.get_scratchpad() is None) # Test - set scrathpad value = 'dragon' self.conduit.set_scratchpad(value) # Test - get updated value self.assertEqual(value, self.conduit.get_scratchpad()) def test_scratchpad_with_error(self): # Setup mock_manager = mock.Mock() mock_manager.get_importer_scratchpad.side_effect = Exception() mock_manager.set_importer_scratchpad.side_effect = Exception() manager_factory._INSTANCES[manager_factory.TYPE_REPO_IMPORTER] = mock_manager # Test self.assertRaises(mixins.ImporterConduitException, self.conduit.get_scratchpad) self.assertRaises(mixins.ImporterConduitException, self.conduit.set_scratchpad, 'foo') @mock.patch('pulp.server.managers.repo.importer.RepoImporterManager.get_importer_scratchpad') def test_get_scratchpad(self, mock_call): # Setup mock_call.return_value = 'sp' # Test sp = self.mixin.get_scratchpad() # Verify self.assertEqual(sp, 'sp') self.assertEqual(1, mock_call.call_count) @mock.patch('pulp.server.managers.repo.importer.RepoImporterManager.get_importer_scratchpad') def test_get_scratchpad_server_error(self, mock_call): # Setup mock_call.side_effect = Exception() # Test self.assertRaises(mixins.ImporterConduitException, self.mixin.get_scratchpad) @mock.patch('pulp.server.managers.repo.importer.RepoImporterManager.set_importer_scratchpad') def test_set_scratchpad(self, mock_call): # Test self.mixin.set_scratchpad('foo') # Verify self.assertEqual(1, mock_call.call_count) self.assertEqual(mock_call.call_args[0][0], self.repo_id) self.assertEqual(mock_call.call_args[0][1], 'foo') @mock.patch('pulp.server.managers.repo.importer.RepoImporterManager.set_importer_scratchpad') def test_set_scratchpad_server_error(self, mock_call): # Setup mock_call.side_effect = Exception() # Test self.assertRaises(mixins.ImporterConduitException, self.mixin.set_scratchpad, 'foo')