Page MenuHomeSoftware Heritage

Improve HTTP errors reporting in tests
Closed, ResolvedPublic

Description

When testing webapp views and an unexpected HTTP status code is returned, tests reporting do not help to find the cause of the issue, see below:

_________________ test_content_origin_snapshot_release_browse __________________

client = <django.test.client.Client object at 0x7f9ce315e828>
archive_data = <swh.web.tests.conftest._ArchiveData object at 0x7f9ce781b6a0>

    @given(origin_with_multiple_visits())
>   def test_content_origin_snapshot_release_browse(client, archive_data, origin):

swh/web/tests/browse/views/test_content.py:477: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

client = <django.test.client.Client object at 0x7f9ce315e828>
archive_data = <swh.web.tests.conftest._ArchiveData object at 0x7f9ce781b6a0>
origin = {'archives': ['highlightjs-line-numbers.js.zip', 'highlightjs-line-numbers.js_visit2.zip'], 'type': 'git', 'url': 'https://github.com/wcoder/highlightjs-line-numbers.js'}

    @given(origin_with_multiple_visits())
    def test_content_origin_snapshot_release_browse(client, archive_data, origin):
        visits = archive_data.origin_visit_get(origin["url"])
        visit = random.choice(visits)
        snapshot = archive_data.snapshot_get(visit["snapshot"])
        branches, releases = process_snapshot_branches(snapshot)
        release_info = random.choice(releases)
    
        directory_content = archive_data.directory_ls(release_info["directory"])
        directory_file = random.choice(
            [e for e in directory_content if e["type"] == "file"]
        )
    
        url = reverse(
            "browse-content",
            url_args={"query_string": directory_file["checksums"]["sha1"]},
            query_params={
                "origin_url": origin["url"],
                "snapshot": snapshot["id"],
                "release": release_info["name"],
                "path": directory_file["name"],
            },
        )
    
        resp = client.get(url)
>       assert resp.status_code == 200
E       assert 500 == 200
E        +  where 500 = <HttpResponse status_code=500, "text/html; charset=utf-8">.status_code

swh/web/tests/browse/views/test_content.py:501: AssertionError
---------------------------------- Hypothesis ----------------------------------
Falsifying example: test_content_origin_snapshot_release_browse(
    client=<django.test.client.Client at 0x7f9ce315e828>,
    archive_data=<swh.web.tests.conftest._ArchiveData at 0x7f9ce781b6a0>,
    origin={'archives': ['highlightjs-line-numbers.js.zip',
      'highlightjs-line-numbers.js_visit2.zip'],
     'type': 'git',
     'url': 'https://github.com/wcoder/highlightjs-line-numbers.js'},
)

We should manage to display the stack trace that led to the HTTP error in order to gain some debugging time here.