-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mauko Quiroga
committed
Nov 13, 2018
1 parent
a54a312
commit 5ac914e
Showing
2 changed files
with
42 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from openfisca_web_api.loader.parameters import walk_node | ||
import pytest | ||
|
||
from openfisca_core.parameters import ( | ||
ParameterNode, | ||
Scale, | ||
) | ||
from openfisca_core.parameters import ParameterNode, Scale | ||
|
||
from openfisca_web_api.loader.parameters import build_api_scale, walk_node | ||
|
||
def test_rate_tax_scale_serialization(): | ||
|
||
def test_build_rate_scale(): | ||
'''Extracts a 'rate' children from a bracket collection''' | ||
data = {'brackets': [{'rate': {'2014-01-01': {'value': 0.5}}, 'threshold': {'2014-01-01': {'value': 1}}}]} | ||
rate = Scale('this rate', data, None) | ||
assert build_api_scale(rate, 'rate') == {'2014-01-01': {1: 0.5}} | ||
|
||
|
||
def test_build_amount_scale(): | ||
'''Extracts an 'amount' children from a bracket collection''' | ||
data = {'brackets': [{'amount': {'2014-01-01': {'value': 0}}, 'threshold': {'2014-01-01': {'value': 1}}}]} | ||
rate = Scale('that amount', data, None) | ||
assert build_api_scale(rate, 'amount') == {'2014-01-01': {1: 0}} | ||
|
||
|
||
@pytest.fixture | ||
def walk_node_args(): | ||
parameters = [] | ||
metadata = {'location': 'foo', 'version': '1', 'repository_url': 'foo'} | ||
path_fragments = [] | ||
country_package_metadata = {'location': 'foo', 'version': '1', 'repository_url': 'foo'} | ||
|
||
return parameters, path_fragments, country_package_metadata | ||
|
||
|
||
def test_walk_node_rate_scale(walk_node_args): | ||
'''Serializes a 'rate' parameter node''' | ||
root_node = ParameterNode(data = {}) | ||
amount_rate_data = {'brackets': [{'rate': {'2014-01-01': {'value': 0.5}}, 'threshold': {'2014-01-01': {'value': 1}}}]} | ||
rate = Scale('scale', amount_rate_data, 'foo') | ||
root_node.children['rate'] = rate | ||
walk_node(root_node, parameters, [], metadata) | ||
assert parameters == [{'description': None, 'id': 'rate', 'metadata': {}, 'source': 'foo/blob/1', 'brackets': {'2014-01-01': {1: 0.5}}}] | ||
data = {'brackets': [{'rate': {'2014-01-01': {'value': 0.5}}, 'threshold': {'2014-01-01': {'value': 1}}}]} | ||
scale = Scale('this rate', data, None) | ||
root_node.children['rate'] = scale | ||
parameters = walk_node(root_node, *walk_node_args) | ||
assert parameters == [{'description': None, 'id': 'rate', 'metadata': {}, 'brackets': {'2014-01-01': {1: 0.5}}}] | ||
|
||
|
||
def test_amount_tax_scale_serialization(): | ||
parameters = [] | ||
metadata = {'location': 'foo', 'version': '1', 'repository_url': 'foo'} | ||
def test_walk_node_amount_scale(walk_node_args): | ||
'''Serializes a 'rate' parameter node''' | ||
root_node = ParameterNode(data = {}) | ||
amount_scale_data = {'brackets': [{'amount': {'2014-01-01': {'value': 0}}, 'threshold': {'2014-01-01': {'value': 1}}}]} | ||
amount = Scale('scale', amount_scale_data, 'foo') | ||
root_node.children['amount'] = amount | ||
walk_node(root_node, parameters, [], metadata) | ||
assert parameters == [{'description': None, 'id': 'amount', 'metadata': {}, 'source': 'foo/blob/1', 'brackets': {'2014-01-01': {1: 0}}}] | ||
data = {'brackets': [{'amount': {'2014-01-01': {'value': 0}}, 'threshold': {'2014-01-01': {'value': 1}}}]} | ||
scale = Scale('that amount', data, None) | ||
root_node.children['amount'] = scale | ||
parameters = walk_node(root_node, *walk_node_args) | ||
assert parameters == [{'description': None, 'id': 'amount', 'metadata': {}, 'brackets': {'2014-01-01': {1: 0}}}] |