From 7226ca57a28a34b1fa726021b74bb8b8bd126d8d Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 3 Jan 2021 22:01:46 +0100 Subject: [PATCH] Render spaceless HTML --- articles/templates/articles/base.html | 2 ++ articles/tests/test_html_views.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/articles/templates/articles/base.html b/articles/templates/articles/base.html index dbfeab5..4a853d3 100644 --- a/articles/templates/articles/base.html +++ b/articles/templates/articles/base.html @@ -1,5 +1,6 @@ +{% spaceless %} @@ -40,4 +41,5 @@

+{% endspaceless %} diff --git a/articles/tests/test_html_views.py b/articles/tests/test_html_views.py index 78612eb..b2da102 100644 --- a/articles/tests/test_html_views.py +++ b/articles/tests/test_html_views.py @@ -1,4 +1,5 @@ import pytest +from django.template import Context, Template from django.test import Client from django.urls import reverse from model_bakery import baker @@ -48,7 +49,15 @@ def _assert_article_is_rendered(item: Article, res): assert res.status_code == 200 content = res.content.decode("utf-8") assert item.title in content - assert item.get_formatted_content in content + html = item.get_formatted_content + html = get_spaceless_html(html) + assert html in content + + +def get_spaceless_html(html): + context = Context({}) + html = Template("{% spaceless %}" + html + "{% endspaceless %}").render(context) + return html @pytest.mark.django_db