-
Notifications
You must be signed in to change notification settings - Fork 82
Refactor web_api test using pytest.fixtures #984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a463475
Add a minimal TaxBenefitSystem Fixture in tests/web_api/conftest.py
RamParameswaran eca32de
Create `test_client` fixture in tests/web_api/test_variables
RamParameswaran 6166bd2
Fix // Change fixture scope to "package" to prevent recreating fixtur…
RamParameswaran c1abb72
Refactor all existing tests to use Fixtures instead of importing from…
RamParameswaran a328923
Style // fix flake8
RamParameswaran 72d83fb
Changed pytest scope of pytest.fixture test_tax_benefit_system to "mo…
RamParameswaran 3e6f555
Fix failing test caused by #987 refactoring of `test_variables.test_v…
RamParameswaran d79eec0
Refactoring due to modularisation works on #997
RamParameswaran fd3dc4d
Modularise `test_calculate.py`
RamParameswaran f906dbf
Modularise `test_entities.py`
RamParameswaran e70283b
Move `test_client` fixture to `/tests/fixtures/` directory to reduce …
RamParameswaran b09f50e
Remove `test_client` from individual test modules since it's in "test…
RamParameswaran f3dbee3
Modularise test_headers.py
RamParameswaran eddd680
Fix import styles
RamParameswaran 8e7fec0
Modularise test_parameters.py
RamParameswaran d9fe83a
Modularise test_spec.py
RamParameswaran 9cd824b
Modularise test_trace.py
RamParameswaran aa3157c
Remove `tax_benefit_system` and `subject` from "tests/web_api/__init_…
RamParameswaran 390f194
bump version
RamParameswaran b1dfd14
Update CHANGELOG.md
RamParameswaran 0e42b47
Style // remove redundant underscore from `_client` argument
RamParameswaran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
|
||
setup( | ||
name = 'OpenFisca-Core', | ||
version = '35.3.5', | ||
version = '35.3.6', | ||
author = 'OpenFisca Team', | ||
author_email = '[email protected]', | ||
classifiers = [ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from openfisca_web_api import app | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def test_client(tax_benefit_system): | ||
""" This module-scoped fixture creates an API client for the TBS defined in the `tax_benefit_system` | ||
fixture. This `tax_benefit_system` is mutable, so you can add/update variables. Example: | ||
|
||
``` | ||
from openfisca_country_template import entities | ||
from openfisca_core import periods | ||
from openfisca_core.variables import Variable | ||
... | ||
|
||
class new_variable(Variable): | ||
value_type = float | ||
entity = entities.Person | ||
definition_period = periods.MONTH | ||
label = "New variable" | ||
reference = "https://law.gov.example/new_variable" # Always use the most official source | ||
|
||
tax_benefit_system.add_variable(new_variable) | ||
flask_app = app.create_app(tax_benefit_system) | ||
``` | ||
""" | ||
|
||
# Create the test API client | ||
flask_app = app.create_app(tax_benefit_system) | ||
return flask_app.test_client() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pkg_resources | ||
from openfisca_web_api.app import create_app | ||
from openfisca_core.scripts import build_tax_benefit_system | ||
|
||
TEST_COUNTRY_PACKAGE_NAME = 'openfisca_country_template' | ||
distribution = pkg_resources.get_distribution(TEST_COUNTRY_PACKAGE_NAME) | ||
tax_benefit_system = build_tax_benefit_system(TEST_COUNTRY_PACKAGE_NAME, extensions = None, reforms = None) | ||
subject = create_app(tax_benefit_system).test_client() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import distribution, subject | ||
from . import distribution | ||
|
||
parameters_response = subject.get('/parameters') | ||
|
||
|
||
def test_package_name_header(): | ||
def test_package_name_header(test_client): | ||
parameters_response = test_client.get('/parameters') | ||
assert parameters_response.headers.get('Country-Package') == distribution.key | ||
|
||
|
||
def test_package_version_header(): | ||
def test_package_version_header(test_client): | ||
parameters_response = test_client.get('/parameters') | ||
assert parameters_response.headers.get('Country-Package-Version') == distribution.version |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.