-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor web_api test using pytest.fixtures
Merge pull request #984 from openfisca/refactor-web_api-test-fixtures
- Loading branch information
Showing
13 changed files
with
273 additions
and
232 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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.