From c036c17a547c4b6ce9ccae5aee32ebf811367cc4 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 2 Oct 2016 11:36:21 +0100 Subject: [PATCH] add tests for core pages --- config/pelicanconf.py | 2 +- tests/__init__.py | 7 +++++++ tests/tests_pages.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/config/pelicanconf.py b/config/pelicanconf.py index 071c7ce..f0beea9 100644 --- a/config/pelicanconf.py +++ b/config/pelicanconf.py @@ -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" diff --git a/tests/__init__.py b/tests/__init__.py index 49c4b3c..96548d5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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)) diff --git a/tests/tests_pages.py b/tests/tests_pages.py index 3c28e0b..12d4333 100644 --- a/tests/tests_pages.py +++ b/tests/tests_pages.py @@ -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'])