"""Tests for exception handler.""" from typing import Any import pytest from video import handlers # noqa (handlers are imported for test client) from video.exceptions import InvalidReleaseStatus, InvalidRequest @pytest.mark.parametrize( ("side_effect", "expected_code"), [(Exception, 500), (InvalidRequest, 400)] ) def test_exception_handler( mocker: Any, client: Any, side_effect: type, expected_code: int ) -> None: """Test an uncaught Exception results in a 500 status code.""" mocker.patch.object(handlers, "jsonify", side_effect=side_effect, autospec=True) result = client.get("/hello/") assert result.status_code == expected_code def test_invalid_release_status_response_body(mocker: Any, client: Any) -> None: """Verify the on-the-wire JSON when InvalidReleaseStatus is raised.""" mocker.patch.object( handlers, "jsonify", side_effect=InvalidReleaseStatus, autospec=True ) result = client.get("/hello/") assert result.status_code == 400 assert result.get_json() == { "code": "invalid_release_status", "message": "Invalid release status", }