mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
PR fixes
- Add test for no argument - noqa for Flake8 long line error on heap javascript include - Ran isort on files
This commit is contained in:
parent
34a195cbab
commit
ec30d6aa9b
3 changed files with 15 additions and 10 deletions
|
|
@ -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 = """
|
||||
<script type="text/javascript">
|
||||
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
|
||||
<script type="text/javascript">
|
||||
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
|
||||
heap.load("%(tracker_id)s");
|
||||
</script>
|
||||
|
||||
"""
|
||||
""" # 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()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ sys.path.append(os.path.dirname(os.path.abspath('.')))
|
|||
|
||||
import analytical # noqa
|
||||
|
||||
|
||||
# -- General configuration --------------------------------------------------
|
||||
|
||||
project = 'django-analytical'
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue