Skip to content

Commit

Permalink
test: module 5 tests complete
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3p3x0 committed Aug 24, 2018
1 parent 89eb747 commit 81dc52e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
7 changes: 6 additions & 1 deletion jobs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ def close_connection(exception):
@app.route('/jobs')
def jobs():
jobs = query_db('SELECT job.id, job.title, job.description, job.salary, employer.id as employer_id, employer.name as employer_name FROM job JOIN employer ON employer.id = job.employer_id')
return render_template('index.html', jobs=jobs)
return render_template('index.html', jobs=jobs)

@app.route('/job/<job_id>')
def job(job_id):
job = query_db('SELECT job.id, job.title, job.description, job.salary, employer.id as employer_id, employer.name as employer_name FROM job JOIN employer ON employer.id = job.employer_id WHERE job.id = ?', [job_id], True)
return render_template('job.html', job=job)
3 changes: 3 additions & 0 deletions jobs/templates/job.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "layout.html" %}

{{ show_job(job) }}
4 changes: 2 additions & 2 deletions tests/test_module3.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_app_query_db_module3():
def test_app_query_db_parameters_module3():
assert 'query_db' in dir(app), 'Have you defined a function named `query_db`.'
parameters = inspect.getfullargspec(app.query_db)
assert parameters.args[0] == 'query' and parameters.args[1] == 'args' and parameters.args[2] == 'one', 'Have you added the correct parameters to the parameters list?'
assert parameters.defaults[0] == () and parameters.defaults[1] == False, 'Do the `args` and `one` parameters have the correct defaults?'
assert parameters.args[0] == 'query' and parameters.args[1] == 'args' and parameters.args[2] == 'one', 'Have you added the correct parameters to the `query_db` function parameters list?'
assert parameters.defaults[0] == () and parameters.defaults[1] == False, 'Do the `args` and `one` parameters have the correct defaults in the `query_db` function parameters list?'

@pytest.mark.app_query_db_execute
def test_app_query_db_execute_module3():
Expand Down
22 changes: 16 additions & 6 deletions tests/test_module5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@
import sys

from jobs import app
from .utils import *

@pytest.mark.app_job_template
def test_app_job_template_module5():
pass
assert template_exists('job'), 'The `job.html` template does not exist in the `templates` folder.'
assert 'layout.html' in template_extends('job'), 'The `job.html` template does not extend `layout.html`.'
assert 'show_job:job' in template_functions('job', 'show_job'), 'Have you call the `show_job` macro in the `job.html` file?'

@pytest.mark.app_job_route
def test_app_job_route_module5():
pass
assert 'job' in dir(app), 'Have you created the `job` function?'
result = [item for item in get_functions(app.job) if item.startswith('render_template:job.html')]
assert len(result) == 1, 'Have you called the `render_template` function.'

@pytest.mark.app_job_route_decorator
def test_app_job_route_decorator_module5():
pass
assert 'job' in dir(app), 'Have you created the `job` function?'
assert 'route:/job/<job_id>' in get_functions(app.job)

@pytest.mark.app_job_route_parameter
def test_app_job_route_parameter_module5():
pass
assert 'job' in dir(app), 'Have you created the `job` function?'
assert 'job_id' in inspect.getfullargspec(app.job).args, 'Have you added the correct parameters to the `job` function parameters list?'

@pytest.mark.app_job_route_data
def test_app_job_route_data_module5():
pass
assert 'job' in dir(app), 'Have you created the `job` function?'
query_db = 'query_db:SELECT job.id, job.title, job.description, job.salary, employer.id as employer_id, employer.name as employer_name FROM job JOIN employer ON employer.id = job.employer_id WHERE job.id = ?:job_id:True'
assert query_db in get_functions(app.job), '`query_db` has not been called or has the wrong parameters.'

@pytest.mark.app_job_route_pass_data
def test_app_job_route_pass_data_module5():
pass
assert 'job' in dir(app), 'Have you created the `job` function?'
assert 'render_template:job.html:job:job' in get_functions(app.job), 'Have you added `job` to the `render_template` call.'

0 comments on commit 81dc52e

Please sign in to comment.