Skip to content

Commit 7979f91

Browse files
committed
feat(tests/test_module1): all tests
1 parent 73ff03a commit 7979f91

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

tests/test_module1.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,54 @@
11
import pytest
2-
import sys
3-
import pprint
2+
import sys, os, inspect, re
3+
4+
from bs4 import BeautifulSoup
45

56
from jobs import app
67

8+
def list_routes(app):
9+
rules = []
10+
for rule in app.url_map.iter_rules():
11+
methods = ','.join(sorted(rule.methods))
12+
if rule.endpoint is not 'static':
13+
rules.append(rule.endpoint+':'+ methods +':'+ str(rule))
14+
return rules
15+
716
@pytest.mark.app_import_flask
817
def test_app_import_flask():
9-
pass
18+
assert 'Flask' in dir(app), 'Have you imported the `Flask` class from `flask`'
19+
assert inspect.isclass(app.Flask), '`Flask` is not a class.'
20+
assert 'render_template' in dir(app), '`render_template` has not been imported.'
21+
assert callable(app.render_template), '`render_template` is not a function.'
1022

1123
@pytest.mark.app_create_flask_app
1224
def test_app_create_flask_app():
13-
pass
25+
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
26+
assert isinstance(app.app, app.Flask), '`app` is not an instance of the `Flask` class.'
1427

1528
@pytest.mark.templates_folder
1629
def test_templates_folder():
17-
pass
30+
assert os.path.isdir('jobs/templates'), 'The `templates` folder has not been created.'
1831

1932
@pytest.mark.index_template
2033
def test_index_template():
21-
pass
34+
assert os.path.isfile('jobs/templates/index.html'), 'The `index.html` template does not exist in the `templates` folder.'
35+
index = BeautifulSoup(open(os.getcwd() + '/jobs/templates/index.html'), 'html.parser')
36+
assert index.find('h1'), 'The `index.html` template does not contain an `<h1>`.'
37+
assert index.find('h1').text == 'Jobs', "The `<h1>` in the `index.html` template does not contain the contents 'Jobs'."
2238

2339
@pytest.mark.app_index_route_function
2440
def test_app_index_route_function():
25-
pass
41+
assert os.path.isfile('jobs/templates/index.html'), 'The `index.html` template does not exist in the `templates` folder.'
42+
assert 'jobs' in dir(app)
43+
with app.app.app_context():
44+
assert re.findall(r"return\s*render_template\s*\(\s*(?:'|\")index\.html(?:'|\")\s*\)", inspect.getsource(app.jobs))
2645

2746
@pytest.mark.app_route_decoractors
2847
def test_app_route_decoractors():
29-
pass
48+
assert os.path.isfile('jobs/templates/index.html'), 'The `index.html` template does not exist in the `templates` folder.'
49+
assert 'jobs' in dir(app)
50+
51+
rules = list_routes(app.app)
3052

53+
assert 'jobs:GET,HEAD,OPTIONS:/jobs' in rules
54+
assert 'jobs:GET,HEAD,OPTIONS:/' in rules

0 commit comments

Comments
 (0)