1- # -*- coding: utf-8 -*-
2-
1+ import copy
2+ import dpath
3+ from http import client
34import json
4- from copy import deepcopy
55
6- from http .client import OK
7- import dpath
86from openfisca_country_template .situation_examples import single , couple
97
10- from . import subject
11-
128
139def assert_items_equal (x , y ):
1410 assert set (x ) == set (y )
1511
1612
17- def test_trace_basic ():
13+ def test_trace_basic (test_client ):
1814 simulation_json = json .dumps (single )
19- response = subject .post ('/trace' , data = simulation_json , content_type = 'application/json' )
20- assert response .status_code == OK
15+ response = test_client .post ('/trace' , data = simulation_json , content_type = 'application/json' )
16+ assert response .status_code == client . OK
2117 response_json = json .loads (response .data .decode ('utf-8' ))
2218 disposable_income_value = dpath .util .get (response_json , 'trace/disposable_income<2017-01>/value' )
2319 assert isinstance (disposable_income_value , list )
@@ -31,52 +27,52 @@ def test_trace_basic():
3127 assert_items_equal (basic_income_dep , ['age<2017-01>' ])
3228
3329
34- def test_trace_enums ():
35- new_single = deepcopy (single )
30+ def test_trace_enums (test_client ):
31+ new_single = copy . deepcopy (single )
3632 new_single ['households' ]['_' ]['housing_occupancy_status' ] = {"2017-01" : None }
3733 simulation_json = json .dumps (new_single )
38- response = subject .post ('/trace' , data = simulation_json , content_type = 'application/json' )
34+ response = test_client .post ('/trace' , data = simulation_json , content_type = 'application/json' )
3935 response_json = json .loads (response .data )
4036 housing_status = dpath .util .get (response_json , 'trace/housing_occupancy_status<2017-01>/value' )
4137 assert housing_status [0 ] == 'tenant' # The default value
4238
4339
44- def test_entities_description ():
40+ def test_entities_description (test_client ):
4541 simulation_json = json .dumps (couple )
46- response = subject .post ('/trace' , data = simulation_json , content_type = 'application/json' )
42+ response = test_client .post ('/trace' , data = simulation_json , content_type = 'application/json' )
4743 response_json = json .loads (response .data .decode ('utf-8' ))
4844 assert_items_equal (
4945 dpath .util .get (response_json , 'entitiesDescription/persons' ),
5046 ['Javier' , "Alicia" ]
5147 )
5248
5349
54- def test_root_nodes ():
50+ def test_root_nodes (test_client ):
5551 simulation_json = json .dumps (couple )
56- response = subject .post ('/trace' , data = simulation_json , content_type = 'application/json' )
52+ response = test_client .post ('/trace' , data = simulation_json , content_type = 'application/json' )
5753 response_json = json .loads (response .data .decode ('utf-8' ))
5854 assert_items_equal (
5955 dpath .util .get (response_json , 'requestedCalculations' ),
6056 ['disposable_income<2017-01>' , 'total_benefits<2017-01>' , 'total_taxes<2017-01>' ]
6157 )
6258
6359
64- def test_str_variable ():
65- new_couple = deepcopy (couple )
60+ def test_str_variable (test_client ):
61+ new_couple = copy . deepcopy (couple )
6662 new_couple ['households' ]['_' ]['postal_code' ] = {'2017-01' : None }
6763 simulation_json = json .dumps (new_couple )
6864
69- response = subject .post ('/trace' , data = simulation_json , content_type = 'application/json' )
65+ response = test_client .post ('/trace' , data = simulation_json , content_type = 'application/json' )
7066
71- assert response .status_code == OK
67+ assert response .status_code == client . OK
7268
7369
74- def test_trace_parameters ():
75- new_couple = deepcopy (couple )
70+ def test_trace_parameters (test_client ):
71+ new_couple = copy . deepcopy (couple )
7672 new_couple ['households' ]['_' ]['housing_tax' ] = {'2017' : None }
7773 simulation_json = json .dumps (new_couple )
7874
79- response = subject .post ('/trace' , data = simulation_json , content_type = 'application/json' )
75+ response = test_client .post ('/trace' , data = simulation_json , content_type = 'application/json' )
8076 response_json = json .loads (response .data .decode ('utf-8' ))
8177
8278 assert len (dpath .util .get (response_json , 'trace/housing_tax<2017>/parameters' )) > 0
0 commit comments