1
Fork 0

refactor tests

This commit is contained in:
Jake Howard 2016-09-30 23:13:41 +01:00
parent cb7b83cb5c
commit 1d02b3d450
Signed by: jake
GPG key ID: 57AFB45680EDD477
5 changed files with 44 additions and 37 deletions

View file

@ -1,33 +0,0 @@
import unittest
import os.path
from bs4 import BeautifulSoup
class TestClient:
output_path = os.path.realpath('./output')
def get(self, path):
file_path = self.build_path(path)
content = "".join(open(file_path).readlines())
if path.endswith('html'):
content = BeautifulSoup(content, 'html.parser')
return content
def build_path(self, path):
if path.startswith('/'):
path = path[1:]
return os.path.join(self.output_path, path)
def exists(self, path):
try:
open(self.build_path(path)).close()
return True
except FileNotFoundError:
return False
class TestCase(unittest.TestCase):
client = TestClient()
def assertTitle(self, content, title):
self.assertIn(title, content.title.string)

View file

@ -0,0 +1,33 @@
import unittest
import os.path
from bs4 import BeautifulSoup
class TestClient:
output_path = os.path.realpath('./output')
def get(self, path):
file_path = self.build_path(path)
content = "".join(open(file_path).readlines())
if path.endswith('html'):
content = BeautifulSoup(content, 'html.parser')
return content
def build_path(self, path):
if path.startswith('/'):
path = path[1:]
return os.path.join(self.output_path, path)
def exists(self, path):
try:
with open(self.build_path(path)):
return True
except FileNotFoundError:
return False
class TestCase(unittest.TestCase):
client = TestClient()
def assertTitle(self, content, title):
self.assertIn(title, content.title.string)

View file

@ -1,4 +1,4 @@
from tests.TestWrapper import TestCase
from tests import TestCase
from bs4 import BeautifulSoup

View file

@ -1,4 +1,4 @@
from tests.TestWrapper import TestCase
from tests import TestCase
from config import settings

View file

@ -1,4 +1,4 @@
from tests.TestWrapper import TestCase
from tests import TestCase
import os.path
@ -7,6 +7,13 @@ class HomepageTestCase(TestCase):
content = self.client.get('index.html')
blogs = content.find('section', id='blog').find_all('div', class_="col-xs-12")
self.assertTrue(len(blogs) <= 4)
for post in content.find('section', id='blog').find_all('div', class_="col-xs-12"):
for post in blogs:
url = os.path.join(post.find('a').attrs['href'], 'index.html')
self.assertTrue(self.client.exists(url))
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))