Skip to content

Commit 6e28fda

Browse files
committed
test(modules): add module suffix
1 parent 7979f91 commit 6e28fda

File tree

8 files changed

+127
-76
lines changed

8 files changed

+127
-76
lines changed

tests/test_module1.py

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

5+
from pprint import pprint
6+
from .utils import *
67
from jobs import app
78

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
159

1610
@pytest.mark.app_import_flask
17-
def test_app_import_flask():
11+
def test_app_import_flask_module1():
1812
assert 'Flask' in dir(app), 'Have you imported the `Flask` class from `flask`'
1913
assert inspect.isclass(app.Flask), '`Flask` is not a class.'
2014
assert 'render_template' in dir(app), '`render_template` has not been imported.'
21-
assert callable(app.render_template), '`render_template` is not a function.'
15+
assert inspect.isfunction(app.render_template), '`render_template` is not a function.'
2216

2317
@pytest.mark.app_create_flask_app
24-
def test_app_create_flask_app():
18+
def test_app_create_flask_app_module1():
2519
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
2620
assert isinstance(app.app, app.Flask), '`app` is not an instance of the `Flask` class.'
2721

2822
@pytest.mark.templates_folder
29-
def test_templates_folder():
23+
def test_templates_folder_module1():
3024
assert os.path.isdir('jobs/templates'), 'The `templates` folder has not been created.'
3125

3226
@pytest.mark.index_template
33-
def test_index_template():
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'."
27+
def test_index_template_module1():
28+
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
29+
assert tag_contains('index', 'h1', 'Jobs'), "The `<h1>` in the `index.html` template does not contain the contents 'Jobs'."
3830

3931
@pytest.mark.app_index_route_function
40-
def test_app_index_route_function():
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)
32+
def test_app_index_route_function_module1():
33+
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
34+
assert 'jobs' in dir(app), 'Have you created the `jobs` function?'
4335
with app.app.app_context():
44-
assert re.findall(r"return\s*render_template\s*\(\s*(?:'|\")index\.html(?:'|\")\s*\)", inspect.getsource(app.jobs))
36+
assert 'render_template:index.html' in get_functions(app.jobs)
4537

4638
@pytest.mark.app_route_decoractors
47-
def test_app_route_decoractors():
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)
39+
def test_app_route_decoractors_module1():
40+
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
41+
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
42+
assert 'jobs' in dir(app), 'Have you created the `jobs` function?'
5043

5144
rules = list_routes(app.app)
5245

tests/test_module2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
from jobs import app
55

66
@pytest.mark.layout_template
7-
def test_layout_template():
7+
def test_layout_template_module2():
88
pass
99

1010
@pytest.mark.add_bulma_css_framework
11-
def test_add_bulma_css_framework():
11+
def test_add_bulma_css_framework_module2():
1212
pass
1313

1414
@pytest.mark.add_custom_css
15-
def test_add_custom_css():
15+
def test_add_custom_css_module2():
1616
pass
1717

1818
@pytest.mark.add_fontawesome
19-
def test_add_fontawesome():
19+
def test_add_fontawesome_module2():
2020
pass
2121

2222
@pytest.mark.extend_base_template
23-
def test_extend_base_template():
23+
def test_extend_base_template_module2():
2424
pass

tests/test_module3.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,53 @@
44
from jobs import app
55

66
@pytest.mark.app_import_sqlite
7-
def test_app_import_sqlite():
7+
def test_app_import_sqlite_module3():
88
pass
99

1010
@pytest.mark.app_import_g
11-
def test_app_import_g():
11+
def test_app_import_g_module3():
1212
pass
1313

1414
@pytest.mark.app_db_path
15-
def test_app_db_path():
15+
def test_app_db_path_module3():
1616
pass
1717

1818
@pytest.mark.app_get_db_get_attribute
19-
def test_app_get_db_get_attribute():
19+
def test_app_get_db_get_attribute_module3():
2020
pass
2121

2222
@pytest.mark.app_get_db_connection
23-
def test_app_get_db_connection():
23+
def test_app_get_db_connection_module3():
2424
pass
2525

2626
@pytest.mark.app_get_db_row_factory
27-
def test_app_get_db_row_factory():
27+
def test_app_get_db_row_factory_module3():
2828
pass
2929

3030
@pytest.mark.app_query_db
31-
def test_app_query_db():
31+
def test_app_query_db_module3():
3232
pass
3333

3434
@pytest.mark.app_query_db_parameters
35-
def test_app_query_db_parameters():
35+
def test_app_query_db_parameters_module3():
3636
pass
3737

3838
@pytest.mark.app_query_db_execute
39-
def test_app_query_db_execute():
39+
def test_app_query_db_execute_module3():
4040
pass
4141

4242
@pytest.mark.app_query_db_fetchall
43-
def test_app_query_db_fetchall():
43+
def test_app_query_db_fetchall_module3():
4444
pass
4545

4646
@pytest.mark.app_query_db_one
47-
def test_app_query_db_one():
47+
def test_app_query_db_one_module3():
4848
pass
4949

5050
@pytest.mark.app_close_connection
51-
def test_app_close_connection():
51+
def test_app_close_connection_module3():
5252
pass
5353

5454
@pytest.mark.app_close_connection_decorator
55-
def test_app_close_connection_decorator():
55+
def test_app_close_connection_decorator_module3():
5656
pass

tests/test_module4.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,49 @@
44
from jobs import app
55

66
@pytest.mark.template_macros
7-
def test_template_macros():
7+
def test_template_macros_module4():
88
pass
99

1010
@pytest.mark.show_job_macro_definition
11-
def test_show_job_macro_definition():
11+
def test_show_job_macro_definition_module4():
1212
pass
1313

1414
@pytest.mark.show_job_macro_html
15-
def test_show_job_macro_html():
15+
def test_show_job_macro_html_module4():
1616
pass
1717

1818
@pytest.mark.show_job_macro_header
19-
def test_show_job_macro_header():
19+
def test_show_job_macro_header_module4():
2020
pass
2121

2222
@pytest.mark.show_job_macro_body
23-
def test_show_job_macro_body():
23+
def test_show_job_macro_body_module4():
2424
pass
2525

2626
@pytest.mark.show_jobs_macro_definition
27-
def test_show_jobs_macro_definition():
27+
def test_show_jobs_macro_definition_module4():
2828
pass
2929

3030
@pytest.mark.show_jobs_macro_for_loop
31-
def test_show_jobs_macro_for_loop():
31+
def test_show_jobs_macro_for_loop_module4():
3232
pass
3333

3434
@pytest.mark.show_jobs_macro_for_loop_body
35-
def test_show_jobs_macro_for_loop_body():
35+
def test_show_jobs_macro_for_loop_body_module4():
3636
pass
3737

3838
@pytest.mark.import_macros
39-
def test_import_macros():
39+
def test_import_macros_module4():
4040
pass
4141

4242
@pytest.mark.index_template
43-
def test_index_template():
43+
def test_index_template_module4():
4444
pass
4545

4646
@pytest.mark.display_all_jobs
47-
def test_display_all_jobs():
47+
def test_display_all_jobs_module4():
4848
pass
4949

5050
@pytest.mark.app_jobs_route_jobs
51-
def test_app_jobs_route_jobs():
51+
def test_app_jobs_route_jobs_module4():
5252
pass

tests/test_module5.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
from jobs import app
55

66
@pytest.mark.app_job_template
7-
def test_app_job_template():
7+
def test_app_job_template_module5():
88
pass
99

1010
@pytest.mark.app_job_route
11-
def test_app_job_route():
11+
def test_app_job_route_module5():
1212
pass
1313

1414
@pytest.mark.app_job_route_decorator
15-
def test_app_job_route_decorator():
15+
def test_app_job_route_decorator_module5():
1616
pass
1717

1818
@pytest.mark.app_job_route_parameter
19-
def test_app_job_route_parameter():
19+
def test_app_job_route_parameter_module5():
2020
pass
2121

2222
@pytest.mark.app_job_route_data
23-
def test_app_job_route_data():
23+
def test_app_job_route_data_module5():
2424
pass
2525

2626
@pytest.mark.app_job_route_pass_data
27-
def test_app_job_route_pass_data():
27+
def test_app_job_route_pass_data_module5():
2828
pass

tests/test_module6.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44
from jobs import app
55

66
@pytest.mark.employer_template
7-
def test_employer_template():
7+
def test_employer_template_module6():
88
pass
99

1010
@pytest.mark.employer_template_details
11-
def test_employer_template_details():
11+
def test_employer_template_details_module6():
1212
pass
1313

1414
@pytest.mark.employer_template_all_jobs
15-
def test_employer_template_all_jobs():
15+
def test_employer_template_all_jobs_module6():
1616
pass
1717

1818
@pytest.mark.employer_template_reviews
19-
def test_employer_template_reviews():
19+
def test_employer_template_reviews_module6():
2020
pass
2121

2222
@pytest.mark.employer_template_review_stars
23-
def test_employer_template_review_stars():
23+
def test_employer_template_review_stars_module6():
2424
pass
2525

2626
@pytest.mark.employer_template_review_details
27-
def test_employer_template_review_details():
27+
def test_employer_template_review_details_module6():
2828
pass
2929

3030
@pytest.mark.app_employer_route
31-
def test_app_employer_route():
31+
def test_app_employer_route_module6():
3232
pass
3333

3434
@pytest.mark.app_employer_route_employers
35-
def test_app_employer_route_employers():
35+
def test_app_employer_route_employers_module6():
3636
pass
3737

3838
@pytest.mark.app_employer_route_jobs
39-
def test_app_employer_route_jobs():
39+
def test_app_employer_route_jobs_module6():
4040
pass
4141

4242
@pytest.mark.app_employer_route_reviews
43-
def test_app_employer_route_reviews():
43+
def test_app_employer_route_reviews_module6():
4444
pass

tests/test_module7.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
from jobs import app
55

66
@pytest.mark.app_review_route
7-
def test_app_review_route():
7+
def test_app_review_route_module7():
88
pass
99

1010
@pytest.mark.app_review_post_request_check
11-
def test_app_review_post_request_check():
11+
def test_app_review_post_request_check_module7():
1212
pass
1313

1414
@pytest.mark.app_review_insert_review
15-
def test_app_review_insert_review():
15+
def test_app_review_insert_review_module7():
1616
pass
1717

1818
@pytest.mark.review_form_cancel
19-
def test_review_form_cancel():
19+
def test_review_form_cancel_module7():
2020
pass

tests/utils.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import ast
3+
import inspect
4+
from pprint import pprint
5+
6+
from bs4 import BeautifulSoup
7+
8+
def get_decorators(source):
9+
decorators = {}
10+
11+
def visit_FunctionDef(node):
12+
decorators[node.name] = []
13+
for n in node.decorator_list:
14+
name = ''
15+
if isinstance(n, ast.Call):
16+
name = n.func.attr if isinstance(n.func, ast.Attribute) else n.func.id
17+
else:
18+
name = n.attr if isinstance(n, ast.Attribute) else n.id
19+
20+
args = [a.s for a in n.args] if hasattr(n, 'args') else []
21+
decorators[node.name].append((name, args))
22+
23+
node_iter = ast.NodeVisitor()
24+
node_iter.visit_FunctionDef = visit_FunctionDef
25+
node_iter.visit(ast.parse(inspect.getsource(source)))
26+
return decorators
27+
28+
29+
def get_functions(source):
30+
functions = []
31+
32+
def visit_Call(node):
33+
name = node.func.attr if isinstance(node.func, ast.Attribute) else node.func.id
34+
functions.append(name + ':' + ':'.join([a.s for a in node.args]))
35+
36+
node_iter = ast.NodeVisitor()
37+
node_iter.visit_Call = visit_Call
38+
node_iter.visit(ast.parse(inspect.getsource(source)))
39+
40+
return functions
41+
42+
def list_routes(app):
43+
rules = []
44+
for rule in app.url_map.iter_rules():
45+
methods = ','.join(sorted(rule.methods))
46+
if rule.endpoint is not 'static':
47+
rules.append(rule.endpoint+':'+ methods +':'+ str(rule))
48+
return rules
49+
50+
def template_exists(name):
51+
return os.path.isfile('jobs/templates/' + name + '.html')
52+
53+
def template_contains(name, tag):
54+
doc = BeautifulSoup(open(os.getcwd() + '/jobs/templates/' + name + '.html'), 'html.parser')
55+
return doc.find(tag)
56+
57+
def tag_contains(name, tag, text):
58+
return template_contains(name, tag).text if template_contains(name, tag) else False

0 commit comments

Comments
 (0)