diff --git a/tests/TestWrapper.py b/tests/TestWrapper.py deleted file mode 100644 index 59854d9..0000000 --- a/tests/TestWrapper.py +++ /dev/null @@ -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) diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..49c4b3c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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) diff --git a/tests/test_client.py b/tests/test_client.py index 718be4d..6e62675 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,4 +1,4 @@ -from tests.TestWrapper import TestCase +from tests import TestCase from bs4 import BeautifulSoup diff --git a/tests/tests_core.py b/tests/tests_common.py similarity index 97% rename from tests/tests_core.py rename to tests/tests_common.py index c607ea5..0229c61 100644 --- a/tests/tests_core.py +++ b/tests/tests_common.py @@ -1,4 +1,4 @@ -from tests.TestWrapper import TestCase +from tests import TestCase from config import settings diff --git a/tests/tests_homepage.py b/tests/tests_pages.py similarity index 50% rename from tests/tests_homepage.py rename to tests/tests_pages.py index 174de86..3c28e0b 100644 --- a/tests/tests_homepage.py +++ b/tests/tests_pages.py @@ -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))