mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-05-24 14:53:51 +00:00
Added tests for Clickmap integration
This commit is contained in:
parent
fe12e97fba
commit
a631acb591
3 changed files with 55 additions and 10 deletions
|
|
@ -17,16 +17,14 @@ TRACKING_CODE = """
|
|||
<script type="text/javascript">
|
||||
var clickmapConfig = {tracker: '%(tracker_id)', version:'2'};
|
||||
window.clickmapAsyncInit = function(){ __clickmap.init(clickmapConfig); };
|
||||
(function() { var _cmf = document.createElement('script'); _cmf.async = true;
|
||||
(function() { var _cmf = document.createElement('script'); _cmf.async = true;
|
||||
_cmf.src = document.location.protocol + '//www.clickmap.ch/tracker.js?t=';
|
||||
_cmf.src += clickmapConfig.tracker; _cmf.id += 'clickmap_tracker';
|
||||
_cmf.src += '&v='+clickmapConfig.version+'&now='+(new Date().getTime());
|
||||
_cmf.src += '&v='+clickmapConfig.version+'&now='+(new Date().getTime());
|
||||
if (document.getElementById('clickmap_tracker')==null) {
|
||||
document.getElementsByTagName('head')[0].appendChild(_cmf); }}());
|
||||
document.getElementsByTagName('head')[0].appendChild(_cmf); }}());
|
||||
</script>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
register = Library()
|
||||
|
||||
|
|
@ -45,9 +43,10 @@ def clickmap(parser, token):
|
|||
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
|
||||
return ClickmapNode()
|
||||
|
||||
|
||||
class ClickmapNode(Node):
|
||||
def __init__(self):
|
||||
self.tracker_id = get_required_setting('CLICKMAP_TRACKER_ID',
|
||||
self.tracker_id = get_required_setting('CLICKMAP_TRACKER_ID',
|
||||
CLICKMAP_TRACKER_ID_RE,
|
||||
"must be a (string containing) a number")
|
||||
|
||||
|
|
@ -70,10 +69,10 @@ class ClickmapNode(Node):
|
|||
"""
|
||||
html = TRACKING_CODE % {'portal_id': self.portal_id,
|
||||
'domain': self.domain}
|
||||
if is_internal_ip(context, 'HUBSPOT'):
|
||||
html = disable_html(html, 'HubSpot')
|
||||
if is_internal_ip(context, 'CLICKMAP'):
|
||||
html = disable_html(html, 'Clickmap')
|
||||
return html
|
||||
|
||||
|
||||
|
||||
def contribute_to_analytical(add_node):
|
||||
ClickmapNode() # ensure properly configured
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
Tests for the Clickmap template tags and filters.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.http import HttpRequest
|
||||
from django.template import Context
|
||||
|
||||
from analytical.templatetags.clicky import ClickmapNode
|
||||
from analytical.tests.utils import TagTestCase, override_settings, SETTING_DELETED
|
||||
from analytical.utils import AnalyticalException
|
||||
|
||||
|
||||
@override_settings(CLICKMAP_TRACKER_ID='12345')
|
||||
class ClickyTagTestCase(TagTestCase):
|
||||
"""
|
||||
Tests for the ``clickmap`` template tag.
|
||||
"""
|
||||
|
||||
def test_tag(self):
|
||||
r = self.render_tag('clicjmap', 'clickmap')
|
||||
self.assertTrue("tracker: '12345', version:'2'};" in r, r)
|
||||
|
||||
def test_node(self):
|
||||
r = ClickmapNode().render(Context({}))
|
||||
self.assertTrue("tracker: '12345', version:'2'};" in r, r)
|
||||
|
||||
@override_settings(CLICKMAP_TRACKER_ID=SETTING_DELETED)
|
||||
def test_no_site_id(self):
|
||||
self.assertRaises(AnalyticalException, ClickmapNode)
|
||||
|
||||
@override_settings(CLICKMAP_TRACKER_ID='abc')
|
||||
def test_wrong_site_id(self):
|
||||
self.assertRaises(AnalyticalException, ClickyNode)
|
||||
|
||||
@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
|
||||
def test_render_internal_ip(self):
|
||||
req = HttpRequest()
|
||||
req.META['REMOTE_ADDR'] = '1.1.1.1'
|
||||
context = Context({'request': req})
|
||||
r = ClickmapNode().render(context)
|
||||
self.assertTrue(r.startswith(
|
||||
'<!-- Clickmap disabled on internal IP address'), r)
|
||||
self.assertTrue(r.endswith('-->'), r)
|
||||
|
|
@ -41,7 +41,7 @@ Configuration
|
|||
=============
|
||||
|
||||
Before you can use the Clickmap integration, you must first set your
|
||||
Clickmap Tracker Code ID. If you don't have a Clickmap account yet,
|
||||
Clickmap Tracker ID. If you don't have a Clickmap account yet,
|
||||
`sign up`_ to get your Tracker ID.
|
||||
|
||||
.. _`sign up`: http://www.getclickmap.com/
|
||||
|
|
|
|||
Loading…
Reference in a new issue