diff --git a/tests/__init__.py b/tests/__init__.py
index 7632174..6183f0b 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -6,13 +6,14 @@ from bs4 import BeautifulSoup
class TestClient:
output_path = os.path.realpath('./output')
- def get(self, path):
+ def get(self, path, JS=True):
file_path = self.build_path(path)
content = "".join(open(file_path).readlines())
if path.endswith('html'):
content = BeautifulSoup(content, 'html.parser')
- for script in content(["noscript"]): # Remove extra tags
- script.extract()
+ if JS:
+ for script in content(["noscript"]): # Remove noscript tags
+ script.extract()
return content
def build_path(self, path):
@@ -21,11 +22,7 @@ class TestClient:
return os.path.join(self.output_path, path)
def exists(self, path):
- try:
- with open(self.build_path(path)):
- return True
- except FileNotFoundError:
- return False
+ return os.path.exists(self.build_path(path))
class TestCase(unittest.TestCase):
diff --git a/tests/tests_common.py b/tests/tests_common.py
index 201980f..ebc8e68 100644
--- a/tests/tests_common.py
+++ b/tests/tests_common.py
@@ -1,6 +1,8 @@
from tests import TestCase
from config import settings, DotDictionary
from bs4 import BeautifulSoup
+from unittest import skipIf
+from os import environ
class CorePagesTestCase(TestCase):
@@ -50,6 +52,18 @@ class CorePagesTestCase(TestCase):
self.assertIn(link.attrs['alt'], settings.footer_accounts)
self.assertIn("fa fa-", str(list(link.children)[0]))
+ @skipIf(not environ.get('BUILD_PRODUCTION', False), 'Not building production')
+ def test_has_analytics(self):
+ content = self.client.get('index.html', False)
+ piwik_script_tag = content.find('script', id='piwik')
+ self.assertNotEqual(piwik_script_tag, None)
+ piwik_script = self.get_children(piwik_script_tag)
+ self.assertIn('piwik.js', piwik_script)
+ self.assertIn(str(settings.piwik.site_id), piwik_script)
+ piwik_img = content.find('noscript', id='piwik').find('img')
+ self.assertIn(settings.piwik.url, piwik_img.attrs['src'])
+ self.assertIn(str(settings.piwik.site_id), piwik_img.attrs['src'])
+
class DotDictionaryTestCase(TestCase):
def setUp(self):
diff --git a/theme/templates/extras/piwik.html b/theme/templates/extras/piwik.html
index 4dd3698..0810082 100644
--- a/theme/templates/extras/piwik.html
+++ b/theme/templates/extras/piwik.html
@@ -13,6 +13,6 @@
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
-
+
{% endif %}