refactor tests
This commit is contained in:
parent
cb7b83cb5c
commit
1d02b3d450
5 changed files with 44 additions and 37 deletions
|
@ -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)
|
|
|
@ -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)
|
|
@ -1,4 +1,4 @@
|
||||||
from tests.TestWrapper import TestCase
|
from tests import TestCase
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from tests.TestWrapper import TestCase
|
from tests import TestCase
|
||||||
from config import settings
|
from config import settings
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from tests.TestWrapper import TestCase
|
from tests import TestCase
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,13 @@ class HomepageTestCase(TestCase):
|
||||||
content = self.client.get('index.html')
|
content = self.client.get('index.html')
|
||||||
blogs = content.find('section', id='blog').find_all('div', class_="col-xs-12")
|
blogs = content.find('section', id='blog').find_all('div', class_="col-xs-12")
|
||||||
self.assertTrue(len(blogs) <= 4)
|
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')
|
url = os.path.join(post.find('a').attrs['href'], 'index.html')
|
||||||
self.assertTrue(self.client.exists(url))
|
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))
|
Reference in a new issue