unittest piwik integration
This commit is contained in:
parent
3941e1a5cd
commit
fba5843050
3 changed files with 20 additions and 9 deletions
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
</script>
|
||||
<noscript><p><img src="//{{ PIWIK.url }}/piwik.php?idsite={{ PIWIK.site_id }}" style="border:0;" alt="" /></p></noscript>
|
||||
<noscript id="piwik"><p><img src="//{{ PIWIK.url }}/piwik.php?idsite={{ PIWIK.site_id }}" style="border:0;" alt="" /></p></noscript>
|
||||
<!-- End Piwik Code -->
|
||||
{% endif %}
|
||||
|
|
Reference in a new issue