Page MenuHomeSoftware Heritage

Jenkins > .tox.py3.lib.python3.7.site-packages.swh.deposit.tests.api.test_collection_post_atom::test_post_deposit_atom_400_with_empty_body
Failed

TEST RESULT

Run At
Jan 18 2022, 11:31 AM
Details
self = <rest_framework.test.ForceAuthClientHandler object at 0x7f135fbfe6d8> request = <WSGIRequest: POST '/1/test/'> def _get_response(self, request): """ Resolve and call the view, then apply view, exception, and template_response middleware. This method is everything that happens inside the request/response middleware. """ response = None if hasattr(request, 'urlconf'): urlconf = request.urlconf set_urlconf(urlconf) resolver = get_resolver(urlconf) else: resolver = get_resolver() resolver_match = resolver.resolve(request.path_info) callback, callback_args, callback_kwargs = resolver_match request.resolver_match = resolver_match # Apply view middleware for middleware_method in self._view_middleware: response = middleware_method(request, callback, callback_args, callback_kwargs) if response: break if response is None: wrapped_callback = self.make_view_atomic(callback) try: > response = wrapped_callback(request, *callback_args, **callback_kwargs) .tox/py3/lib/python3.7/site-packages/django/core/handlers/base.py:113: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (<WSGIRequest: POST '/1/test/'>,), kwargs = {'collection_name': 'test'} def wrapped_view(*args, **kwargs): > return view_func(*args, **kwargs) .tox/py3/lib/python3.7/site-packages/django/views/decorators/csrf.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ request = <WSGIRequest: POST '/1/test/'>, args = () kwargs = {'collection_name': 'test'} self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> def view(request, *args, **kwargs): self = cls(**initkwargs) if hasattr(self, 'get') and not hasattr(self, 'head'): self.head = self.get self.setup(request, *args, **kwargs) if not hasattr(self, 'request'): raise AttributeError( "%s instance has no 'request' attribute. Did you override " "setup() and forget to call super()?" % cls.__name__ ) > return self.dispatch(request, *args, **kwargs) .tox/py3/lib/python3.7/site-packages/django/views/generic/base.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> request = <rest_framework.request.Request: POST '/1/test/'>, args = () kwargs = {'collection_name': 'test'} handler = <bound method APIPost.post of <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160>> def dispatch(self, request, *args, **kwargs): """ `.dispatch()` is pretty much the same as Django's regular dispatch, but with extra hooks for startup, finalize, and exception handling. """ self.args = args self.kwargs = kwargs request = self.initialize_request(request, *args, **kwargs) self.request = request self.headers = self.default_response_headers # deprecate? try: self.initial(request, *args, **kwargs) # Get the appropriate handler method if request.method.lower() in self.http_method_names: handler = getattr(self, request.method.lower(), self.http_method_not_allowed) else: handler = self.http_method_not_allowed response = handler(request, *args, **kwargs) except Exception as exc: > response = self.handle_exception(exc) .tox/py3/lib/python3.7/site-packages/rest_framework/views.py:509: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> exc = DepositError('Empty body request is not supported.', 'Atom entry request is about non-empty metadata deposit.') def handle_exception(self, exc): """ Handle any exception that occurs, by returning an appropriate response, or re-raising the error. """ if isinstance(exc, (exceptions.NotAuthenticated, exceptions.AuthenticationFailed)): # WWW-Authenticate header for 401 responses, else coerce to 403 auth_header = self.get_authenticate_header(self.request) if auth_header: exc.auth_header = auth_header else: exc.status_code = status.HTTP_403_FORBIDDEN exception_handler = self.get_exception_handler() context = self.get_exception_handler_context() response = exception_handler(exc, context) if response is None: > self.raise_uncaught_exception(exc) .tox/py3/lib/python3.7/site-packages/rest_framework/views.py:469: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> exc = DepositError('Empty body request is not supported.', 'Atom entry request is about non-empty metadata deposit.') def raise_uncaught_exception(self, exc): if settings.DEBUG: request = self.request renderer_format = getattr(request.accepted_renderer, 'format') use_plaintext_traceback = renderer_format not in ('html', 'api', 'admin') request.force_plaintext_errors(use_plaintext_traceback) > raise exc .tox/py3/lib/python3.7/site-packages/rest_framework/views.py:480: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> request = <rest_framework.request.Request: POST '/1/test/'>, args = () kwargs = {'collection_name': 'test'} handler = <bound method APIPost.post of <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160>> def dispatch(self, request, *args, **kwargs): """ `.dispatch()` is pretty much the same as Django's regular dispatch, but with extra hooks for startup, finalize, and exception handling. """ self.args = args self.kwargs = kwargs request = self.initialize_request(request, *args, **kwargs) self.request = request self.headers = self.default_response_headers # deprecate? try: self.initial(request, *args, **kwargs) # Get the appropriate handler method if request.method.lower() in self.http_method_names: handler = getattr(self, request.method.lower(), self.http_method_not_allowed) else: handler = self.http_method_not_allowed > response = handler(request, *args, **kwargs) .tox/py3/lib/python3.7/site-packages/rest_framework/views.py:506: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> request = <rest_framework.request.Request: POST '/1/test/'> collection_name = 'test', deposit_id = None def post( # type: ignore self, request: Request, collection_name: str, deposit_id: Optional[int] = None ) -> HttpResponse: """Endpoint to create/add resources to deposit. Returns: 204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist """ if deposit_id is None: deposit = None else: deposit = get_deposit_by_id(deposit_id, collection_name) headers = self.checks(request, collection_name, deposit) status, iri_key, receipt = self.process_post( > request, headers, collection_name, deposit ) .tox/py3/lib/python3.7/site-packages/swh/deposit/api/common.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> req = <rest_framework.request.Request: POST '/1/test/'> headers = ParsedRequestHeaders(content_type='application/atom+xml;type=entry', content_length=74, in_progress=False, content_dis...n=None, content_md5sum=None, packaging=None, slug='external-id', on_behalf_of=None, metadata_relevant=None, swhid=None) collection_name = 'test' deposit = <Deposit: {'id': None, 'reception_date': None, 'collection': 'test', 'external_id': 'external-id', 'origin_url': None, 'client': 'test', 'status': 'partial'}> def process_post( self, req, headers: ParsedRequestHeaders, collection_name: str, deposit: Optional[Deposit] = None, ) -> Tuple[int, str, Receipt]: """Create a first deposit as: - archive deposit (1 zip) - multipart (1 zip + 1 atom entry) - atom entry Args: req (Request): the request holding the information to parse and inject in db collection_name (str): the associated client Returns: An http response (HttpResponse) according to the situation. If everything is ok, a 201 response (created) with a deposit receipt. Raises: - archive deposit: - 400 (bad request) if the request is not providing an external identifier - 403 (forbidden) if the length of the archive exceeds the max size configured - 412 (precondition failed) if the length or hash provided mismatch the reality of the archive. - 415 (unsupported media type) if a wrong media type is provided - multipart deposit: - 400 (bad request) if the request is not providing an external identifier - 412 (precondition failed) if the potentially md5 hash provided mismatch the reality of the archive - 415 (unsupported media type) if a wrong media type is provided - Atom entry deposit: - 400 (bad request) if the request is not providing an external identifier - 400 (bad request) if the request's body is empty - 415 (unsupported media type) if a wrong media type is provided """ assert deposit is None deposit = self._deposit_create(req, collection_name, external_id=headers.slug) if req.content_type in ACCEPT_ARCHIVE_CONTENT_TYPES: receipt = self._binary_upload(req, headers, collection_name, deposit) elif req.content_type.startswith("multipart/"): receipt = self._multipart_upload(req, headers, collection_name, deposit) else: > receipt = self._atom_entry(req, headers, collection_name, deposit) .tox/py3/lib/python3.7/site-packages/swh/deposit/api/collection.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swh.deposit.api.collection.CollectionAPI object at 0x7f135fbfe160> request = <rest_framework.request.Request: POST '/1/test/'> headers = ParsedRequestHeaders(content_type='application/atom+xml;type=entry', content_length=74, in_progress=False, content_dis...n=None, content_md5sum=None, packaging=None, slug='external-id', on_behalf_of=None, metadata_relevant=None, swhid=None) collection_name = 'test' deposit = <Deposit: {'id': None, 'reception_date': None, 'collection': 'test', 'external_id': 'external-id', 'origin_url': None, 'client': 'test', 'status': 'partial'}> replace_metadata = False, replace_archives = False def _atom_entry( self, request: Request, headers: ParsedRequestHeaders, collection_name: str, deposit: Deposit, replace_metadata: bool = False, replace_archives: bool = False, ) -> Receipt: """Atom entry deposit. Args: request: the request holding information to parse and inject in db headers: parsed request headers collection_name: the associated client deposit: deposit to be updated replace_metadata: 'Update or add' request to existing deposit. If False (default), this adds new metadata request to existing ones. Otherwise, this will replace existing metadata. replace_archives: 'Update or add' request to existing deposit. If False (default), this adds new archive request to existing ones. Otherwise, this will replace existing archives. ones. Raises: - 400 (bad request) if the request is not providing an external identifier - 400 (bad request) if the request's body is empty - 415 (unsupported media type) if a wrong media type is provided """ metadata_stream = request.data empty_atom_entry_summary = "Empty body request is not supported." empty_atom_entry_desc = ( "Atom entry request is about non-empty metadata deposit." ) if not metadata_stream: raise DepositError(empty_atom_entry_summary, empty_atom_entry_desc) try: raw_metadata, metadata = self._read_metadata(metadata_stream) except ParserError: raise DepositError( BAD_REQUEST, "Malformed xml metadata", "The xml received is malformed. " "Please ensure your metadata file is correctly formatted.", ) if metadata is None: > raise DepositError(empty_atom_entry_summary, empty_atom_entry_desc) E swh.deposit.errors.DepositError: ('Empty body request is not supported.', 'Atom entry request is about non-empty metadata deposit.') .tox/py3/lib/python3.7/site-packages/swh/deposit/api/common.py:829: DepositError During handling of the above exception, another exception occurred: authenticated_client = <rest_framework.test.APIClient object at 0x7f135fbfe358> deposit_collection = <DepositCollection: {'id': 20, 'name': 'test'}> atom_dataset = {'codemeta-sample': '<?xml version="1.0"?>\n <entry xmlns="http://www.w3.org/2005/Atom"\n xmlns:d...ntry>\n', 'entry-data-empty-body': '<?xml version="1.0"?>\n<entry xmlns="http://www.w3.org/2005/Atom"></entry>\n', ...} def test_post_deposit_atom_400_with_empty_body( authenticated_client, deposit_collection, atom_dataset ): """Posting empty body request should return a 400 response """ atom_content = atom_dataset["entry-data-empty-body"] response = post_atom( authenticated_client, reverse(COL_IRI, args=[deposit_collection.name]), data=atom_content, > HTTP_SLUG="external-id", ) .tox/py3/lib/python3.7/site-packages/swh/deposit/tests/api/test_collection_post_atom.py:146: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.7/site-packages/swh/deposit/tests/common.py:173: in post_atom url, content_type="application/atom+xml;type=entry", data=data, **kwargs .tox/py3/lib/python3.7/site-packages/rest_framework/test.py:297: in post path, data=data, format=format, content_type=content_type, **extra) .tox/py3/lib/python3.7/site-packages/rest_framework/test.py:210: in post return self.generic('POST', path, data, content_type, **extra) .tox/py3/lib/python3.7/site-packages/rest_framework/test.py:235: in generic method, path, data, content_type, secure, **extra) .tox/py3/lib/python3.7/site-packages/django/test/client.py:422: in generic return self.request(**r) .tox/py3/lib/python3.7/site-packages/rest_framework/test.py:286: in request return super().request(**kwargs) .tox/py3/lib/python3.7/site-packages/rest_framework/test.py:238: in request request = super().request(**kwargs) .tox/py3/lib/python3.7/site-packages/django/test/client.py:503: in request raise exc_value .tox/py3/lib/python3.7/site-packages/django/core/handlers/exception.py:34: in inner response = get_response(request) .tox/py3/lib/python3.7/site-packages/django/core/handlers/base.py:115: in _get_response response = self.process_exception_by_middleware(e, request) .tox/py3/lib/python3.7/site-packages/django/core/handlers/base.py:155: in process_exception_by_middleware response = middleware_method(request, exception) .tox/py3/lib/python3.7/site-packages/swh/deposit/errors.py:196: in process_exception return make_error_response_from_dict(request, exception.to_dict()["error"]) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ req = <WSGIRequest: POST '/1/test/'> error = {'key': 'Empty body request is not supported.', 'summary': 'Atom entry request is about non-empty metadata deposit.', 'verboseDescription': None} def make_error_response_from_dict(req, error): """Utility function to return an http response with error detail. Args: req (Request): original request error (dict): Error described as dict, typically generated from the make_error_dict function. Returns: HttpResponse with detailed error. """ > error_information = ERRORS[error["key"]] E KeyError: 'Empty body request is not supported.' .tox/py3/lib/python3.7/site-packages/swh/deposit/errors.py:127: KeyError