"""Tests for exception handler.""" import pytest import werkzeug from product_review import handlers @pytest.mark.parametrize( ( "test_description", "exception", "code_key", "expected_code", "message_key", "expected_message", ), [ ( "500 error", werkzeug.exceptions.InternalServerError("this is a 500"), "code", 500, "data", b'{"code": "error", "message": "this is a 500"}', ), ( "400 error", werkzeug.exceptions.BadRequest("this is a 400"), "code", 400, "data", b'{"code": "error", "message": "this is a 400"}', ), ( "Arbitrary Exception", Exception("oops"), "status_code", 500, "json", {"code": "bad_request", "message": "oops"}, ), ], ) def test_exception_handler( test_description, exception, code_key, expected_code, message_key, expected_message, fixture_client, mocker, ): """Test exception_handler.""" mocker.patch.object(handlers, "jsonify", side_effect=exception) result = fixture_client.get("/hello/") assert result.status_code == expected_code assert getattr(result, message_key) == expected_message