1
Fork 0

add tests for core pages

This commit is contained in:
Jake Howard 2016-10-02 11:36:21 +01:00
parent ae553e808e
commit c036c17a54
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 48 additions and 1 deletions

View file

@ -49,7 +49,7 @@ AUTHOR_SAVE_AS = False
# Override page URLs
PAGE_SAVE_AS = "{slug}/index.html"
PAGE_URL = "{slug}"
PAGE_URL = "{slug}/"
ARTICLE_SAVE_AS = "{category}/{slug}/index.html"
ARTICLE_URL = "{category}/{slug}/"
CATEGORY_SAVE_AS = "{slug}/index.html"

View file

@ -29,5 +29,12 @@ class TestClient:
class TestCase(unittest.TestCase):
client = TestClient()
def get_children(self, content):
return str(list(content.children)[0])
def assertTitle(self, content, title):
self.assertIn(title, content.title.string)
def assertHeaderTitle(self, content, title):
header_title = content.find('h1', class_="section-heading")
self.assertIn(title, self.get_children(header_title))

View file

@ -1,4 +1,5 @@
from tests import TestCase
from config import settings
import os.path
@ -17,3 +18,42 @@ class HomepageTestCase(TestCase):
for project in projects:
url = os.path.join(project.attrs['href'], 'index.html')
self.assertTrue(self.client.exists(url))
class AboutPageTestCase(TestCase):
def test_title(self):
content = self.client.get('about/index.html')
self.assertHeaderTitle(content, 'About Me')
self.assertTitle(content, 'About')
def test_website_section(self):
content = self.client.get('about/index.html')
section = content.find('section', id='website')
subtitle = section.find('h2')
self.assertEqual('About my website', self.get_children(subtitle))
def test_server_section(self):
content = self.client.get('about/index.html')
section = content.find('section', id='server')
subtitle = section.find('h2')
self.assertEqual('The Server', self.get_children(subtitle))
def test_github_card(self):
content = self.client.get('about/index.html')
tags = content.find_all('div', class_='github-card')
self.assertEqual(len(tags), 1)
tag = tags[0]
self.assertEqual('medium', tag.attrs['data-theme'])
self.assertEqual(settings.accounts.github[1], tag.attrs['data-github'])
class Page404TestCase(TestCase):
def test_title(self):
content = self.client.get('.404.html')
self.assertHeaderTitle(content, 'Uh Oh - There\'s nothing here!')
self.assertTitle(content, '404 - Page not found')
def test_image(self):
content = self.client.get('.404.html')
img = content.find('img')
self.assertEqual('Cat', img.attrs['alt'])