diff --git a/analytical/templatetags/heap.py b/analytical/templatetags/heap.py index 1cd85ac..d64e336 100644 --- a/analytical/templatetags/heap.py +++ b/analytical/templatetags/heap.py @@ -6,20 +6,24 @@ import re from django.template import Library, Node, TemplateSyntaxError -from analytical.utils import is_internal_ip, disable_html, get_required_setting - +from analytical.utils import disable_html, get_required_setting, is_internal_ip HEAP_TRACKER_ID_RE = re.compile(r'^\d+$') TRACKING_CODE = """ - -""" +""" # noqa register = Library() +def _validate_no_args(token): + bits = token.split_contents() + if len(bits) > 1: + raise TemplateSyntaxError("'%s' takes no arguments" % bits[0]) + @register.tag def heap(parser, token): @@ -30,9 +34,7 @@ def heap(parser, token): your heap tracker ID (as a string) in the ``HEAP_TRACKER_ID`` setting. """ - bits = token.split_contents() - if len(bits) > 1: - raise TemplateSyntaxError("'%s' takes no arguments" % bits[0]) + _validate_no_args(token) return HeapNode() diff --git a/docs/conf.py b/docs/conf.py index 7d86315..1894cd9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,6 @@ sys.path.append(os.path.dirname(os.path.abspath('.'))) import analytical # noqa - # -- General configuration -------------------------------------------------- project = 'django-analytical' diff --git a/tests/unit/test_tag_heap.py b/tests/unit/test_tag_heap.py index 60ccd27..c0c1863 100644 --- a/tests/unit/test_tag_heap.py +++ b/tests/unit/test_tag_heap.py @@ -4,7 +4,7 @@ Tests for the Heap template tags and filters. import pytest from django.http import HttpRequest -from django.template import Context +from django.template import Context, Template, TemplateSyntaxError from django.test.utils import override_settings from utils import TagTestCase @@ -25,6 +25,10 @@ class HeapTagTestCase(TagTestCase): def test_node(self): r = HeapNode().render(Context({})) assert "123456789" in r + + def test_tags_take_no_args(self): + with pytest.raises(TemplateSyntaxError, match="'heap' takes no arguments"): + Template('{% load heap %}{% heap "arg" %}').render(Context({})) @override_settings(HEAP_TRACKER_ID=None) def test_no_site_id(self):