def put(self, request, repo_id, importer_id): """ Associate an importer to a repository. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: The id of the repository :type repo_id: str :param importer_id: The id of the importer to associate :type importer_id: str :raises exceptions.MissingValue: if required param importer_config is not in the body :raises exceptions.MissingResource: if importer does not match the repo's importer :raises exceptions.OperationPostponed: dispatch a task """ importer_controller.get_valid_importer(repo_id, importer_id) importer_config = request.body_as_json.get('importer_config', None) if importer_config is None: raise exceptions.MissingValue(['importer_config']) async_result = importer_controller.queue_update_importer_config(repo_id, importer_id, importer_config) raise exceptions.OperationPostponed(async_result)
def test_as_expected(self, mock_get_imp, mock_tags, mock_update_importer): """ Test dispatching a task to update the importer config. """ result = importer.queue_update_importer_config('mock_r', 'mock_type', 'mock_config') mock_get_imp.assert_called_once_with('mock_r', 'mock_type') call_tags = [mock_tags.resource_tag.return_value, mock_tags.resource_tag.return_value, mock_tags.action_tag.return_value] mock_update_importer.apply_async_with_reservation.assert_called_once_with( mock_tags.RESOURCE_REPOSITORY_TYPE, 'mock_r', ['mock_r'], {'importer_config': 'mock_config'}, tags=call_tags) self.assertTrue(result is mock_update_importer.apply_async_with_reservation.return_value)