1
Fork 0

Remove unittests

This commit is contained in:
Jake Howard 2017-07-09 19:55:26 +01:00
parent 33462f2270
commit 3bbc53dace
Signed by: jake
GPG key ID: 57AFB45680EDD477
5 changed files with 0 additions and 129 deletions

View file

@ -40,8 +40,6 @@ test:
$(NODE_BIN)/yamllint data/*.yml $(NODE_BIN)/yamllint data/*.yml
$(NODE_BIN)/yamllint config.yml $(NODE_BIN)/yamllint config.yml
$(NODE_BIN)/mdspell --en-gb -ranx 'content/**/*.*' $(NODE_BIN)/mdspell --en-gb -ranx 'content/**/*.*'
nose2
.PHONY: build clean install test .PHONY: build clean install test

View file

@ -1,5 +1,2 @@
beautifulsoup4==4.6.0
nose2==0.6.5
pygments pygments
pyyaml==3.12

View file

@ -1,50 +0,0 @@
import unittest
import os.path
from bs4 import BeautifulSoup
import yaml
SETTINGS = yaml.safe_load(open(os.path.realpath('./config.yml')))
class TestClient:
output_path = os.path.realpath('./public')
def get(self, path, JS=True):
file_path = self.build_path(path)
content = "".join(open(file_path).readlines())
if file_path.endswith('html'):
content = BeautifulSoup(content, 'html.parser')
if JS:
for script in content(["noscript"]): # Remove noscript tags
script.extract()
return content
def build_path(self, path):
if path.startswith(SETTINGS['baseURL']):
path = path.replace(SETTINGS['baseURL'], '')
if path.startswith('/'):
path = path[1:]
if path.endswith('/'):
path += 'index.html'
return os.path.join(self.output_path, path)
def exists(self, path):
return os.path.exists(self.build_path(path))
class TestCase(unittest.TestCase):
client = TestClient()
settings = SETTINGS
def get_children(self, content):
return str(list(content.children)[0]).strip()
def assertTitle(self, content, title):
self.assertIn(title, content.title.string)
def assertHeaderTitle(self, content, title):
header_title = content.find('header').find('h2')
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

@ -1,57 +0,0 @@
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:
self.assertLessEqual(len(tab.find_all('a')), self.settings['params']['nav_items'] + 2)
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'))

View file

@ -1,17 +0,0 @@
from tests import TestCase
class IndexPageTestCase(TestCase):
def test_index_sections(self):
for section in ['projects', 'recent-posts']:
content = self.client.get('index.html')
rows = content.find('div', id=section).find_all('div', class_='row')
self.assertLessEqual(len(rows), self.settings['params']['index_items'])
self.assertGreater(self.settings['params']['index_items'], 0)
for row in rows:
self.assertIsNotNone(row.find('section', class_='box'))
self.assertTrue(self.client.exists(row.find('a').attrs['href']))
self.assertNotEqual(self.get_children(row.find('p')), '')
self.assertLessEqual(len(self.get_children(row.find('p'))), self.settings['params']['summary_length'] + 3)
self.assertNotEqual(self.get_children(row.find('h3')), '')