-
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.
Add a
/entities
endpoint to the API #714
- Loading branch information
Showing
9 changed files
with
160 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ dist/ | |
/tags | ||
.tags* | ||
.noseids | ||
.pytest_cache |
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,42 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals, print_function, division, absolute_import | ||
from openfisca_core.commons import to_unicode | ||
|
||
|
||
def build_entities(tax_benefit_system): | ||
entities = { | ||
entity.key: build_entity(entity) | ||
for entity in tax_benefit_system.entities | ||
} | ||
return entities | ||
|
||
|
||
def build_entity(entity): | ||
formatted_doc = to_unicode(entity.doc.strip()) | ||
|
||
formatted_entity = { | ||
'plural': entity.plural, | ||
'description': to_unicode(entity.label), | ||
'documentation': formatted_doc | ||
} | ||
if not entity.is_person: | ||
formatted_entity['roles'] = { | ||
role.key: build_role(role) | ||
for role in entity.roles | ||
} | ||
return formatted_entity | ||
|
||
|
||
def build_role(role): | ||
formatted_role = { | ||
'plural': role.plural, | ||
'description': role.doc | ||
} | ||
|
||
if role.max: | ||
formatted_role['max'] = role.max | ||
if role.subroles: | ||
formatted_role['max'] = len(role.subroles) | ||
|
||
return formatted_role |
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,42 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals, print_function, division, absolute_import | ||
from http.client import OK | ||
from nose.tools import assert_equal | ||
import json | ||
import openfisca_country_template | ||
from openfisca_core.commons import to_unicode | ||
from . import subject | ||
|
||
entities_response = subject.get('/entities') | ||
|
||
# /entities | ||
|
||
|
||
def test_return_code(): | ||
assert_equal(entities_response.status_code, OK) | ||
|
||
|
||
def test_response_data(): | ||
entities = json.loads(entities_response.data.decode('utf-8')) | ||
test_documentation = to_unicode(openfisca_country_template.entities.Household.doc.strip()) | ||
|
||
assert_equal( | ||
entities['household'], | ||
{ | ||
'description': 'Household', | ||
'documentation': test_documentation, | ||
'plural': 'households', | ||
'roles': { | ||
'child': { | ||
'description': 'Other individuals living in the household.', | ||
'plural': 'children' | ||
}, | ||
'parent': { | ||
'description': 'The one or two adults in charge of the household.', | ||
'max': 2, | ||
'plural': "parents" | ||
} | ||
} | ||
} | ||
) |
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