1
Fork 0

Add more tests

This commit is contained in:
Jake Howard 2017-01-14 23:53:18 +00:00
parent 434646d806
commit cbbacc2682
Signed by: jake
GPG key ID: 57AFB45680EDD477
5 changed files with 46 additions and 5 deletions

View file

@ -36,7 +36,7 @@ from plugins import image_resizer
META_IMAGES = image_resizer.generate()
PIWIK = {
'url': 'piwik.theorangeone.net',
'site_id': '1'
'site_id': 1
}
# Disable some pages

View file

@ -7,7 +7,7 @@ FLAKE8_IGNORE=--ignore=E128,E501,E401,E402
set -e
nose2 --verbose
nose2
eslint 'theme/static/src/js/'

View file

@ -29,7 +29,7 @@ class TestCase(unittest.TestCase):
client = TestClient()
def get_children(self, content):
return str(list(content.children)[0])
return str(list(content.children)[0]).strip()
def assertTitle(self, content, title):
self.assertIn(title, content.title.string)
@ -37,3 +37,6 @@ class TestCase(unittest.TestCase):
def assertHeaderTitle(self, content, title):
header_title = content.find('h1', class_="section-heading")
self.assertIn(title, self.get_children(header_title))
def assertSamePath(self, p1, p2):
self.assertEqual(self.client.build_path(p1), self.client.build_path(p2))

View file

@ -27,12 +27,13 @@ class CorePagesTestCase(TestCase):
content = self.client.get('.404.html')
self.assertTitle(content, '404')
class CommonPagesTestCase(TestCase):
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'])
self.assertTrue(self.client.exists(script.attrs['src']))
def test_has_stylesheet(self):
content = self.client.get('index.html')
@ -53,6 +54,22 @@ class CorePagesTestCase(TestCase):
self.assertIn(link.attrs['alt'], social_settings['footer_accounts'])
self.assertIn("fa fa-", str(list(link.children)[0]))
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)
@skipIf(not environ.get('BUILD_PRODUCTION', False), 'Not building production')
def test_has_analytics(self):
content = self.client.get('index.html', False)

View file

@ -4,9 +4,21 @@ import os.path
class HomepageTestCase(TestCase):
def test_about_section(self):
content = self.client.get('index.html')
about = content.find('section', id='about')
self.assertIsNotNone(about)
about_content = about.find('p')
self.assertNotEqual(self.get_children(about_content), '')
about_link = about.find('a')
self.assertTrue(self.client.exists(about_link.attrs['href']))
def test_blog_links(self):
content = self.client.get('index.html')
blogs = content.find('section', id='blog').find_all('div', class_="col-xs-12")
blog = content.find('section', id='blog')
blog_link = blog.find('a', class_='btn')
self.assertTrue(self.client.exists(blog_link.attrs['href']))
blogs = blog.find_all('div', class_="col-xs-12")
self.assertTrue(len(blogs) <= 4)
for post in blogs:
url = os.path.join(post.find('a').attrs['href'], 'index.html')
@ -19,6 +31,15 @@ class HomepageTestCase(TestCase):
url = os.path.join(project.attrs['href'], 'index.html')
self.assertTrue(self.client.exists(url))
def test_navbar(self):
content = self.client.get('index.html')
links = content.find('ul', class_='navbar-nav').find_all('a')
self.assertEqual(len(links), 5)
for link in links:
self.assertIn('page-scroll', link.attrs['class'])
element = self.get_children(link)
self.assertEqual(link.attrs['href'], '#' + element.lower())
class AboutPageTestCase(TestCase):
def test_title(self):