1
Fork 0

Import some basic tests

This commit is contained in:
Jake Howard 2017-05-22 09:40:47 +01:00
parent ff164e9525
commit d6234e155b
4 changed files with 63 additions and 2 deletions

3
content/_index.md Normal file
View file

@ -0,0 +1,3 @@
---
title: Homepage
---

View file

@ -3,7 +3,7 @@
<nav id="nav">
<ul>
{{ range where .Site.Pages.ByTitle "Kind" "section" }}
<li>
<li class="top-level">
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
{{ if .Pages }}
<ul>
@ -20,7 +20,7 @@
{{ range where .Site.Pages.ByTitle "Kind" "page" }}
{{ if eq .Section "" }}
<li><a href="{{ .Permalink }}">{{ title .LinkTitle }}</a></li>
<li class="top-level"><a href="{{ .Permalink }}">{{ title .LinkTitle }}</a></li>
{{ end }}
{{ end }}
</ul>

View file

@ -17,6 +17,8 @@ class TestClient:
return content
def build_path(self, path):
if path.startswith('https://theorangeone.net'):
path = path.replace('https://theorangeone.net', '')
if path.startswith('/'):
path = path[1:]
if path.endswith('/'):

56
tests/tests_common.py Normal file
View file

@ -0,0 +1,56 @@
from tests import TestCase
from bs4 import BeautifulSoup
class CorePagesTestCase(TestCase):
def test_has_index(self):
content = self.client.get('index.html')
self.assertTitle(content, 'Homepage')
def test_has_sitemap(self):
self.assertTrue(self.client.exists('sitemap.xml'))
def test_has_atom_feed(self):
self.assertTrue(self.client.exists('index.xml'))
def test_has_robots(self):
self.assertTrue(self.client.exists('robots.txt'))
class CommonPagesTestCase(TestCase):
def test_navbar_links(self):
content = self.client.get('index.html')
tabs = content.find('nav').find_all('li', class_="top-level")
self.assertEqual(len(tabs), 6)
for tab in tabs:
if len(tab.find_all('a')) == 1:
self.assertEqual(len(tab.find_all('ul')), 0)
self.assertTrue(self.client.exists(tab.find('a').attrs['href']))
else:
for link in tab.find_all('a'):
self.assertTrue(self.client.exists(link.attrs['href']))
self.assertNotEqual(self.get_children(link), '')
if self.get_children(link) == '<i>See more</i>':
self.assertEqual(link.attrs['href'], tab.find_all('a')[0].attrs['href'])
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_build_path_without_index(self):
self.assertEqual(
self.client.build_path('foo/'),
self.client.build_path('foo/index.html')
)
def test_file_doesnt_exist(self):
self.assertFalse(self.client.exists('foo.bar'))