Render spaceless HTML

This commit is contained in:
Gabriel Augendre 2021-01-03 22:01:46 +01:00
parent d59565fa82
commit 7226ca57a2
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 12 additions and 1 deletions

View file

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
{% spaceless %}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@ -40,4 +41,5 @@
</p>
</footer>
</body>
{% endspaceless %}
</html>

View file

@ -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