def test_invalid_importer_type(self, m_plug_call_config, m_repo_model, m_plug_api): m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.is_valid_importer.return_value = False with self.assertRaises(exceptions.PulpCodedValidationException) as cm: importer.validate_importer_config(m_repo, 'm_type', 'm_conf') self.assertEqual(cm.exception.error_code.code, 'PLP1008')
def test_invalid_importer_type(self, m_plug_call_config, m_repo_model, m_plug_api): m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.is_valid_importer.return_value = False with self.assertRaises(exceptions.PulpCodedValidationException) as cm: importer.validate_importer_config(m_repo, 'm_type', 'm_conf') self.assertEqual(cm.exception.error_code.code, 'PLP1008')
def test_plugin_is_invalid_importer(self, m_repo_model, m_plug_api, m_clean): """ If the plugin_api returns that an importer is invalid, raise. """ m_plug_api.is_valid_importer.return_value = False try: importer.validate_importer_config('m_id', 'm_type', 'm_conf') except exceptions.PulpCodedValidationException, e: pass
def test_plugin_is_invalid_importer(self, m_repo_model, m_plug_api, m_clean): """ If the plugin_api returns that an importer is invalid, raise. """ m_plug_api.is_valid_importer.return_value = False try: importer.validate_importer_config('m_id', 'm_type', 'm_conf') except exceptions.PulpCodedValidationException, e: pass
def test_invalid_as_expected_tuple(self, m_plug_call_config, m_repo_model, m_plug_api): """ Importer instances can return a boolean or a tuple. Test tuple. """ imp_inst = mock.MagicMock() m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.get_importer_by_id.return_value = (imp_inst, 'plug_config') imp_inst.validate_config.return_value = (False, 'm_message') try: importer.validate_importer_config(m_repo, 'm_type', 'm_conf') except exceptions.PulpDataException, e: pass
def test_invalid_as_expected_tuple(self, m_plug_call_config, m_repo_model, m_plug_api, m_clean): """ Importer instances can return a boolean or a tuple. Test tuple. """ imp_inst = mock.MagicMock() m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.get_importer_by_id.return_value = (imp_inst, 'plug_config') imp_inst.validate_config.return_value = (False, 'm_message') try: importer.validate_importer_config('m_id', 'm_type', 'm_conf') except exceptions.PulpCodedValidationException, e: pass
def test_invalid_as_expected_tuple(self, m_plug_call_config, m_repo_model, m_plug_api): """ Importer instances can return a boolean or a tuple. Test tuple. """ imp_inst = mock.MagicMock() m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.get_importer_by_id.return_value = (imp_inst, "plug_config") imp_inst.validate_config.return_value = (False, "m_message") try: importer.validate_importer_config(m_repo, "m_type", "m_conf") except exceptions.PulpDataException, e: pass
def test_valid_as_expected(self, m_plug_call_config, m_repo_model, m_plug_api): """ Test a valid importer. """ imp_inst = mock.MagicMock() m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.get_importer_by_id.return_value = (imp_inst, 'plug_config') imp_inst.validate_config.return_value = True # No error messages should be raised. importer.validate_importer_config(m_repo, 'm_type', 'm_conf') m_plug_call_config.assert_called_once_with('plug_config', 'm_conf') imp_inst.validate_config.assert_called_once_with( m_repo.to_transfer_repo.return_value, m_plug_call_config.return_value)
def test_valid_as_expected(self, m_plug_call_config, m_repo_model, m_plug_api): """ Test a valid importer. """ imp_inst = mock.MagicMock() m_repo = m_repo_model.objects.get_repo_or_missing_resource.return_value m_plug_api.get_importer_by_id.return_value = (imp_inst, 'plug_config') imp_inst.validate_config.return_value = True # No error messages should be raised. importer.validate_importer_config(m_repo, 'm_type', 'm_conf') m_plug_call_config.assert_called_once_with('plug_config', 'm_conf') imp_inst.validate_config.assert_called_once_with( m_repo.to_transfer_repo.return_value, m_plug_call_config.return_value)
def post(self, request, repo_id): """ Associate an importer with a repository. This will validate that the repository exists and that there is an importer with the importer_type_id given. However, the importer configuration validation only checks the provided values against a standard set of importer configuration keys. The importer specific validation is called on association, so any type specific configuration will be validated later. This means the spawned task could fail with a validation error. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: the repository to associate the importer with :type repo_id: str :raises exceptions.OperationPostponed: dispatch a task """ importer_type = request.body_as_json.get('importer_type_id', None) config = request.body_as_json.get('importer_config', None) importer_controller.validate_importer_config(repo_id, importer_type, config) repo = model.Repository.objects.get_repo_or_missing_resource(repo_id) async_result = importer_controller.queue_set_importer(repo, importer_type, config) raise exceptions.OperationPostponed(async_result)
def post(self, request, repo_id): """ Associate an importer with a repository. This will validate that the repository exists and that there is an importer with the importer_type_id given. However, the importer configuration validation only checks the provided values against a standard set of importer configuration keys. The importer specific validation is called on association, so any type specific configuration will be validated later. This means the spawned task could fail with a validation error. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: the repository to associate the importer with :type repo_id: str :raises exceptions.OperationPostponed: dispatch a task """ importer_type = request.body_as_json.get('importer_type_id', None) config = request.body_as_json.get('importer_config', None) importer_controller.validate_importer_config(repo_id, importer_type, config) repo = model.Repository.objects.get_repo_or_missing_resource(repo_id) async_result = importer_controller.queue_set_importer(repo, importer_type, config) raise exceptions.OperationPostponed(async_result)