From f0b46266878773098f4582518722b456f89b65bb Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Thu, 21 Jul 2022 09:58:32 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20tag=20overrides=E2=80=99=20default=5Fhtml?= =?UTF-8?q?=20taking=20precedence=20over=20real=20tag=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pattern_library/monkey_utils.py | 3 +-- .../patterns/atoms/tags_test_atom/tags_test_atom.html | 6 ++++-- tests/tests/test_tags.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pattern_library/monkey_utils.py b/pattern_library/monkey_utils.py index 956e638b..1859562f 100644 --- a/pattern_library/monkey_utils.py +++ b/pattern_library/monkey_utils.py @@ -7,7 +7,6 @@ from pattern_library.utils import is_pattern_library_context, render_pattern logger = logging.getLogger(__name__) -UNSPECIFIED = object() def override_tag( @@ -78,7 +77,7 @@ def node_render(context): # Render result instead of the tag, as a string. # See https://github.com/torchbox/django-pattern-library/issues/166. return str(result) - elif default_html is not UNSPECIFIED: + elif default_html is not None: # Render provided default; # if no stub data supplied. return default_html diff --git a/tests/templates/patterns/atoms/tags_test_atom/tags_test_atom.html b/tests/templates/patterns/atoms/tags_test_atom/tags_test_atom.html index c7945bc8..ce9895c1 100644 --- a/tests/templates/patterns/atoms/tags_test_atom/tags_test_atom.html +++ b/tests/templates/patterns/atoms/tags_test_atom/tags_test_atom.html @@ -4,10 +4,12 @@ SAND{% error_tag none %}WICH SAND{% error_tag zero %}WICH -POTA{% default_html_tag page.url %}TO +POTA{% default_html_tag page.url %}TO POTA{% default_html_tag page.child.url %}TO POTA{% default_html_tag None %}TO POTA{% default_html_tag_falsey empty_string %}TO1 POTA{% default_html_tag_falsey none %}TO2 -POTA{% default_html_tag_falsey zero %}TO3 \ No newline at end of file +POTA{% default_html_tag_falsey zero %}TO3 + +Real tag usage: {% pageurl page %} diff --git a/tests/tests/test_tags.py b/tests/tests/test_tags.py index ee88b900..37dabf44 100644 --- a/tests/tests/test_tags.py +++ b/tests/tests/test_tags.py @@ -4,6 +4,17 @@ class TagsTestCase(SimpleTestCase): + def test_real_tag_usage(self): + response = self.client.get( + reverse( + "pattern_library:render_pattern", + kwargs={ + "pattern_template_name": "patterns/atoms/tags_test_atom/tags_test_atom.html" + }, + ) + ) + self.assertContains(response, "Real tag usage: /page/url") + def test_falsey_raw_values_for_tag_output(self): response = self.client.get( reverse(