示例#1
0
    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')
示例#2
0
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')
示例#3
0
    def setUp(self):
        super(ImporterScratchPadMixinTests, self).setUp()
        mock_plugins.install()

        self.importer_manager = RepoImporterManager()

        self.repo_id = 'repo-1'
        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")
示例#5
0
    def setUp(self):
        super(ImporterScratchPadMixinTests, self).setUp()
        mock_plugins.install()

        self.importer_manager = RepoImporterManager()

        self.repo_id = 'repo-1'
        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)
示例#6
0
class ImporterScratchPadMixinTests(base.PulpServerTests):
    def setUp(self):
        super(ImporterScratchPadMixinTests, self).setUp()
        mock_plugins.install()

        self.importer_manager = RepoImporterManager()

        self.repo_id = 'repo-1'
        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()
        model.Repository.drop_collection()

    def tearDown(self):
        super(ImporterScratchPadMixinTests, self).tearDown()
        manager_factory.reset()
        mock_plugins.reset()

    @mock.patch('pulp.server.managers.repo.importer.model.Repository')
    def test_get_set_scratchpad(self, mock_repo_qs):
        """
        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')
示例#7
0
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')