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:
|
class TestClient:
|
||||||
output_path = os.path.realpath('./output')
|
output_path = os.path.realpath('./output')
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path, JS=True):
|
||||||
file_path = self.build_path(path)
|
file_path = self.build_path(path)
|
||||||
content = "".join(open(file_path).readlines())
|
content = "".join(open(file_path).readlines())
|
||||||
if path.endswith('html'):
|
if path.endswith('html'):
|
||||||
content = BeautifulSoup(content, 'html.parser')
|
content = BeautifulSoup(content, 'html.parser')
|
||||||
for script in content(["noscript"]): # Remove extra tags
|
if JS:
|
||||||
script.extract()
|
for script in content(["noscript"]): # Remove noscript tags
|
||||||
|
script.extract()
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def build_path(self, path):
|
def build_path(self, path):
|
||||||
|
@ -21,11 +22,7 @@ class TestClient:
|
||||||
return os.path.join(self.output_path, path)
|
return os.path.join(self.output_path, path)
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
try:
|
return os.path.exists(self.build_path(path))
|
||||||
with open(self.build_path(path)):
|
|
||||||
return True
|
|
||||||
except FileNotFoundError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class TestCase(unittest.TestCase):
|
class TestCase(unittest.TestCase):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from tests import TestCase
|
from tests import TestCase
|
||||||
from config import settings, DotDictionary
|
from config import settings, DotDictionary
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from unittest import skipIf
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
|
||||||
class CorePagesTestCase(TestCase):
|
class CorePagesTestCase(TestCase):
|
||||||
|
@ -50,6 +52,18 @@ class CorePagesTestCase(TestCase):
|
||||||
self.assertIn(link.attrs['alt'], settings.footer_accounts)
|
self.assertIn(link.attrs['alt'], settings.footer_accounts)
|
||||||
self.assertIn("fa fa-", str(list(link.children)[0]))
|
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):
|
class DotDictionaryTestCase(TestCase):
|
||||||
def setUp(self):
|
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);
|
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
||||||
})();
|
})();
|
||||||
</script>
|
</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 -->
|
<!-- End Piwik Code -->
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Reference in a new issue