diff --git a/tests/test_html_signposting_middleware.py b/tests/test_html_signposting_middleware.py index c971dd1..8b87e6a 100644 --- a/tests/test_html_signposting_middleware.py +++ b/tests/test_html_signposting_middleware.py @@ -1,8 +1,8 @@ from bs4 import BeautifulSoup -from django.http import HttpResponse +from django.http import HttpResponse, JsonResponse from django_signposting.middleware import HtmlSignpostingMiddleware from signposting import LinkRel, Signpost - +import pytest def test_middleware_no_signposting(): response = HttpResponse("") @@ -13,6 +13,29 @@ def test_middleware_no_signposting(): assert "link" not in response.content.decode("utf-8") +def test_middleware_no_html(): + response = JsonResponse({"hello": "world"}) + response.status_code = 200 + response._signpost = [ + Signpost(LinkRel.author, "http://example.com") + ] + + middleware = HtmlSignpostingMiddleware(lambda request: response) + content = middleware(None).content + assert response.content == content + +def test_middleware_malformed_html(): + response = HttpResponse("Hello world") + response.status_code = 200 + response.content_type = "text/html" + response._signposts = [ + Signpost(LinkRel.author, "http://example.com") + ] + + middleware = HtmlSignpostingMiddleware(lambda request: response) + with pytest.raises(Exception): + middleware(None) + def test_middleware_signposting(): response = HttpResponse("") response.status_code = 200