mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Relax service code validation
This commit is contained in:
parent
c23b0abc02
commit
8649c07c24
16 changed files with 23 additions and 42 deletions
|
|
@ -15,7 +15,7 @@ from django.utils import simplejson
|
|||
from analytical.utils import is_internal_ip, disable_html, get_required_setting
|
||||
|
||||
|
||||
USER_ID_RE = re.compile(r'^\d{5}$')
|
||||
USER_ID_RE = re.compile(r'^\d+$')
|
||||
INIT_CODE = """<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>"""
|
||||
SETUP_CODE = """
|
||||
<script type="text/javascript">
|
||||
|
|
@ -78,9 +78,8 @@ def chartbeat_bottom(parser, token):
|
|||
|
||||
class ChartbeatBottomNode(Node):
|
||||
def __init__(self):
|
||||
self.user_id = get_required_setting(
|
||||
'CHARTBEAT_USER_ID', USER_ID_RE,
|
||||
"must be a string containing an five-digit number")
|
||||
self.user_id = get_required_setting('CHARTBEAT_USER_ID', USER_ID_RE,
|
||||
"must be (a string containing) a number")
|
||||
|
||||
def render(self, context):
|
||||
config = {'uid': self.user_id}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from analytical.utils import get_identity, is_internal_ip, disable_html, \
|
|||
get_required_setting
|
||||
|
||||
|
||||
SITE_ID_RE = re.compile(r'^\d{8}$')
|
||||
SITE_ID_RE = re.compile(r'^\d+$')
|
||||
TRACKING_CODE = """
|
||||
<script type="text/javascript">
|
||||
var clicky = { log: function(){ return; }, goal: function(){ return; }};
|
||||
|
|
@ -51,7 +51,7 @@ def clicky(parser, token):
|
|||
class ClickyNode(Node):
|
||||
def __init__(self):
|
||||
self.site_id = get_required_setting('CLICKY_SITE_ID', SITE_ID_RE,
|
||||
"must be a string containing an eight-digit number")
|
||||
"must be a (string containing) a number")
|
||||
|
||||
def render(self, context):
|
||||
custom = {}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from django.template import Library, Node, TemplateSyntaxError
|
|||
from analytical.utils import is_internal_ip, disable_html, get_required_setting
|
||||
|
||||
|
||||
ACCOUNT_NUMBER_RE = re.compile(r'^\d{8}$')
|
||||
ACCOUNT_NUMBER_RE = re.compile(r'^\d+$')
|
||||
SETUP_CODE = """<script type="text/javascript" src="//dnn506yrbagrg.cloudfront.net/pages/scripts/%(account_nr_1)s/%(account_nr_2)s.js"</script>"""
|
||||
USERVAR_CODE = "CE2.set(%(varnr)d, '%(value)s');"
|
||||
|
||||
|
|
@ -36,8 +36,7 @@ def crazy_egg(parser, token):
|
|||
class CrazyEggNode(Node):
|
||||
def __init__(self):
|
||||
self.account_nr = get_required_setting('CRAZY_EGG_ACCOUNT_NUMBER',
|
||||
ACCOUNT_NUMBER_RE,
|
||||
"must be a string containing an eight-digit number")
|
||||
ACCOUNT_NUMBER_RE, "must be (a string containing) a number")
|
||||
|
||||
def render(self, context):
|
||||
html = SETUP_CODE % {'account_nr_1': self.account_nr[:4],
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from analytical.utils import get_identity, get_required_setting
|
|||
|
||||
|
||||
ACCOUNT_NUMBER_RE = re.compile(r'^\d+$')
|
||||
SITE_CODE_RE = re.compile(r'^[\w]{3}$')
|
||||
SITE_CODE_RE = re.compile(r'^[\w]+$')
|
||||
SETUP_CODE = """
|
||||
<script type="text/javascript">var _kiq = _kiq || []; %(commands)s</script>
|
||||
<script type="text/javascript" src="//s3.amazonaws.com/ki.js/%(account_number)s/%(site_code)s.js" async="true"></script>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from django.utils import simplejson
|
|||
from analytical.utils import get_identity, get_required_setting
|
||||
|
||||
|
||||
SITE_ID_RE = re.compile(r'^\d{4}-\d{3}-\d{2}-\d{4}$')
|
||||
SITE_ID_RE = re.compile(r'^\d+-\d+-\d+-\d+$')
|
||||
SETUP_CODE = """
|
||||
<script type='text/javascript'>
|
||||
/*{literal}<![CDATA[*/ window.olark||(function(k){var g=window,j=document,a=g.location.protocol=="https:"?"https:":"http:",i=k.name,b="load",h="addEventListener";(function(){g[i]=function(){(c.s=c.s||[]).push(arguments)};var c=g[i]._={},f=k.methods.length;while(f--){(function(l){g[i][l]=function(){g[i]("call",l,arguments)}})(k.methods[f])}c.l=k.loader;c.i=arguments.callee;c.p={0:+new Date};c.P=function(l){c.p[l]=new Date-c.p[0]};function e(){c.P(b);g[i](b)}g[h]?g[h](b,e,false):g.attachEvent("on"+b,e);c.P(1);var d=j.createElement("script"),m=document.getElementsByTagName("script")[0];d.type="text/javascript";d.async=true;d.src=a+"//"+c.l;m.parentNode.insertBefore(d,m);c.P(2)})()})({loader:(function(a){return "static.olark.com/jsclient/loader1.js?ts="+(a?a[1]:(+new Date))})(document.cookie.match(/olarkld=([0-9]+)/)),name:"olark",methods:["configure","extend","declare","identify"]}); olark.identify('%(site_id)s');/*]]>{/literal}*/
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from django.template import Library, Node, TemplateSyntaxError
|
|||
from analytical.utils import is_internal_ip, disable_html, get_required_setting
|
||||
|
||||
|
||||
ACCOUNT_NUMBER_RE = re.compile(r'^\d{7}$')
|
||||
ACCOUNT_NUMBER_RE = re.compile(r'^\d+$')
|
||||
SETUP_CODE = """<script src="//cdn.optimizely.com/js/%(account_number)s.js"></script>"""
|
||||
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class OptimizelyNode(Node):
|
|||
def __init__(self):
|
||||
self.account_number = get_required_setting(
|
||||
'OPTIMIZELY_ACCOUNT_NUMBER', ACCOUNT_NUMBER_RE,
|
||||
"must be a string containing an seven-digit number")
|
||||
"must be a string looking like 'XXXXXXX'")
|
||||
|
||||
def render(self, context):
|
||||
html = SETUP_CODE % {'account_number': self.account_number}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from analytical.utils import is_internal_ip, disable_html, get_identity, \
|
|||
get_required_setting
|
||||
|
||||
|
||||
API_KEY_RE = re.compile(r'^\w{6}$')
|
||||
API_KEY_RE = re.compile(r'^\w+$')
|
||||
SETUP_CODE = """
|
||||
<script src="//d1nu2rn22elx8m.cloudfront.net/performable/pax/%(api_key)s.js" type="text/javascript"></script>
|
||||
"""
|
||||
|
|
@ -52,9 +52,8 @@ def performable(parser, token):
|
|||
|
||||
class PerformableNode(Node):
|
||||
def __init__(self):
|
||||
self.api_key = get_required_setting(
|
||||
'PERFORMABLE_API_KEY', API_KEY_RE,
|
||||
"must be a string containing five alphanumerical characters")
|
||||
self.api_key = get_required_setting('PERFORMABLE_API_KEY', API_KEY_RE,
|
||||
"must be a string looking like 'XXXXX'")
|
||||
|
||||
def render(self, context):
|
||||
html = SETUP_CODE % {'api_key': self.api_key}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from analytical.utils import get_identity, is_internal_ip, disable_html, \
|
|||
get_required_setting
|
||||
|
||||
|
||||
TRACKING_ID_RE = re.compile(r'^[\w\d]{5}-[\w\d]{10}$')
|
||||
TRACKING_ID_RE = re.compile(r'^[\w\d]+-[\w\d]+$')
|
||||
TRACKING_CODE = """
|
||||
<script type="text/javascript">
|
||||
document.write(unescape("%%3Cscript src='" + (("https:" == document.location.protocol) ? "https://ssl-" : "http://") + "include.reinvigorate.net/re_.js' type='text/javascript'%%3E%%3C/script%%3E"));
|
||||
|
|
|
|||
|
|
@ -55,9 +55,7 @@ class ChartbeatTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, ChartbeatBottomNode)
|
||||
|
||||
def test_wrong_user_id(self):
|
||||
self.settings_manager.set(CHARTBEAT_USER_ID='1234')
|
||||
self.assertRaises(AnalyticalException, ChartbeatBottomNode)
|
||||
self.settings_manager.set(CHARTBEAT_USER_ID='123456')
|
||||
self.settings_manager.set(CHARTBEAT_USER_ID='123abc')
|
||||
self.assertRaises(AnalyticalException, ChartbeatBottomNode)
|
||||
|
||||
def test_rendering_setup_no_site(self):
|
||||
|
|
|
|||
|
|
@ -39,9 +39,7 @@ class ClickyTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, ClickyNode)
|
||||
|
||||
def test_wrong_site_id(self):
|
||||
self.settings_manager.set(CLICKY_SITE_ID='1234567')
|
||||
self.assertRaises(AnalyticalException, ClickyNode)
|
||||
self.settings_manager.set(CLICKY_SITE_ID='123456789')
|
||||
self.settings_manager.set(CLICKY_SITE_ID='123abc')
|
||||
self.assertRaises(AnalyticalException, ClickyNode)
|
||||
|
||||
def test_identify(self):
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ class CrazyEggTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, CrazyEggNode)
|
||||
|
||||
def test_wrong_account_number(self):
|
||||
self.settings_manager.set(CRAZY_EGG_ACCOUNT_NUMBER='1234567')
|
||||
self.assertRaises(AnalyticalException, CrazyEggNode)
|
||||
self.settings_manager.set(CRAZY_EGG_ACCOUNT_NUMBER='123456789')
|
||||
self.settings_manager.set(CRAZY_EGG_ACCOUNT_NUMBER='123abc')
|
||||
self.assertRaises(AnalyticalException, CrazyEggNode)
|
||||
|
||||
def test_uservars(self):
|
||||
|
|
|
|||
|
|
@ -41,9 +41,7 @@ class KissInsightsTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, KissInsightsNode)
|
||||
|
||||
def test_wrong_site_id(self):
|
||||
self.settings_manager.set(KISS_INSIGHTS_SITE_CODE='ab')
|
||||
self.assertRaises(AnalyticalException, KissInsightsNode)
|
||||
self.settings_manager.set(KISS_INSIGHTS_SITE_CODE='abcd')
|
||||
self.settings_manager.set(KISS_INSIGHTS_SITE_CODE='abc def')
|
||||
self.assertRaises(AnalyticalException, KissInsightsNode)
|
||||
|
||||
def test_identify(self):
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ class OlarkTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, OlarkNode)
|
||||
|
||||
def test_wrong_site_id(self):
|
||||
self.settings_manager.set(OLARK_SITE_ID='1234-567-89-012')
|
||||
self.assertRaises(AnalyticalException, OlarkNode)
|
||||
self.settings_manager.set(OLARK_SITE_ID='1234-567-89-01234')
|
||||
self.settings_manager.set(OLARK_SITE_ID='1234-567-8901234')
|
||||
self.assertRaises(AnalyticalException, OlarkNode)
|
||||
|
||||
def test_identify(self):
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ class OptimizelyTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, OptimizelyNode)
|
||||
|
||||
def test_wrong_account_number(self):
|
||||
self.settings_manager.set(OPTIMIZELY_ACCOUNT_NUMBER='123456')
|
||||
self.assertRaises(AnalyticalException, OptimizelyNode)
|
||||
self.settings_manager.set(OPTIMIZELY_ACCOUNT_NUMBER='12345678')
|
||||
self.settings_manager.set(OPTIMIZELY_ACCOUNT_NUMBER='123abc')
|
||||
self.assertRaises(AnalyticalException, OptimizelyNode)
|
||||
|
||||
def test_render_internal_ip(self):
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ class PerformableTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, PerformableNode)
|
||||
|
||||
def test_wrong_account_number(self):
|
||||
self.settings_manager.set(PERFORMABLE_API_KEY='123AB')
|
||||
self.assertRaises(AnalyticalException, PerformableNode)
|
||||
self.settings_manager.set(PERFORMABLE_API_KEY='123ABCD')
|
||||
self.settings_manager.set(PERFORMABLE_API_KEY='123 ABC')
|
||||
self.assertRaises(AnalyticalException, PerformableNode)
|
||||
|
||||
def test_render_internal_ip(self):
|
||||
|
|
|
|||
|
|
@ -35,9 +35,7 @@ class ReinvigorateTagTestCase(TagTestCase):
|
|||
self.assertRaises(AnalyticalException, ReinvigorateNode)
|
||||
|
||||
def test_wrong_tracking_id(self):
|
||||
self.settings_manager.set(REINVIGORATE_TRACKING_ID='12345-abcdefghi')
|
||||
self.assertRaises(AnalyticalException, ReinvigorateNode)
|
||||
self.settings_manager.set(REINVIGORATE_TRACKING_ID='12345-abcdefghijk')
|
||||
self.settings_manager.set(REINVIGORATE_TRACKING_ID='123abc')
|
||||
self.assertRaises(AnalyticalException, ReinvigorateNode)
|
||||
|
||||
def test_identify(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue