82 lines
3.1 KiB
Python
82 lines
3.1 KiB
Python
from tests import TestCase
|
|
from bs4 import BeautifulSoup
|
|
import pelicanconf as settings
|
|
from config import social as social_settings
|
|
from unittest import skipIf
|
|
from os import environ
|
|
|
|
|
|
class CorePagesTestCase(TestCase):
|
|
def test_has_index(self):
|
|
content = self.client.get('index.html')
|
|
self.assertTitle(content, 'Homepage')
|
|
|
|
def test_has_robots(self):
|
|
content = self.client.get('robots.txt')
|
|
self.assertIn('Allow: /', content)
|
|
|
|
def test_has_sitemap(self):
|
|
content = self.client.get('sitemap.xml')
|
|
self.assertIn(settings.SITEURL, content)
|
|
|
|
def test_has_atom_feed(self):
|
|
content = self.client.get('feed.atom')
|
|
self.assertIn(settings.SITEURL, content)
|
|
|
|
def test_has_404_page(self):
|
|
content = self.client.get('.404.html')
|
|
self.assertTitle(content, '404')
|
|
|
|
def test_has_scripts(self):
|
|
content = self.client.get('index.html')
|
|
for script in content.find_all('script'):
|
|
if script.attrs.get('id') == 'piwik':
|
|
continue
|
|
self.client.exists(script.attrs['src'])
|
|
|
|
def test_has_stylesheet(self):
|
|
content = self.client.get('index.html')
|
|
for script in content.find_all('link', rel='stylesheet'):
|
|
self.assertTrue(self.client.exists(script.attrs['href']))
|
|
|
|
def test_has_link_icons(self):
|
|
content = self.client.get('index.html')
|
|
for script in content.find_all('link', rel='icon'):
|
|
self.assertTrue(self.client.exists(script.attrs['href']))
|
|
for script in content.find_all('link', rel='apple-touch-icon-precomposed'):
|
|
self.assertTrue(self.client.exists(script.attrs['href']))
|
|
|
|
def test_footer_links(self):
|
|
content = self.client.get('index.html')
|
|
footer = content.footer
|
|
for link in footer.find('p', class_="social").find_all('a'):
|
|
self.assertIn(link.attrs['alt'], social_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 TestClientTestCase(TestCase):
|
|
def test_client_fails(self):
|
|
with self.assertRaises(FileNotFoundError):
|
|
self.client.get('foo.bar')
|
|
|
|
def test_client_gets_data(self):
|
|
content = self.client.get('index.html')
|
|
self.assertIsInstance(content, BeautifulSoup)
|
|
|
|
def test_file_exists(self):
|
|
self.assertTrue(self.client.exists('index.html'))
|
|
|
|
def test_file_doesnt_exist(self):
|
|
self.assertFalse(self.client.exists('foo.bar'))
|