Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_exception.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020-2021 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 General Public License version 3, or any later version | # License: GNU 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 | ||||
from django.db.utils import OperationalError | from django.db.utils import OperationalError | ||||
from rest_framework.exceptions import APIException | from rest_framework.exceptions import APIException | ||||
from rest_framework.response import Response | from rest_framework.response import Response | ||||
Show All 28 Lines | |||||
def test_custom_exception_handler_default_behavior_maintained(mocker): | def test_custom_exception_handler_default_behavior_maintained(mocker): | ||||
"""Other internal errors are transmitted as is | """Other internal errors are transmitted as is | ||||
""" | """ | ||||
fake_exception = APIException("Fake internal error", 500) | fake_exception = APIException("Fake internal error", 500) | ||||
fake_response = Response( | fake_response = Response( | ||||
exception=fake_exception, status=fake_exception.status_code | exception=fake_exception, status=fake_exception.status_code | ||||
) | ) | ||||
mock_exception_handler = mocker.patch("swh.deposit.exception.exception_handler") | mock_exception_handler = mocker.patch("rest_framework.views.exception_handler") | ||||
mock_exception_handler.return_value = fake_response | mock_exception_handler.return_value = fake_response | ||||
response = custom_exception_handler(fake_exception, {}) | response = custom_exception_handler(fake_exception, {}) | ||||
assert response is not None | assert response is not None | ||||
assert response == fake_response | assert response == fake_response |