Beispiel #1
0
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = PiwikNode().render(context)
     assert r.startswith('<!-- Piwik disabled on internal IP address')
     assert r.endswith('-->')
Beispiel #2
0
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = PiwikNode().render(context)
     self.assertTrue(r.startswith(
         '<!-- Piwik disabled on internal IP address'), r)
     self.assertTrue(r.endswith('-->'), r)
Beispiel #3
0
 def test_default_usertrack(self):
     context = Context({
         'user':
         User(username='******', first_name='Guido', last_name='van Rossum')
     })
     r = PiwikNode().render(context)
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     assert var_code in r
 def test_default_usertrack(self):
     context = Context({
         'user':
         User(username='******', first_name='Guido', last_name='van Rossum')
     })
     r = PiwikNode().render(context)
     msg = 'Incorrect Piwik user tracking rendering.\nNot found:\n%s\nIn:\n%s'
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     self.assertIn(var_code, r, msg % (var_code, r))
Beispiel #5
0
 def test_disable_usertrack(self):
     context = Context({
         'user':
         User(username='******', first_name='Guido', last_name='van Rossum'),
         'piwik_identity':
         None
     })
     r = PiwikNode().render(context)
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     assert var_code not in r
Beispiel #6
0
 def test_uservars(self):
     context = Context({
         'piwik_vars': [(1, 'foo', 'foo_val'),
                        (2, 'bar', 'bar_val', 'page'),
                        (3, 'spam', 'spam_val', 'visit')]
     })
     r = PiwikNode().render(context)
     for var_code in [
             '_paq.push(["setCustomVariable", 1, "foo", "foo_val", "page"]);',
             '_paq.push(["setCustomVariable", 2, "bar", "bar_val", "page"]);',
             '_paq.push(["setCustomVariable", 3, "spam", "spam_val", "visit"]);'
     ]:
         assert var_code in r
 def test_uservars(self):
     context = Context({
         'piwik_vars': [(1, 'foo', 'foo_val'),
                        (2, 'bar', 'bar_val', 'page'),
                        (3, 'spam', 'spam_val', 'visit')]
     })
     r = PiwikNode().render(context)
     msg = 'Incorrect Piwik custom variable rendering. Expected:\n%s\nIn:\n%s'
     for var_code in [
             '_paq.push(["setCustomVariable", 1, "foo", "foo_val", "page"]);',
             '_paq.push(["setCustomVariable", 2, "bar", "bar_val", "page"]);',
             '_paq.push(["setCustomVariable", 3, "spam", "spam_val", "visit"]);'
     ]:
         self.assertIn(var_code, r, msg % (var_code, r))
 def test_node(self):
     r = PiwikNode().render(Context({}))
     self.assertTrue('"//example.com/";' in r, r)
     self.assertTrue("_paq.push(['setSiteId', 345]);" in r, r)
     self.assertTrue('img src="//example.com/piwik.php?idsite=345"' in r, r)
Beispiel #9
0
 def test_domain_port_invalid(self):
     with pytest.raises(AnalyticalException):
         PiwikNode()
 def test_analytical_usertrack(self):
     context = Context({'analytical_identity': 'BDFL'})
     r = PiwikNode().render(context)
     msg = 'Incorrect Piwik user tracking rendering.\nNot found:\n%s\nIn:\n%s'
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     self.assertIn(var_code, r, msg % (var_code, r))
 def test_disable_cookies(self):
     r = PiwikNode().render(Context({}))
     self.assertTrue("_paq.push(['disableCookies']);" in r, r)
Beispiel #12
0
 def test_no_domain(self):
     with pytest.raises(AnalyticalException):
         PiwikNode()
Beispiel #13
0
 def test_analytical_usertrack(self):
     context = Context({'analytical_identity': 'BDFL'})
     r = PiwikNode().render(context)
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     assert var_code in r
 def test_ask_for_consent(self):
     r = PiwikNode().render(Context({}))
     self.assertTrue("_paq.push(['requireConsent']);" in r, r)
Beispiel #15
0
 def test_no_siteid(self):
     with pytest.raises(AnalyticalException):
         PiwikNode()
Beispiel #16
0
 def test_siteid_not_a_number(self):
     with pytest.raises(AnalyticalException):
         PiwikNode()
Beispiel #17
0
 def test_domain_uri_incomplete_port(self):
     with pytest.raises(AnalyticalException):
         PiwikNode()
Beispiel #18
0
 def test_domain_multi_port(self):
     with pytest.raises(AnalyticalException):
         PiwikNode()