2016-09-30 23:13:41 +01:00
|
|
|
from tests import TestCase
|
2016-10-02 11:37:19 +01:00
|
|
|
from bs4 import BeautifulSoup
|
2017-01-13 21:41:40 +00:00
|
|
|
import pelicanconf as settings
|
|
|
|
from config import social as social_settings
|
2016-10-08 22:44:45 +01:00
|
|
|
from unittest import skipIf
|
|
|
|
from os import environ
|
2016-09-11 21:26:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
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')
|
2017-01-13 21:41:40 +00:00
|
|
|
self.assertIn(settings.SITEURL, content)
|
2016-09-11 21:26:30 +01:00
|
|
|
|
|
|
|
def test_has_atom_feed(self):
|
|
|
|
content = self.client.get('feed.atom')
|
2017-01-13 21:41:40 +00:00
|
|
|
self.assertIn(settings.SITEURL, content)
|
2016-09-11 21:26:30 +01:00
|
|
|
|
|
|
|
def test_has_404_page(self):
|
|
|
|
content = self.client.get('.404.html')
|
|
|
|
self.assertTitle(content, '404')
|
|
|
|
|
2017-01-14 23:53:18 +00:00
|
|
|
class CommonPagesTestCase(TestCase):
|
2016-09-11 21:26:30 +01:00
|
|
|
def test_has_scripts(self):
|
|
|
|
content = self.client.get('index.html')
|
|
|
|
for script in content.find_all('script'):
|
2016-10-08 20:37:55 +01:00
|
|
|
if script.attrs.get('id') == 'piwik':
|
|
|
|
continue
|
2017-01-14 23:53:18 +00:00
|
|
|
self.assertTrue(self.client.exists(script.attrs['src']))
|
2016-09-11 21:26:30 +01:00
|
|
|
|
|
|
|
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'):
|
2017-01-13 21:41:40 +00:00
|
|
|
self.assertIn(link.attrs['alt'], social_settings['footer_accounts'])
|
2016-09-11 21:26:30 +01:00
|
|
|
self.assertIn("fa fa-", str(list(link.children)[0]))
|
2016-10-02 10:43:09 +01:00
|
|
|
|
2017-01-14 23:53:18 +00:00
|
|
|
def test_navbar_links(self):
|
|
|
|
content = self.client.get('.404.html') # a page that isnt home
|
|
|
|
links = content.find('ul', class_='navbar-nav').find_all('a')
|
|
|
|
self.assertEqual(len(links), 4)
|
|
|
|
for link in links:
|
|
|
|
element = self.get_children(link)
|
|
|
|
self.assertEqual(link.attrs['href'], '/{}/'.format(element.lower()))
|
|
|
|
self.assertTrue(self.client.exists(link.attrs['href']))
|
|
|
|
|
|
|
|
def test_navbar_index_link(self):
|
|
|
|
content = self.client.get('.404.html') # a page that isnt home
|
|
|
|
link = content.find('a', class_='navbar-brand')
|
|
|
|
self.assertTrue(self.client.exists(link.attrs['href']))
|
|
|
|
self.assertSamePath(link.attrs['href'], '/')
|
|
|
|
self.assertEqual(self.get_children(link), settings.SITENAME)
|
|
|
|
|
2016-10-08 22:44:45 +01:00
|
|
|
@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)
|
2017-01-13 21:41:40 +00:00
|
|
|
self.assertIn(str(settings.PIWIK['site_id']), piwik_script)
|
2016-10-08 22:44:45 +01:00
|
|
|
piwik_img = content.find('noscript', id='piwik').find('img')
|
2017-01-13 21:41:40 +00:00
|
|
|
self.assertIn(settings.PIWIK['url'], piwik_img.attrs['src'])
|
|
|
|
self.assertIn(str(settings.PIWIK['site_id']), piwik_img.attrs['src'])
|
2016-10-02 11:37:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
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'))
|