1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/tests/tests_pages.py

97 lines
3.9 KiB
Python
Raw Normal View History

2016-09-30 23:13:41 +01:00
from tests import TestCase
2017-01-13 21:41:40 +00:00
from config import social as social_settings
2017-02-11 16:16:11 +00:00
import pelicanconf as settings
2016-09-11 21:26:30 +01:00
import os.path
class HomepageTestCase(TestCase):
2017-01-14 23:53:18 +00:00
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']))
2016-09-11 21:26:30 +01:00
def test_blog_links(self):
content = self.client.get('index.html')
2017-01-14 23:53:18 +00:00
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")
2016-09-11 21:26:30 +01:00
self.assertTrue(len(blogs) <= 4)
2016-09-30 23:13:41 +01:00
for post in blogs:
2016-09-11 21:26:30 +01:00
url = os.path.join(post.find('a').attrs['href'], 'index.html')
self.assertTrue(self.client.exists(url))
2016-09-30 23:13:41 +01:00
def test_projects(self):
content = self.client.get('index.html')
projects = content.find('section', id='projects').find_all('a', class_='portfolio-box')
for project in projects:
url = os.path.join(project.attrs['href'], 'index.html')
self.assertTrue(self.client.exists(url))
2016-10-02 11:36:21 +01:00
2017-01-14 23:53:18 +00:00
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())
2016-10-02 11:36:21 +01:00
class AboutPageTestCase(TestCase):
def test_title(self):
content = self.client.get('about/index.html')
2017-01-31 21:07:17 +00:00
self.assertHeaderTitle(content, 'About')
2016-10-02 11:36:21 +01:00
self.assertTitle(content, 'About')
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'])
2017-01-13 21:41:40 +00:00
self.assertEqual(social_settings['accounts']['github'][1], tag.attrs['data-github'])
2016-10-02 11:36:21 +01:00
2017-02-11 16:16:11 +00:00
def test_accounts(self):
content = self.client.get('about/index.html')
accounts = content.find_all('div', class_='account')
defined_accounts = [s for k, s in settings.ACCOUNTS.items()]
self.assertEqual(len(accounts), len(defined_accounts))
site_names = [s['site'] for s in defined_accounts]
urls = [s['url'] for s in defined_accounts]
icons = [s['icon'] for s in defined_accounts]
for account in accounts:
self.assertIn(account.find('a').attrs['href'], urls)
self.assertIn(account.find('i').attrs['class'][-1], icons)
self.assertIn(self.get_children(account.find('h3')), site_names)
2016-10-02 11:36:21 +01:00
2017-02-11 20:27:32 +00:00
class ContactPageTestCase(TestCase):
def test_title(self):
content = self.client.get('contact/')
self.assertHeaderTitle(content, 'Contact Me')
self.assertTitle(content, 'Contact Me')
def test_contact_links(self):
content = self.client.get('contact/')
links = content.find_all('section')[2].find_all('a')
self.assertEqual(links[1].attrs['href'], settings.ACCOUNTS['twitter']['url'])
decoded_value = ''.join([chr(int(c)) for c in links[0].attrs['data-value'].split(' ')])
self.assertEqual(decoded_value, settings.CONTACT_EMAIL)
2016-10-02 11:36:21 +01:00
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'])