Skip to content

Commit

Permalink
test: tag name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3p3x0 committed Sep 5, 2018
1 parent 906ea30 commit 12290b0
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 63 deletions.
14 changes: 8 additions & 6 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ At this point you have a styled application. Check out the styles:

## 3.3 - Database Path

@pytest.mark.app_db_path below all of the import statements, create a constant called `PATH`, that contains the path to the already created database stored in `db/jobs.sqlite`.
@pytest.mark.app_db_path Below all of the import statements, create a constant called `PATH`, that contains the path to the already created database stored in `db/jobs.sqlite`.

## 3.4 - Global Database Attribute

Expand Down Expand Up @@ -177,9 +177,11 @@ In the body of `execute_sql` create a variable called `db`. Assign this variable
- Set the default of `single` to `False`.

## 3.9 - Query Database Function Execute

@pytest.mark.app_execute_sql_execute In the body of `execute_sql` call the `execute` function on `connection`, pass in the `sql` and `values` variables. Assign the return value to a variable called `cursor`.

## 3.10 - Query Database Function Commit

@pytest.mark.app_execute_sql_commit In the body of `execute_sql`:

- Create an `if` statement to test if `commit` is `True`.
Expand Down Expand Up @@ -252,7 +254,7 @@ In `<p>` tag add the following:
## 4.8 - Show Jobs Macro For Loop Body

@pytest.mark.show_jobs_macro_for_loop_body In the body of the `for` loop add a `<div>` with two classes `column` and `is_half`.

- In this `column` `<div>` add a call to the `show_job` macro passing in an individual `job` from the `for` loop.

## 4.9 - Import Macros
Expand All @@ -261,7 +263,7 @@ In `<p>` tag add the following:

```
{% from '_macros.html' import show_job, show_jobs with context %}
```
```

**Notes: Because each template extends `layouts.html` all of them will have access to these two new macros.**

Expand All @@ -284,7 +286,7 @@ Above the `render_template` function, call the `execute_sql` function:
- In the `render_template` function, pass a keyword argument of `jobs=jobs`.

**Preview**

At this point you can see all jobs on the homepage:

- Open a terminal at the root of the project
Expand All @@ -302,7 +304,7 @@ At this point you can see all jobs on the homepage:
In the file use an `extends` template tag to inherit `layout.html`.

After the `extends` tag add a template `block` called `content`. In the block call the `show_job` macro passing in `job`. **Note: Use the `{{}}` for the macro call.**

## 5.2 - Job Route Function

@pytest.mark.app_job_route In `app.py` create a function called `job`. In the body return a call to the `render_template` function passing in the newly created `job.html` template.
Expand All @@ -315,7 +317,7 @@ Still in `app.py`, add a route decorator with the URL path `/job/<job_id>` to th

## 5.4 - Job Route Parameter

@pytest.mark.app_job_route_parameter. To use the `job_id`, received from the URL, we need to pass it to the `job` function. Add `job_id` to the parameter list of the `job` function.
@pytest.mark.app_job_route_parameter To use the `job_id`, received from the URL, we need to pass it to the `job` function. Add `job_id` to the parameter list of the `job` function.

## 5.5 - Job Route Data

Expand Down
12 changes: 6 additions & 6 deletions tests/test_module1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@
from .utils import *
from jobs import app

@pytest.mark.app_import_flask
@pytest.mark.test_app_import_flask_module1
def test_app_import_flask_module1():
assert 'Flask' in dir(app), 'Have you imported the `Flask` class from `flask`?'
assert inspect.isclass(app.Flask), '`Flask` is not a class.'
assert 'render_template' in dir(app), '`render_template` has not been imported.'
assert inspect.isfunction(app.render_template), '`render_template` is not a function.'

@pytest.mark.app_create_flask_app
@pytest.mark.test_app_create_flask_app_module1
def test_app_create_flask_app_module1():
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
assert isinstance(app.app, app.Flask), '`app` is not an instance of the `Flask` class.'

@pytest.mark.templates_folder
@pytest.mark.test_templates_folder_module1
def test_templates_folder_module1():
assert os.path.isdir('jobs/templates'), 'The `templates` folder has not been created.'

@pytest.mark.index_template
@pytest.mark.test_index_template_module1
def test_index_template_module1():
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
assert template_find('index', 'h1', limit=1), "The `<h1>` in the `index.html` template does not contain the contents 'Jobs'."
assert template_find('index', 'h1', limit=1)[0].text == 'Jobs', "The `<h1>` in the `index.html` template does not contain the contents 'Jobs'."

@pytest.mark.app_index_route_function
@pytest.mark.test_app_index_route_function_module1
def test_app_index_route_function_module1():
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
assert 'jobs' in dir(app), 'Have you created the `jobs` function?'
result = [item for item in get_functions(app.jobs) if item.startswith('render_template:index.html')]
assert len(result) == 1, 'Have you called the `render_template` function.'

@pytest.mark.app_route_decoractors
@pytest.mark.test_app_route_decoractors_module1
def test_app_route_decoractors_module1():
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
Expand Down
10 changes: 5 additions & 5 deletions tests/test_module2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

calls = template_functions('layout', 'url_for')

@pytest.mark.layout_template
@pytest.mark.test_layout_template_module2
def test_layout_template_module2():
assert template_exists('layout'), 'The `layout.html` template does not exist in the `templates` folder.'

@pytest.mark.add_bulma_css_framework
@pytest.mark.test_add_bulma_css_framework_module2
def test_add_bulma_css_framework_module2():
assert template_exists('layout'), 'The `layout.html` template does not exist in the `templates` folder.'
assert 'static:filename:css/bulma.min.css' in calls, 'Looks like `bulma.min.css` is not linked in `layout.html`.'

@pytest.mark.add_custom_css
@pytest.mark.test_add_custom_css_module2
def test_add_custom_css_module2():
assert template_exists('layout'), 'The `layout.html` template does not exist in the `templates` folder.'
assert 'static:filename:css/app.css' in calls, 'Looks like `app.css` is not linked in `layout.html`.'

@pytest.mark.add_fontawesome
@pytest.mark.test_add_fontawesome_module2
def test_add_fontawesome_module2():
assert template_exists('layout'), 'The `layout.html` template does not exist in the `templates` folder.'
attr = {
Expand All @@ -28,7 +28,7 @@ def test_add_fontawesome_module2():
}
assert template_soup('layout').find('link', attr), 'Looks like FontAwesome is not linked in `layout.html`.'

@pytest.mark.extend_base_template
@pytest.mark.test_extend_base_template_module2
def test_extend_base_template_module2():
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
assert template_exists('layout'), 'The `layout.html` template does not exist in the `templates` folder.'
Expand Down
26 changes: 13 additions & 13 deletions tests/test_module3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
from jobs import app
from .utils import *

@pytest.mark.app_import_sqlite
@pytest.mark.test_app_import_sqlite_module3
def test_app_import_sqlite_module3():
assert 'sqlite3' in dir(app), 'Have you imported `sqlite`?'

@pytest.mark.app_import_g
@pytest.mark.test_app_import_g_module3
def test_app_import_g_module3():
assert 'g' in dir(app), 'Have you imported the `g` class from `flask`?'

@pytest.mark.app_db_path
@pytest.mark.test_app_db_path_module3
def test_app_db_path_module3():
assert 'PATH' in dir(app), 'Have you created a constant called `PATH`.'
assert app.PATH == 'db/jobs.sqlite', 'Have you created a constant called `PATH`?'

@pytest.mark.app_open_connection_get_attribute
@pytest.mark.test_app_open_connection_get_attribute_module3
def test_app_open_connection_get_attribute_module3():
assert 'open_connection' in dir(app), 'Have you defined a function named `open_connection`.'
assert 'getattr:g:_connection:None' in get_functions(app.open_connection), 'Have you used the `getattr` function to get the global `_connection`?'

@pytest.mark.app_open_connection_connection
@pytest.mark.test_app_open_connection_connection_module3
def test_app_open_connection_connection_module3():
assert 'g' in dir(app), 'Have you imported the `g` class from `flask`?'
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
Expand All @@ -33,7 +33,7 @@ def test_app_open_connection_connection_module3():
_, _, db_name = app.g._connection.execute('PRAGMA database_list').fetchone()
assert os.path.join(os.getcwd(), 'db', 'jobs.sqlite') == db_name, 'Did you pass the `connect` function the `PATH` constant?'

@pytest.mark.app_open_connection_row_factory
@pytest.mark.test_app_open_connection_row_factory_module3
def test_app_open_connection_row_factory_module3():
assert 'g' in dir(app), 'Have you imported the `g` class from `flask`?'
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
Expand All @@ -43,26 +43,26 @@ def test_app_open_connection_row_factory_module3():
assert isinstance(db, app.sqlite3.Connection), 'Are you returning the database connection?'
assert id(db.row_factory) == id(app.sqlite3.Row), 'Have you set the database `row_factory` to the sqlite3.Row class?'

@pytest.mark.app_execute_sql
@pytest.mark.test_app_execute_sql_module3
def test_app_execute_sql_module3():
assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
assert 'execute_sql' in dir(app), 'Have you defined a function named `execute_sql`.'
assert 'open_connection' in get_functions(app.execute_sql), 'Have you called the `open_connection` function in `execute_sql`?'

@pytest.mark.app_execute_sql_parameters
@pytest.mark.test_app_execute_sql_parameters_module3
def test_app_execute_sql_parameters_module3():
assert 'execute_sql' in dir(app), 'Have you defined a function named `execute_sql`.'
parameters = inspect.getfullargspec(app.execute_sql)
assert parameters.args[0] == 'sql' and parameters.args[1] == 'values' and parameters.args[2] == 'commit' and parameters.args[3] == 'single', 'Have you added the correct parameters to the `execute_sql` function parameters list?'
assert parameters.defaults[0] == () and parameters.defaults[1] == False and parameters.defaults[2] == False, 'Do the `args` and `one` parameters have the correct defaults in the `execute_sql` function parameters list?'

@pytest.mark.app_execute_sql_execute
@pytest.mark.test_app_execute_sql_execute_module3
def test_app_execute_sql_execute_module3():
assert 'execute_sql' in dir(app), 'Have you defined a function named `execute_sql`.'
assert 'execute:sql:values' in get_functions(app.execute_sql), 'Have you called the `execute` function in `execute_sql`?'

@pytest.mark.app_execute_sql_fetchall
def test_app_execute_sql_fetchall_module3():
@pytest.mark.test_app_execute_sql_results_module3
def test_app_execute_sql_results_module3():
assert 'execute_sql' in dir(app), 'Have you defined a function named `execute_sql`.'
assert 'fetchall' in get_functions(app.execute_sql), 'Have you called the `fetchall` function in `execute_sql`?'
assert 'fetchone' in get_functions(app.execute_sql), 'Have you called the `fetchone` function in `execute_sql`?'
Expand All @@ -72,13 +72,13 @@ def test_app_execute_sql_fetchall_module3():
results = app.execute_sql('SELECT * FROM job', single=True)
assert type(results) != list, 'Have you create an if statement to only return one result in `one` is true?'

@pytest.mark.app_close_connection
@pytest.mark.test_app_close_connection_module3
def test_app_close_connection_module3():
assert 'close_connection' in dir(app), 'Have you defined a function named `close_connection`.'
assert 'getattr:g:_connection:None' in get_functions(app.open_connection), 'Have you used the `getattr` function to get the global `_connection`?'
assert 'close' in get_functions(app.execute_sql), 'Have you called the `close` function in `execute_sql`?'

@pytest.mark.app_close_connection_decorator
@pytest.mark.test_app_close_connection_decorator_module3
def test_app_close_connection_decorator_module3():
assert 'close_connection' in dir(app), 'Have you defined a function named `close_connection`.'
decorator = get_decorators(app.close_connection)['close_connection'][0][0]
Expand Down
24 changes: 12 additions & 12 deletions tests/test_module4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,75 @@
from jobs import app
from .utils import *

@pytest.mark.template_macros
@pytest.mark.test_template_macros_module4
def test_template_macros_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'

@pytest.mark.show_job_macro_definition
@pytest.mark.test_show_job_macro_definition_module4
def test_show_job_macro_definition_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
assert 'show_job:job' in template_macros('_macros'), 'Have you created the `show_job` macro and added the correct parameter?'

@pytest.mark.show_job_macro_html
@pytest.mark.test_show_job_macro_html_module4
def test_show_job_macro_html_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
html = template_macro_soup('_macros', 'show_job')
p = html.select('.card .card-header .card-header-title')
div = html.select('.card-content .content')
assert len(p) == 1 and len(div) == 1, 'Has the `HTML` from `templates.html` been copied to the `show_job` macro?'

@pytest.mark.show_job_macro_header
@pytest.mark.test_show_job_macro_header_module4
def test_show_job_macro_header_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
assert 'job:job_id:job:id' in template_functions('_macros', 'url_for'), 'Looks like the job title link `href` is incorrect.'
assert 'job:title' in template_variables('_macros'), 'Looks like the job title link does not have content.'

@pytest.mark.show_job_macro_body
@pytest.mark.test_show_job_macro_body_module4
def test_show_job_macro_body_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
assert 'employer:employer_id:job:employer_id' in template_functions('_macros', 'url_for'), 'Looks like the job title link `href` is incorrect.'
assert 'job:employer_name' in template_variables('_macros'), 'Are you showing the employer name?'
assert 'job:salary' in template_variables('_macros'), 'Are you showing the job salary?'
assert 'job:description' in template_variables('_macros'), 'Are you showing the job description?'

@pytest.mark.show_jobs_macro_definition
@pytest.mark.test_show_jobs_macro_definition_module4
def test_show_jobs_macro_definition_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
assert 'show_jobs:jobs' in template_macros('_macros'), 'Have you created the `show_jobs` macro and added the correct parameter?'

@pytest.mark.show_jobs_macro_for_loop
@pytest.mark.test_show_jobs_macro_for_loop_module4
def test_show_jobs_macro_for_loop_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
html = template_macro_soup('_macros', 'show_jobs')
div = html.select('div.columns.is-multiline')
assert len(div) == 1, 'Has a `<div>` with classes of `columns` and `is-multiline` been added to the `show_jobs` macro?'
assert 'job:jobs' in show_jobs_for(), 'Does the `show_jobs` macro contain a `for` loop?'

@pytest.mark.show_jobs_macro_for_loop_body
@pytest.mark.test_show_jobs_macro_for_loop_body_module4
def test_show_jobs_macro_for_loop_body_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
html = template_macro_soup('_macros', 'show_jobs')
div = html.select('div.column.is-half')
assert len(div) == 1, 'Has a `<div>` with classes of `column` and `is-half` been added to the `show_jobs` macro `for` loop body?'
assert 'show_job:job' in show_jobs_for(), 'Does the `show_jobs` macro call `show_job`?'

@pytest.mark.import_macros
@pytest.mark.test_import_macros_module4
def test_import_macros_module4():
assert template_exists('_macros'), 'The `_macros.html` template does not exist in the `templates` folder.'
assert '_macros.html:show_job:show_jobs:True' == template_import('layout'), 'Have you imported `_macros.html` in `layouts.html`?'

@pytest.mark.index_template
@pytest.mark.test_index_template_module4
def test_index_template_module4():
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
el = template_data('index').select('.columns .column.is-one-fifth')
assert len(el) == 1, 'Has the `HTML` from `templates.html` been copied to the `index.html` template?'

@pytest.mark.display_all_jobs
@pytest.mark.test_display_all_jobs_module4
def test_display_all_jobs_module4():
assert template_exists('index'), 'The `index.html` template does not exist in the `templates` folder.'
assert 'show_jobs:jobs' in template_functions('index', 'show_jobs'), 'Have you call the `show_jobs` macro in the `index.html` file?'

@pytest.mark.app_jobs_route_jobs
@pytest.mark.test_app_jobs_route_jobs_module4
def test_app_jobs_route_jobs_module4():
assert 'jobs' in dir(app), 'Have you created the `jobs` function?'
execute_sql = 'execute_sql: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'
Expand Down
Loading

0 comments on commit 12290b0

Please sign in to comment.