diff --git a/inspira/responses.py b/inspira/responses.py index 417bae6..01b796b 100644 --- a/inspira/responses.py +++ b/inspira/responses.py @@ -227,5 +227,11 @@ def __init__(self, url: str, status_code=HTTPStatus.FOUND, headers=None): class ForbiddenResponse(HttpResponse): - def __init__(self, content=None, status_code=HTTPStatus.FORBIDDEN, headers=None): - super().__init__(content, status_code, TEXT_PLAIN, headers) + def __init__( + self, + content=None, + content_type=TEXT_PLAIN, + status_code=HTTPStatus.FORBIDDEN, + headers=None, + ): + super().__init__(content, status_code, content_type, headers) diff --git a/tests/test_responses.py b/tests/test_responses.py index 065c366..82b79da 100644 --- a/tests/test_responses.py +++ b/tests/test_responses.py @@ -14,6 +14,7 @@ HttpResponseRedirect, JsonResponse, TemplateResponse, + ForbiddenResponse, ) @@ -313,3 +314,34 @@ async def test_set_cookie(): assert "user=john_doe" in headers[0] assert "Max-Age=3600" in headers[0] assert "Path=/" in headers[0] + + +def test_forbidden_response_default_value(): + response = ForbiddenResponse() + + assert response.content is None + assert response.status_code == HTTPStatus.FORBIDDEN + assert response.content_type == TEXT_PLAIN + + +def test_forbidden_response_custom_values(): + content = "This is forbidden" + custom_status_code = HTTPStatus.UNAUTHORIZED + custom_headers = {"Custom-Header": "Value"} + + response = ForbiddenResponse( + content=content, status_code=custom_status_code, headers=custom_headers + ) + + assert response.content == content + assert response.status_code == custom_status_code + assert response.content_type == TEXT_PLAIN + assert response.headers == custom_headers + + +def test_forbidden_response_content_type_json(): + content = {"message": "You don't have access"} + response = ForbiddenResponse(content=content, content_type=APPLICATION_JSON) + + assert response.content == content + assert response.content_type == APPLICATION_JSON