Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_middlewares.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | # import pytest | ||||
from django.test import modify_settings | # from django.test import modify_settings | ||||
from swh.web.common.utils import reverse | # from swh.web.common.utils import reverse | ||||
# @modify_settings( | |||||
# MIDDLEWARE={"remove": ["swh.web.common.middlewares.ExceptionMiddleware"]} | |||||
# ) | |||||
# def test_exception_middleware_disabled(client, mocker, snapshot): | |||||
# mock_browse_snapshot_directory = mocker.patch( | |||||
# "swh.web.browse.views.snapshot.browse_snapshot_directory" | |||||
# ) | |||||
# mock_browse_snapshot_directory.side_effect = Exception("Something went wrong") | |||||
@modify_settings( | # url = reverse("browse-snapshot-directory", url_args={"snapshot_id": snapshot}) | ||||
MIDDLEWARE={"remove": ["swh.web.common.middlewares.ExceptionMiddleware"]} | |||||
) | |||||
def test_exception_middleware_disabled(client, mocker, snapshot): | |||||
mock_browse_snapshot_directory = mocker.patch( | |||||
"swh.web.browse.views.snapshot.browse_snapshot_directory" | |||||
) | |||||
mock_browse_snapshot_directory.side_effect = Exception("Something went wrong") | |||||
url = reverse("browse-snapshot-directory", url_args={"snapshot_id": snapshot}) | # with pytest.raises(Exception, match="Something went wrong"): | ||||
# client.get(url) | |||||
with pytest.raises(Exception, match="Something went wrong"): | |||||
client.get(url) | |||||
# def test_exception_middleware_enabled(client, mocker, snapshot): | |||||
# mock_browse_snapshot_directory = mocker.patch( | |||||
# "swh.web.browse.views.snapshot.browse_snapshot_directory" | |||||
# ) | |||||
# mock_browse_snapshot_directory.side_effect = Exception("Something went wrong") | |||||
def test_exception_middleware_enabled(client, mocker, snapshot): | # url = reverse("browse-snapshot-directory", url_args={"snapshot_id": snapshot}) | ||||
mock_browse_snapshot_directory = mocker.patch( | |||||
"swh.web.browse.views.snapshot.browse_snapshot_directory" | |||||
) | |||||
mock_browse_snapshot_directory.side_effect = Exception("Something went wrong") | |||||
url = reverse("browse-snapshot-directory", url_args={"snapshot_id": snapshot}) | # resp = client.get(url) | ||||
# assert resp.status_code == 500 | |||||
resp = client.get(url) | # assert hasattr(resp, "traceback") | ||||
assert resp.status_code == 500 | # assert "Traceback" in getattr(resp, "traceback") | ||||
assert hasattr(resp, "traceback") | |||||
assert "Traceback" in getattr(resp, "traceback") |