Beispiel #1
0
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = MatomoNode().render(context)
     assert r.startswith('<!-- Matomo disabled on internal IP address')
     assert r.endswith('-->')
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = MatomoNode().render(context)
     self.assertTrue(r.startswith(
         '<!-- Matomo 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 = MatomoNode().render(context)
     msg = 'Incorrect Matomo 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 #4
0
 def test_default_usertrack(self):
     context = Context({
         'user':
         User(username='******', first_name='Guido', last_name='van Rossum')
     })
     r = MatomoNode().render(context)
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     assert var_code in r
Beispiel #5
0
 def test_analytical_usertrack(self):
     context = Context({
         'analytical_identity': 'BDFL'
     })
     r = MatomoNode().render(context)
     msg = 'Incorrect Matomo 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 #6
0
 def test_disable_usertrack(self):
     context = Context({
         'user':
         User(username='******', first_name='Guido', last_name='van Rossum'),
         'matomo_identity':
         None
     })
     r = MatomoNode().render(context)
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     assert var_code not in r
Beispiel #7
0
 def test_uservars(self):
     context = Context({'matomo_vars': [(1, 'foo', 'foo_val'),
                                        (2, 'bar', 'bar_val', 'page'),
                                        (3, 'spam', 'spam_val', 'visit')]})
     r = MatomoNode().render(context)
     msg = 'Incorrect Matomo 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))
Beispiel #8
0
 def test_uservars(self):
     context = Context({
         'matomo_vars': [(1, 'foo', 'foo_val'),
                         (2, 'bar', 'bar_val', 'page'),
                         (3, 'spam', 'spam_val', 'visit')]
     })
     r = MatomoNode().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
Beispiel #9
0
 def test_domain_uri_incomplete_port(self):
     with pytest.raises(AnalyticalException):
         MatomoNode()
Beispiel #10
0
 def test_domain_multi_port(self):
     with pytest.raises(AnalyticalException):
         MatomoNode()
Beispiel #11
0
 def test_siteid_not_a_number(self):
     with pytest.raises(AnalyticalException):
         MatomoNode()
Beispiel #12
0
 def test_no_siteid(self):
     with pytest.raises(AnalyticalException):
         MatomoNode()
Beispiel #13
0
 def test_no_domain(self):
     with pytest.raises(AnalyticalException):
         MatomoNode()
Beispiel #14
0
 def test_node(self):
     r = MatomoNode().render(Context({}))
     assert '"//example.com/";' in r
     assert "_paq.push(['setSiteId', 345]);" in r
     assert 'img src="//example.com/piwik.php?idsite=345"' in r
Beispiel #15
0
 def test_analytical_usertrack(self):
     context = Context({'analytical_identity': 'BDFL'})
     r = MatomoNode().render(context)
     var_code = '_paq.push(["setUserId", "BDFL"]);'
     assert var_code in r
Beispiel #16
0
 def test_domain_port_invalid(self):
     with pytest.raises(AnalyticalException):
         MatomoNode()
Beispiel #17
0
 def test_disable_cookies(self):
     r = MatomoNode().render(Context({}))
     assert "_paq.push(['disableCookies']);" in r
Beispiel #18
0
 def test_ask_for_consent(self):
     r = MatomoNode().render(Context({}))
     self.assertTrue("_paq.push(['requireConsent']);" in r, r)