Page MenuHomeSoftware Heritage

tests: Improve HTTP errors reporting
ClosedPublic

Authored by anlambert on Oct 15 2020, 7:40 PM.

Details

Summary

Add helper functions to check HTTP responses in tests implementation.

If an unexpected HTTP status code is encountered, the traceback that led to
the error will be displayed in pytest report. See (fake error) example below:

==================================================================================================== FAILURES ====================================================================================================
___________________________________________________________________________________________ test_api_content_filetype ____________________________________________________________________________________________

api_client = <rest_framework.test.APIClient object at 0x7febef719da0>, indexer_data = <swh.web.tests.conftest._IndexerData object at 0x7febef7d74e0>

    @given(content())
>   def test_api_content_filetype(api_client, indexer_data, content):

swh/web/tests/api/views/test_content.py:21: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
swh/web/tests/api/views/test_content.py:26: in test_api_content_filetype
    rv = check_api_get_responses(api_client, url, status_code=200)
swh/web/tests/utils.py:110: in check_api_get_responses
    api_client, url, status_code, content_type="application/json"
swh/web/tests/utils.py:62: in check_http_get_response
    content_type=content_type,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

response = <Response status_code=500, "application/json">, status_code = 200, content_type = 'application/json'

    def _assert_http_response(
        response: HttpResponse, status_code: int, content_type: str
    ) -> HttpResponse:
    
        if isinstance(response, Response):
            drf_response = cast(Response, response)
            error_context = (
                drf_response.data.pop("traceback")
                if isinstance(drf_response.data, dict) and "traceback" in drf_response.data
                else drf_response.data
            )
        else:
            error_context = (
                getattr(response, "traceback")
                if hasattr(response, "traceback")
                else response.content
            )
    
>       assert response.status_code == status_code, error_context
E       AssertionError: Traceback (most recent call last):
E           File "/home/anlambert/.virtualenvs/swh/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
E             response = handler(request, *args, **kwargs)
E           File "/home/anlambert/.virtualenvs/swh/lib/python3.7/site-packages/rest_framework/decorators.py", line 50, in handler
E             return func(*args, **kwargs)
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/apiurls.py", line 92, in api_view_f
E             response = f(request, **kwargs)
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/apidoc.py", line 348, in documented_view
E             raise exc
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/apidoc.py", line 345, in documented_view
E             return {"data": f(request, **kwargs), "doc_data": doc_data}
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/views/content.py", line 65, in api_content_filetype
E             request=request,
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/views/utils.py", line 67, in api_lookup
E             res = lookup_fn(*args)
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/common/archive.py", line 182, in lookup_content_filetype
E             filetype = _first_element(list(idx_storage.content_mimetype_get([sha1])))
E           File "/home/anlambert/swh/swh-environment/swh-indexer/swh/indexer/storage/in_memory.py", line 290, in content_mimetype_get
E             return self._mimetypes.get(ds)
E         NameError: name 'ds' is not defined
E         
E       assert 500 == 200
E        +  where 500 = <Response status_code=500, "application/json">.status_code

swh/web/tests/utils.py:34: AssertionError
____________________________________________________________________________________ test_api_content_filetype_sha_not_found _____________________________________________________________________________________

api_client = <rest_framework.test.APIClient object at 0x7febef719da0>

    def test_api_content_filetype_sha_not_found(api_client):
        unknown_content_ = random_content()
    
        url = reverse(
            "api-1-content-filetype", url_args={"q": "sha1:%s" % unknown_content_["sha1"]}
        )
>       rv = check_api_get_responses(api_client, url, status_code=404)

swh/web/tests/api/views/test_content.py:44: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
swh/web/tests/utils.py:110: in check_api_get_responses
    api_client, url, status_code, content_type="application/json"
swh/web/tests/utils.py:62: in check_http_get_response
    content_type=content_type,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

response = <Response status_code=500, "application/json">, status_code = 404, content_type = 'application/json'

    def _assert_http_response(
        response: HttpResponse, status_code: int, content_type: str
    ) -> HttpResponse:
    
        if isinstance(response, Response):
            drf_response = cast(Response, response)
            error_context = (
                drf_response.data.pop("traceback")
                if isinstance(drf_response.data, dict) and "traceback" in drf_response.data
                else drf_response.data
            )
        else:
            error_context = (
                getattr(response, "traceback")
                if hasattr(response, "traceback")
                else response.content
            )
    
>       assert response.status_code == status_code, error_context
E       AssertionError: Traceback (most recent call last):
E           File "/home/anlambert/.virtualenvs/swh/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
E             response = handler(request, *args, **kwargs)
E           File "/home/anlambert/.virtualenvs/swh/lib/python3.7/site-packages/rest_framework/decorators.py", line 50, in handler
E             return func(*args, **kwargs)
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/apiurls.py", line 92, in api_view_f
E             response = f(request, **kwargs)
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/apidoc.py", line 348, in documented_view
E             raise exc
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/apidoc.py", line 345, in documented_view
E             return {"data": f(request, **kwargs), "doc_data": doc_data}
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/views/content.py", line 65, in api_content_filetype
E             request=request,
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/api/views/utils.py", line 67, in api_lookup
E             res = lookup_fn(*args)
E           File "/home/anlambert/swh/swh-environment/swh-web/swh/web/common/archive.py", line 182, in lookup_content_filetype
E             filetype = _first_element(list(idx_storage.content_mimetype_get([sha1])))
E           File "/home/anlambert/swh/swh-environment/swh-indexer/swh/indexer/storage/in_memory.py", line 290, in content_mimetype_get
E             return self._mimetypes.get(ds)
E         NameError: name 'ds' is not defined
E         
E       assert 500 == 404
E        +  where 500 = <Response status_code=500, "application/json">.status_code

swh/web/tests/utils.py:34: AssertionError

Closes T2657

Depends on D4277

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build has FAILED

Patch application report for D4278 (id=15124)

Could not rebase; Attempt merge onto d948e60ecd...

Updating d948e60e..0921e5de
Fast-forward
 swh/web/api/apidoc.py                          |  24 +-
 swh/web/api/apiresponse.py                     |  61 +++--
 swh/web/api/apiurls.py                         |  44 +++-
 swh/web/api/views/content.py                   |   2 +-
 swh/web/api/views/origin_save.py               |   2 +-
 swh/web/api/views/revision.py                  |   2 +-
 swh/web/api/views/vault.py                     |  10 +-
 swh/web/auth/views.py                          | 114 ++++------
 swh/web/browse/browseurls.py                   |   1 +
 swh/web/browse/identifiers.py                  |   6 +-
 swh/web/browse/snapshot_context.py             | 303 ++++++++++++-------------
 swh/web/browse/views/content.py                |  98 ++++----
 swh/web/browse/views/directory.py              |  77 +++----
 swh/web/browse/views/origin.py                 |  16 +-
 swh/web/browse/views/release.py                |  73 +++---
 swh/web/browse/views/revision.py               | 225 +++++++++---------
 swh/web/common/exc.py                          |  14 +-
 swh/web/common/middlewares.py                  |  18 ++
 swh/web/settings/common.py                     |   2 +
 swh/web/settings/tests.py                      |   2 +-
 swh/web/tests/admin/test_origin_save.py        |  46 ++--
 swh/web/tests/api/test_apidoc.py               |  44 ++--
 swh/web/tests/api/test_apiresponse.py          |  42 ++--
 swh/web/tests/api/views/__init__.py            |  71 ------
 swh/web/tests/api/views/test_content.py        |  21 +-
 swh/web/tests/api/views/test_directory.py      |   5 +-
 swh/web/tests/api/views/test_graph.py          |  37 +--
 swh/web/tests/api/views/test_identifiers.py    |   2 +-
 swh/web/tests/api/views/test_origin.py         |   6 +-
 swh/web/tests/api/views/test_origin_save.py    |   2 +-
 swh/web/tests/api/views/test_ping.py           |   2 +-
 swh/web/tests/api/views/test_release.py        |   5 +-
 swh/web/tests/api/views/test_revision.py       |   9 +-
 swh/web/tests/api/views/test_snapshot.py       |   5 +-
 swh/web/tests/api/views/test_stat.py           |   2 +-
 swh/web/tests/api/views/test_vault.py          |  21 +-
 swh/web/tests/auth/test_api_auth.py            |  21 +-
 swh/web/tests/auth/test_middlewares.py         |   7 +-
 swh/web/tests/auth/test_views.py               | 134 ++++++-----
 swh/web/tests/browse/views/test_content.py     | 129 ++++++-----
 swh/web/tests/browse/views/test_directory.py   |  43 ++--
 swh/web/tests/browse/views/test_identifiers.py |  52 ++---
 swh/web/tests/browse/views/test_origin.py      | 175 +++++++-------
 swh/web/tests/browse/views/test_release.py     |  20 +-
 swh/web/tests/browse/views/test_revision.py    |  45 ++--
 swh/web/tests/common/test_middlewares.py       |  43 ++++
 swh/web/tests/misc/test_badges.py              |  45 +++-
 swh/web/tests/misc/test_metrics.py             |   8 +-
 swh/web/tests/misc/test_origin_save.py         |  25 +-
 swh/web/tests/utils.py                         | 200 ++++++++++++++++
 50 files changed, 1228 insertions(+), 1133 deletions(-)
 create mode 100644 swh/web/tests/common/test_middlewares.py
 create mode 100644 swh/web/tests/utils.py
Changes applied before test
commit 0921e5de947dfea74e213d8fddb553f3b02a56f5
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Thu Oct 15 19:22:17 2020 +0200

    tests: Improve HTTP errors reporting
    
    Add helper functions to check HTTP responses in tests implementation.
    
    If an unexpected HTTP status code is encountered, the traceback that led to
    the error will be displayed in pytest report.
    
    Closes T2657

commit 706829d86bfcaf2f7f6dfaf33a2bc071d928fa7e
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 18:04:04 2020 +0200

    browse: Improve error handling
    
    Use a dedicated django middleware to handle uncaught exception raised when
    processing a view and generate error response.
    
    Related to T2657

commit 65339606f4a1868665d0355beac7b5d6d0fa84ea
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 16:44:55 2020 +0200

    api: Improve error handling and response management
    
    Use a custom DRF exception handler to generate an error response when an
    exception is raised in a view.
    
    Move api response creation from the api_doc decorator to the api_route one.
    
    Remove the handle_response parameter from the api_doc decorator.
    
    Related to T2657

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/416/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/416/console

vlorentz added a subscriber: vlorentz.

great! thanks!

This revision is now accepted and ready to land.Oct 15 2020, 8:03 PM

Build has FAILED

Patch application report for D4278 (id=15126)

Could not rebase; Attempt merge onto d948e60ecd...

Updating d948e60e..b599f514
Fast-forward
 swh/web/api/apidoc.py                          |  24 +-
 swh/web/api/apiresponse.py                     |  61 +++--
 swh/web/api/apiurls.py                         |  44 +++-
 swh/web/api/views/content.py                   |   2 +-
 swh/web/api/views/origin_save.py               |   2 +-
 swh/web/api/views/revision.py                  |   2 +-
 swh/web/api/views/vault.py                     |  10 +-
 swh/web/auth/views.py                          | 114 ++++------
 swh/web/browse/browseurls.py                   |   1 +
 swh/web/browse/identifiers.py                  |   6 +-
 swh/web/browse/snapshot_context.py             | 303 ++++++++++++-------------
 swh/web/browse/views/content.py                |  98 ++++----
 swh/web/browse/views/directory.py              |  77 +++----
 swh/web/browse/views/origin.py                 |  16 +-
 swh/web/browse/views/release.py                |  73 +++---
 swh/web/browse/views/revision.py               | 225 +++++++++---------
 swh/web/common/exc.py                          |  14 +-
 swh/web/common/middlewares.py                  |  18 ++
 swh/web/settings/common.py                     |   2 +
 swh/web/settings/tests.py                      |   2 +-
 swh/web/tests/admin/test_origin_save.py        |  46 ++--
 swh/web/tests/api/test_apidoc.py               |  44 ++--
 swh/web/tests/api/test_apiresponse.py          |  42 ++--
 swh/web/tests/api/views/__init__.py            |  71 ------
 swh/web/tests/api/views/test_content.py        |  21 +-
 swh/web/tests/api/views/test_directory.py      |   5 +-
 swh/web/tests/api/views/test_graph.py          |  37 +--
 swh/web/tests/api/views/test_identifiers.py    |   2 +-
 swh/web/tests/api/views/test_origin.py         |   6 +-
 swh/web/tests/api/views/test_origin_save.py    |   2 +-
 swh/web/tests/api/views/test_ping.py           |   2 +-
 swh/web/tests/api/views/test_release.py        |   5 +-
 swh/web/tests/api/views/test_revision.py       |   9 +-
 swh/web/tests/api/views/test_snapshot.py       |   5 +-
 swh/web/tests/api/views/test_stat.py           |   2 +-
 swh/web/tests/api/views/test_vault.py          |  21 +-
 swh/web/tests/auth/test_api_auth.py            |  21 +-
 swh/web/tests/auth/test_middlewares.py         |   7 +-
 swh/web/tests/auth/test_views.py               | 134 ++++++-----
 swh/web/tests/browse/views/test_content.py     | 129 ++++++-----
 swh/web/tests/browse/views/test_directory.py   |  43 ++--
 swh/web/tests/browse/views/test_identifiers.py |  52 ++---
 swh/web/tests/browse/views/test_origin.py      | 175 +++++++-------
 swh/web/tests/browse/views/test_release.py     |  20 +-
 swh/web/tests/browse/views/test_revision.py    |  45 ++--
 swh/web/tests/common/test_middlewares.py       |  43 ++++
 swh/web/tests/misc/test_badges.py              |  45 +++-
 swh/web/tests/misc/test_metrics.py             |   8 +-
 swh/web/tests/misc/test_origin_save.py         |  25 +-
 swh/web/tests/utils.py                         | 200 ++++++++++++++++
 50 files changed, 1228 insertions(+), 1133 deletions(-)
 create mode 100644 swh/web/tests/common/test_middlewares.py
 create mode 100644 swh/web/tests/utils.py
Changes applied before test
commit b599f5141aae6ed7be18c4deffcc8f08b157bbc5
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Thu Oct 15 19:22:17 2020 +0200

    tests: Improve HTTP errors reporting
    
    Add helper functions to check HTTP responses in tests implementation.
    
    If an unexpected HTTP status code is encountered, the traceback that led to
    the error will be displayed in pytest report.
    
    Closes T2657

commit 1c043710cbde5df2cbabef8a00b49f25c432a567
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 18:04:04 2020 +0200

    django: Improve error handling
    
    Use a dedicated django middleware to handle uncaught exception raised when
    processing a view and generate error response.
    
    Related to T2657

commit 65339606f4a1868665d0355beac7b5d6d0fa84ea
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 16:44:55 2020 +0200

    api: Improve error handling and response management
    
    Use a custom DRF exception handler to generate an error response when an
    exception is raised in a view.
    
    Move api response creation from the api_doc decorator to the api_route one.
    
    Remove the handle_response parameter from the api_doc decorator.
    
    Related to T2657

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/418/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/418/console

Rebase and fix cypress tests

Build is green

Patch application report for D4278 (id=15130)

Could not rebase; Attempt merge onto d948e60ecd...

Updating d948e60e..4c45e0c0
Fast-forward
 swh/web/api/apidoc.py                          |  24 +-
 swh/web/api/apiresponse.py                     |  61 +++--
 swh/web/api/apiurls.py                         |  44 +++-
 swh/web/api/views/content.py                   |   2 +-
 swh/web/api/views/origin_save.py               |   2 +-
 swh/web/api/views/revision.py                  |   2 +-
 swh/web/api/views/vault.py                     |  10 +-
 swh/web/auth/views.py                          | 114 ++++------
 swh/web/browse/identifiers.py                  |   6 +-
 swh/web/browse/snapshot_context.py             | 303 ++++++++++++-------------
 swh/web/browse/views/content.py                |  98 ++++----
 swh/web/browse/views/directory.py              |  77 +++----
 swh/web/browse/views/origin.py                 |  16 +-
 swh/web/browse/views/release.py                |  73 +++---
 swh/web/browse/views/revision.py               | 225 +++++++++---------
 swh/web/common/exc.py                          |  14 +-
 swh/web/common/middlewares.py                  |  18 ++
 swh/web/settings/common.py                     |   2 +
 swh/web/settings/tests.py                      |   3 +-
 swh/web/tests/admin/test_origin_save.py        |  46 ++--
 swh/web/tests/api/test_apidoc.py               |  44 ++--
 swh/web/tests/api/test_apiresponse.py          |  42 ++--
 swh/web/tests/api/views/__init__.py            |  71 ------
 swh/web/tests/api/views/test_content.py        |  21 +-
 swh/web/tests/api/views/test_directory.py      |   5 +-
 swh/web/tests/api/views/test_graph.py          |  37 +--
 swh/web/tests/api/views/test_identifiers.py    |   2 +-
 swh/web/tests/api/views/test_origin.py         |   6 +-
 swh/web/tests/api/views/test_origin_save.py    |   2 +-
 swh/web/tests/api/views/test_ping.py           |   2 +-
 swh/web/tests/api/views/test_release.py        |   5 +-
 swh/web/tests/api/views/test_revision.py       |   9 +-
 swh/web/tests/api/views/test_snapshot.py       |   5 +-
 swh/web/tests/api/views/test_stat.py           |   2 +-
 swh/web/tests/api/views/test_vault.py          |  21 +-
 swh/web/tests/auth/test_api_auth.py            |  21 +-
 swh/web/tests/auth/test_middlewares.py         |   7 +-
 swh/web/tests/auth/test_views.py               | 134 ++++++-----
 swh/web/tests/browse/views/test_content.py     | 129 ++++++-----
 swh/web/tests/browse/views/test_directory.py   |  43 ++--
 swh/web/tests/browse/views/test_identifiers.py |  52 ++---
 swh/web/tests/browse/views/test_origin.py      | 175 +++++++-------
 swh/web/tests/browse/views/test_release.py     |  20 +-
 swh/web/tests/browse/views/test_revision.py    |  45 ++--
 swh/web/tests/common/test_middlewares.py       |  43 ++++
 swh/web/tests/misc/test_badges.py              |  45 +++-
 swh/web/tests/misc/test_metrics.py             |   8 +-
 swh/web/tests/misc/test_origin_save.py         |  25 +-
 swh/web/tests/utils.py                         | 196 ++++++++++++++++
 49 files changed, 1224 insertions(+), 1133 deletions(-)
 create mode 100644 swh/web/tests/common/test_middlewares.py
 create mode 100644 swh/web/tests/utils.py
Changes applied before test
commit 4c45e0c0c2dd7107ee2973e6289e063b7c0f8b1e
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Thu Oct 15 19:22:17 2020 +0200

    tests: Improve HTTP errors reporting
    
    Add helper functions to check HTTP responses in tests implementation.
    
    If an unexpected HTTP status code is encountered, the traceback that led to
    the error will be displayed in pytest report.
    
    Closes T2657

commit 11c2bbcc380b62dfe71630bece55f7c1bed76a40
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 18:04:04 2020 +0200

    django: Improve error handling
    
    Use a dedicated django middleware to handle uncaught exception raised when
    processing a view and generate error response.
    
    Related to T2657

commit bd8b47d67345028ac843034cdcbe602e11e28c95
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 16:44:55 2020 +0200

    api: Improve error handling and response management
    
    Use a custom DRF exception handler to generate an error response when an
    exception is raised in a view.
    
    Move api response creation from the api_doc decorator to the api_route one.
    
    Remove the handle_response parameter from the api_doc decorator.
    
    Related to T2657

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/421/ for more details.

(did not look much at the implementation) but the problem is solves is cool \o/, thanks.

Build is green

Patch application report for D4278 (id=15250)

Could not rebase; Attempt merge onto 7fbb185005...

Updating 7fbb1850..d3b1bf38
Fast-forward
 swh/web/api/apidoc.py                          |  24 +-
 swh/web/api/apiresponse.py                     |  61 +++--
 swh/web/api/apiurls.py                         |  44 +++-
 swh/web/api/views/content.py                   |   2 +-
 swh/web/api/views/origin_save.py               |   2 +-
 swh/web/api/views/revision.py                  |   2 +-
 swh/web/api/views/vault.py                     |  10 +-
 swh/web/auth/views.py                          | 114 ++++------
 swh/web/browse/identifiers.py                  |   6 +-
 swh/web/browse/snapshot_context.py             | 303 ++++++++++++-------------
 swh/web/browse/views/content.py                |  98 ++++----
 swh/web/browse/views/directory.py              |  77 +++----
 swh/web/browse/views/origin.py                 |  16 +-
 swh/web/browse/views/release.py                |  73 +++---
 swh/web/browse/views/revision.py               | 225 +++++++++---------
 swh/web/common/exc.py                          |  14 +-
 swh/web/common/middlewares.py                  |  18 ++
 swh/web/settings/common.py                     |   2 +
 swh/web/settings/tests.py                      |   3 +-
 swh/web/tests/admin/test_origin_save.py        |  46 ++--
 swh/web/tests/api/test_apidoc.py               |  44 ++--
 swh/web/tests/api/test_apiresponse.py          |  42 ++--
 swh/web/tests/api/views/__init__.py            |  71 ------
 swh/web/tests/api/views/test_content.py        |  21 +-
 swh/web/tests/api/views/test_directory.py      |   5 +-
 swh/web/tests/api/views/test_graph.py          |  37 +--
 swh/web/tests/api/views/test_identifiers.py    |   2 +-
 swh/web/tests/api/views/test_origin.py         |   6 +-
 swh/web/tests/api/views/test_origin_save.py    |   2 +-
 swh/web/tests/api/views/test_ping.py           |   2 +-
 swh/web/tests/api/views/test_release.py        |   5 +-
 swh/web/tests/api/views/test_revision.py       |   9 +-
 swh/web/tests/api/views/test_snapshot.py       |   5 +-
 swh/web/tests/api/views/test_stat.py           |   2 +-
 swh/web/tests/api/views/test_vault.py          |  21 +-
 swh/web/tests/auth/test_api_auth.py            |  21 +-
 swh/web/tests/auth/test_middlewares.py         |   7 +-
 swh/web/tests/auth/test_views.py               | 134 ++++++-----
 swh/web/tests/browse/views/test_content.py     | 129 ++++++-----
 swh/web/tests/browse/views/test_directory.py   |  43 ++--
 swh/web/tests/browse/views/test_identifiers.py |  52 ++---
 swh/web/tests/browse/views/test_origin.py      | 175 +++++++-------
 swh/web/tests/browse/views/test_release.py     |  20 +-
 swh/web/tests/browse/views/test_revision.py    |  45 ++--
 swh/web/tests/common/test_middlewares.py       |  43 ++++
 swh/web/tests/misc/test_badges.py              |  45 +++-
 swh/web/tests/misc/test_metrics.py             |   8 +-
 swh/web/tests/misc/test_origin_save.py         |  25 +-
 swh/web/tests/utils.py                         | 196 ++++++++++++++++
 49 files changed, 1224 insertions(+), 1133 deletions(-)
 create mode 100644 swh/web/tests/common/test_middlewares.py
 create mode 100644 swh/web/tests/utils.py
Changes applied before test
commit d3b1bf3839fc90805e5f3167455dee5d2b3ebfb9
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Thu Oct 15 19:22:17 2020 +0200

    tests: Improve HTTP errors reporting
    
    Add helper functions to check HTTP responses in tests implementation.
    
    If an unexpected HTTP status code is encountered, the traceback that led to
    the error will be displayed in pytest report.
    
    Closes T2657

commit 3add0d1ee7ca0b2b4b7c428ebfcdd5ba7a6be397
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 18:04:04 2020 +0200

    django: Improve error handling
    
    Use a dedicated django middleware to handle uncaught exception raised when
    processing a view and generate error response.
    
    Related to T2657

commit 7c5e04cca483dda98c76d7482a7c345a03107676
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Oct 7 16:44:55 2020 +0200

    api: Improve error handling and response management
    
    Use a custom DRF exception handler to generate an error response when an
    exception is raised in a view.
    
    Move api response creation from the api_doc decorator to the api_route one.
    
    Remove the handle_response parameter from the api_doc decorator.
    
    Related to T2657

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/424/ for more details.

This revision was automatically updated to reflect the committed changes.