Start adding tests
This commit is contained in:
parent
160f4ac5cb
commit
babd479d37
3 changed files with 146 additions and 3 deletions
102
.gitignore
vendored
102
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
|
||||
# Created by https://www.gitignore.io/api/node,hugo,jetbrains
|
||||
# Created by https://www.gitignore.io/api/hugo,node,python,jetbrains
|
||||
|
||||
### Hugo ###
|
||||
hugo.exe
|
||||
|
@ -127,6 +127,102 @@ typings/
|
|||
.env
|
||||
|
||||
|
||||
# End of https://www.gitignore.io/api/node,hugo,jetbrains
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
static/build
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
local_settings.py
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# dotenv
|
||||
|
||||
# virtualenv
|
||||
.venv
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# End of https://www.gitignore.io/api/hugo,node,python,jetbrains
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
beautifulsoup4==4.6.0
|
||||
nose2==0.6.5
|
||||
pygments
|
||||
|
||||
|
|
44
tests/__init__.py
Normal file
44
tests/__init__.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import unittest
|
||||
import os.path
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
class TestClient:
|
||||
output_path = os.path.realpath('./output')
|
||||
|
||||
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('/'):
|
||||
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()
|
||||
|
||||
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('div', class_="header-content").find('h1')
|
||||
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))
|
Loading…
Reference in a new issue