From 7544bd10e26c7333319e1f6f273125b2a0c7d7ed Mon Sep 17 00:00:00 2001 From: adriaan Date: Thu, 23 Mar 2023 21:38:08 +0100 Subject: [PATCH] Add regression test for #239 (broke extends tags) + minor tweaks (#247) --- .gitignore | 6 +++ .../extendable_template_with_blocks.html | 12 +++++ tests/templates/incrementer.html | 3 +- tests/test_templatetags.py | 47 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/templates/extendable_template_with_blocks.html diff --git a/.gitignore b/.gitignore index b642bdb9..5ac43f5e 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,9 @@ target/ # as project supports variety of Django versions poetry.lock pyproject.toml + +# PyCharm +.idea/ + +# Python environment +.venv/ diff --git a/tests/templates/extendable_template_with_blocks.html b/tests/templates/extendable_template_with_blocks.html new file mode 100644 index 00000000..9cbfb9ee --- /dev/null +++ b/tests/templates/extendable_template_with_blocks.html @@ -0,0 +1,12 @@ +{% load component_tags %} + + + +
+
+ {% block body %} + {% endblock %} +
+
+ + \ No newline at end of file diff --git a/tests/templates/incrementer.html b/tests/templates/incrementer.html index db172128..687c8e02 100644 --- a/tests/templates/incrementer.html +++ b/tests/templates/incrementer.html @@ -1,2 +1,3 @@ -{% load component_tags %}

value={{ value }};calls={{ calls }}

+{% load component_tags %} +

value={{ value }};calls={{ calls }}

{% slot 'content' %}{% endslot %} \ No newline at end of file diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 38de7d50..b7987bb2 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -1055,3 +1055,50 @@ class ConditionalIfFilledSlotsTests(SimpleTestCase): """ rendered = Template(template).render(Context({})) self.assertHTMLEqual(rendered, expected) + + +class RegressionTests(SimpleTestCase): + """Ensure we don't break the same thing AGAIN.""" + + def setUp(self): + component.registry.clear() + super().setUp() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + component.registry.clear() + + def test_extends_tag_works(self): + component.registry.register("slotted_component", SlottedComponent) + template = """ + {% extends "extendable_template_with_blocks.html" %} + {% load component_tags %} + {% block body %} + {% component_block "slotted_component" %} + {% fill "header" %}{% endfill %} + {% fill "main" %} + TEST + {% endfill %} + {% fill "footer" %}{% endfill %} + {% endcomponent_block %} + {% endblock %} + """ + rendered = Template(template).render(Context()) + expected = """ + + + +
+
+ +
+
TEST
+ +
+
+
+ + + """ + self.assertHTMLEqual(rendered, expected)