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)
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))
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
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))
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
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))
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
def test_domain_uri_incomplete_port(self): with pytest.raises(AnalyticalException): MatomoNode()
def test_domain_multi_port(self): with pytest.raises(AnalyticalException): MatomoNode()
def test_siteid_not_a_number(self): with pytest.raises(AnalyticalException): MatomoNode()
def test_no_siteid(self): with pytest.raises(AnalyticalException): MatomoNode()
def test_no_domain(self): with pytest.raises(AnalyticalException): MatomoNode()
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
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
def test_domain_port_invalid(self): with pytest.raises(AnalyticalException): MatomoNode()
def test_disable_cookies(self): r = MatomoNode().render(Context({})) assert "_paq.push(['disableCookies']);" in r
def test_ask_for_consent(self): r = MatomoNode().render(Context({})) self.assertTrue("_paq.push(['requireConsent']);" in r, r)