Skip to content

Commit

Permalink
Drop boolean parameters resolving ospc-org#765 and ospc-org#786
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Doupe committed Feb 21, 2018
1 parent e5ad0a0 commit 90386ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 46 deletions.
16 changes: 1 addition & 15 deletions webapp/apps/taxbrain/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,7 @@ class Meta:
widgets = {}
labels = {}
update_fields = {}
boolean_fields = [
"_ID_BenefitSurtax_Switch",
"_ID_BenefitCap_Switch",
"_ALD_InvInc_ec_base_RyanBrady",
"_NIIT_PT_taxed",
"_CG_nodiff",
"_EITC_indiv",
"_CTC_new_refund_limited",
"_II_no_em_nu18",
"_ID_AmountCap_Switch",
"_CTC_new_for_all",
"_CTC_new_refund_limited_all_payroll",
"_PT_wages_active_income",
"_PT_top_stacking",
]
boolean_fields = []

for param in TAXCALC_DEFAULTS_2016.values():
for field in param.col_fields:
Expand Down
53 changes: 22 additions & 31 deletions webapp/apps/taxbrain/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ def test_taxbrain_quick_calc_post(self):
"Test quick calculation post and full post from quick_calc page"
# switches 0, 4, 6 are False
data = get_post_data(START_YEAR, quick_calc=True)
del data[u'ID_BenefitSurtax_Switch_0']
del data[u'ID_BenefitSurtax_Switch_4']
del data[u'ID_BenefitSurtax_Switch_6']
data[u'ID_BenefitSurtax_Switch_0'] = ['False']
data[u'ID_BenefitSurtax_Switch_4'] = ['0']
data[u'ID_BenefitSurtax_Switch_6'] = ['0.0']
data[u'II_em'] = [u'4333']
data[u'ID_AmountCap_Switch_0'] = [u'True']

data[u'ID_AmountCap_Switch_0'] = [u'0']
wnc, created = WorkerNodesCounter.objects.get_or_create(singleton_enforce=1)
current_dropq_worker_offset = wnc.current_offset

Expand All @@ -75,7 +74,7 @@ def test_taxbrain_quick_calc_post(self):
truth_mods = {START_YEAR: {"_ID_BenefitSurtax_Switch":
[[0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0]],
"_ID_AmountCap_Switch":
[[1, 0, 0, 0, 0, 0, 0]],
[[0, 1, 1, 1, 1, 1, True]],
"_II_em": [4333.0]}
}
check_posted_params(result['tb_dropq_compute'], truth_mods,
Expand Down Expand Up @@ -153,9 +152,9 @@ def test_back_to_back_quickcalc(self):
"Test back to back quick calc posts"
# switches 0, 4, 6 are False
data = get_post_data(START_YEAR, quick_calc=True)
del data[u'ID_BenefitSurtax_Switch_0']
del data[u'ID_BenefitSurtax_Switch_4']
del data[u'ID_BenefitSurtax_Switch_6']
data[u'ID_BenefitSurtax_Switch_0'] = ['False']
data[u'ID_BenefitSurtax_Switch_4'] = ['0']
data[u'ID_BenefitSurtax_Switch_6'] = ['0.0']
data[u'II_em'] = [u'4333']

result = do_micro_sim(self.client, data)
Expand Down Expand Up @@ -184,7 +183,7 @@ def test_back_to_back_quickcalc(self):
def test_taxbrain_post_no_behavior_entries(self):
# marking as xfail for 822--don't have a way to
# check if too invalid parameters are posted

#Monkey patch to mock out running of compute jobs
get_dropq_compute_from_module('webapp.apps.taxbrain.views')

Expand Down Expand Up @@ -274,50 +273,42 @@ def test_taxbrain_edit_benefitsurtax_switch_show_correctly(self):
# sets them to False
data = get_post_data(START_YEAR, _ID_BenefitSurtax_Switches=False)
data[u'II_em'] = [u'4333']
data['ID_BenefitSurtax_Switch_3'] = [u'True']

result = do_micro_sim(self.client, data)

out = OutputUrl.objects.get(pk=result["pk"])
tsi = TaxSaveInputs.objects.get(pk=out.model_pk)
_ids = ['ID_BenefitSurtax_Switch_' + str(i) for i in range(7)]
# Verify that generated model has switches all False
assert all([(getattr(tsi, switch) == "False"
or getattr(tsi, switch) == u'0.0') for switch in _ids])
# only posted param is stored
assert ([_id in tsi.raw_input_fields for _id in _ids] ==
[False, False, False, True, False, False, False])
assert tsi.raw_input_fields['ID_BenefitSurtax_Switch_3'] == 'True'
# Now edit this page
edit_micro = '/taxbrain/edit/{0}/?start_year={1}'.format(result["pk"],
START_YEAR)
edit_page = self.client.get(edit_micro)
self.assertEqual(edit_page.status_code, 200)

# Here we POST flipping two switches. The value of the post is
# unimportant. The existence of the switch in the POST indicates
# that the user set them to on. So, they must get switched to True
# post some more data from the edit parameters page. Posting the
# same data (switch_0) again looks a little funny, but this
# is how it looks to the backend
next_csrf = str(edit_page.context['csrf_token'])
data2 = get_post_data(START_YEAR, _ID_BenefitSurtax_Switches=False)
mod = {u'II_em': [u'4333'],
u'ID_BenefitSurtax_Switch_0': [u'False'],
u'ID_BenefitSurtax_Switch_1': [u'False'],
u'ID_BenefitSurtax_Switch_1': [u'False,*,True'],
u'ID_BenefitSurtax_Switch_3': [u'True'],
'csrfmiddlewaretoken': next_csrf}
data2.update(mod)

result2 = do_micro_sim(self.client, data2)

out2 = OutputUrl.objects.get(pk=result2["pk"])
tsi2 = TaxSaveInputs.objects.get(pk=out2.model_pk)
assert (tsi2.ID_BenefitSurtax_Switch_0 == u'True'
or tsi2.ID_BenefitSurtax_Switch_0 == u'1.0')
assert (tsi2.ID_BenefitSurtax_Switch_1 == u'True'
or tsi2.ID_BenefitSurtax_Switch_1 == u'1.0')
assert (tsi2.ID_BenefitSurtax_Switch_2 == u'False'
or tsi2.ID_BenefitSurtax_Switch_2 == u'0.0')
assert (tsi2.ID_BenefitSurtax_Switch_3 == u'False'
or tsi2.ID_BenefitSurtax_Switch_3 == u'0.0')
assert (tsi2.ID_BenefitSurtax_Switch_4 == u'False'
or tsi2.ID_BenefitSurtax_Switch_4 == u'0.0')
assert (tsi2.ID_BenefitSurtax_Switch_5 == u'False'
or tsi2.ID_BenefitSurtax_Switch_5 == u'0.0')
assert (tsi2.ID_BenefitSurtax_Switch_6 == u'False'
or tsi2.ID_BenefitSurtax_Switch_6 == u'0.0')
assert tsi2.raw_input_fields['ID_BenefitSurtax_Switch_0'] == u'False'
assert tsi2.raw_input_fields['ID_BenefitSurtax_Switch_1'] == u'False,*,True'
assert tsi2.raw_input_fields['ID_BenefitSurtax_Switch_3'] == u'True'


def test_taxbrain_wildcard_params_with_validation_is_OK(self):
Expand Down

0 comments on commit 90386ba

Please sign in to comment.