From 85b12f45a1f11b68f07460cbc35a2bb9a9b0c85e Mon Sep 17 00:00:00 2001 From: Henry Doupe Date: Fri, 19 Jan 2018 13:21:42 -0500 Subject: [PATCH] Update tests part 1 --- webapp/apps/dynamic/tests/test_behavioral.py | 2 +- webapp/apps/dynamic/tests/test_elasticity.py | 2 +- webapp/apps/dynamic/tests/test_ogusa.py | 2 +- webapp/apps/taxbrain/tests/test_views.py | 34 +++--- webapp/apps/test_assets/__init__.py | 2 +- webapp/apps/test_assets/test_reform.py | 113 ------------------- webapp/apps/test_assets/utils.py | 4 +- 7 files changed, 24 insertions(+), 135 deletions(-) diff --git a/webapp/apps/dynamic/tests/test_behavioral.py b/webapp/apps/dynamic/tests/test_behavioral.py index 3c604616..b9dca08f 100644 --- a/webapp/apps/dynamic/tests/test_behavioral.py +++ b/webapp/apps/dynamic/tests/test_behavioral.py @@ -89,7 +89,7 @@ def test_behavioral_reform_with_wildcard(self): def test_behavioral_reform_from_file(self): # Do the microsim from file - data = get_file_post_data(START_YEAR, test_reform.reform_text) + data = get_file_post_data(START_YEAR, test_reform.r1) micro1 = do_micro_sim(self.client, data, post_url='/taxbrain/file/') micro1 = micro1["response"] diff --git a/webapp/apps/dynamic/tests/test_elasticity.py b/webapp/apps/dynamic/tests/test_elasticity.py index b24146e6..ba3416e4 100644 --- a/webapp/apps/dynamic/tests/test_elasticity.py +++ b/webapp/apps/dynamic/tests/test_elasticity.py @@ -81,7 +81,7 @@ def test_elasticity_edit(self): @pytest.mark.xfail def test_elasticity_reform_from_file(self): # Do the microsim from file - data = get_file_post_data(START_YEAR, test_reform.reform_text) + data = get_file_post_data(START_YEAR, test_reform.r1) # set dyn_dropq_compute to False so that # webapp.apps.dynamic_views.dropq_compute is not Mocked micro1 = do_micro_sim( diff --git a/webapp/apps/dynamic/tests/test_ogusa.py b/webapp/apps/dynamic/tests/test_ogusa.py index 260f3c8f..5127a60b 100644 --- a/webapp/apps/dynamic/tests/test_ogusa.py +++ b/webapp/apps/dynamic/tests/test_ogusa.py @@ -163,7 +163,7 @@ def test_ogusa_reform_from_file(self): self.client.login(username='temporary', password='temporary') start_year = 2016 # Do the microsim from file - data = get_file_post_data(start_year, test_reform.reform_text) + data = get_file_post_data(start_year, test_reform.r1) micro1 = do_micro_sim(self.client, data, post_url='/taxbrain/file/') # Do the partial equilibrium simulation based on the microsim diff --git a/webapp/apps/taxbrain/tests/test_views.py b/webapp/apps/taxbrain/tests/test_views.py index 0953622e..8fa4db0f 100644 --- a/webapp/apps/taxbrain/tests/test_views.py +++ b/webapp/apps/taxbrain/tests/test_views.py @@ -103,7 +103,7 @@ def test_taxbrain_file_post_quick_calc(self): Using file-upload interface, test quick calculation post and full post from quick_calc page """ - data = get_file_post_data(START_YEAR, test_reform.reform_text, quick_calc=False) + data = get_file_post_data(START_YEAR, test_reform.r1, quick_calc=False) wnc, created = WorkerNodesCounter.objects.get_or_create(singleton_enforce=1) current_dropq_worker_offset = wnc.current_offset @@ -125,7 +125,7 @@ def test_taxbrain_file_post_quick_calc(self): # Check that data was saved properly truth_mods = taxcalc.Calculator.read_json_param_objects( - test_reform.reform_text, + test_reform.r1, None, ) truth_mods = truth_mods["policy"] @@ -150,7 +150,7 @@ def test_taxbrain_file_post_quick_calc(self): def test_back_to_back_quickcalc(self): - "Test back to back quick calc posts" + "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'] @@ -333,7 +333,7 @@ def test_taxbrain_wildcard_params_with_validation_is_OK(self): truth_mods = { START_YEAR: {'_II_brk2_cpi': False}, START_YEAR + 2: { - '_II_brk1': [[15000.0, 19069.63, 9534.81, 13650.38, 19069.63]] + '_II_brk1': [[15000.0, 19050.0, 9525.0, 13600.0, 19050.0]] } } check_posted_params(result['tb_dropq_compute'], truth_mods, @@ -566,13 +566,13 @@ def test_taxbrain_rt_to_passthrough(self): do_micro_sim(self.client, data) def test_taxbrain_file_post_only_reform(self): - data = get_file_post_data(START_YEAR, test_reform.reform_text) + data = get_file_post_data(START_YEAR, test_reform.r1) do_micro_sim(self.client, data, post_url="/taxbrain/file/") def test_taxbrain_file_post_reform_and_assumptions(self): data = get_file_post_data(START_YEAR, - test_reform.reform_text, + test_reform.r1, test_assumptions.assumptions_text) do_micro_sim(self.client, data, post_url="/taxbrain/file/") @@ -636,8 +636,8 @@ def test_taxbrain_error_reform_file(self): # Check that no redirect happens self.assertEqual(response.status_code, 200) assert response.context['has_errors'] is True - msg = 'ERROR: _II_brk1_4 value 9e+99 > max value 89239.88 for _II_brk2_4 for 2024' - assert msg in response.context['errors'] + assert any(['_II_brk1_4' in msg and '2024' in msg + for msg in response.context['errors']]) # get most recent object objects = js.objects.order_by('id') @@ -672,8 +672,8 @@ def test_taxbrain_warning_reform_file(self): # Check that no redirect happens self.assertEqual(response.status_code, 200) assert response.context['has_errors'] is True - msg = 'WARNING: _STD_0 value 1073.53 < min value 7191.08 for 2023' - assert msg in response.context['errors'] + assert any(['_STD_0' in msg and '2023' in msg + for msg in response.context['errors']]) # get most recent object objects = js.objects.order_by('id') @@ -693,7 +693,7 @@ def test_taxbrain_warning_reform_file(self): truth_mods = { 2020: { - "_STD": [[1000, 13583.32, 6791.67, 10000.32, 13583.32]] + "_STD": [[1000, 24981.84, 12490.92, 18736.38, 24981.84]] } } check_posted_params(result['tb_dropq_compute'], truth_mods, START_YEAR) @@ -715,8 +715,8 @@ def test_taxbrain_reform_file_file_swap(self): # Check that no redirect happens self.assertEqual(response.status_code, 200) assert response.context['has_errors'] is True - msg = 'WARNING: _STD_0 value 1073.53 < min value 7191.08 for 2023' - assert msg in response.context['errors'] + assert any(['_STD_0' in msg and '2023' in msg + for msg in response.context['errors']]) # get most recent object objects = js.objects.order_by('id') @@ -762,8 +762,8 @@ def test_taxbrain_reform_file_file_swap_no_assump(self): # Check that no redirect happens self.assertEqual(response.status_code, 200) assert response.context['has_errors'] is True - msg = 'WARNING: _STD_0 value 1073.53 < min value 7191.08 for 2023' - assert msg in response.context['errors'] + assert any(['_STD_0' in msg and '2023' in msg + for msg in response.context['errors']]) # get most recent object objects = js.objects.order_by('id') @@ -807,7 +807,7 @@ def test_taxbrain_up_to_2018(self): def test_taxbrain_file_up_to_2018(self): start_year = 2018 - data = get_file_post_data(start_year, test_reform.reform_text) + data = get_file_post_data(start_year, test_reform.r1) post_url = '/taxbrain/file/' @@ -819,7 +819,7 @@ def test_taxbrain_file_up_to_2018(self): # Check that data was saved properly truth_mods = taxcalc.Calculator.read_json_param_objects( - test_reform.reform_text, + test_reform.r1, None, ) truth_mods = truth_mods["policy"] diff --git a/webapp/apps/test_assets/__init__.py b/webapp/apps/test_assets/__init__.py index cda67999..a36a3586 100644 --- a/webapp/apps/test_assets/__init__.py +++ b/webapp/apps/test_assets/__init__.py @@ -1,2 +1,2 @@ from test_assumptions import assumptions_text -from test_reform import reform_text +from test_reform import r1 diff --git a/webapp/apps/test_assets/test_reform.py b/webapp/apps/test_assets/test_reform.py index 8c1a1017..4b19ede7 100644 --- a/webapp/apps/test_assets/test_reform.py +++ b/webapp/apps/test_assets/test_reform.py @@ -1,116 +1,3 @@ -reform_text = """// Title: 2016 Trump Campaign Tax Plan -// Reform_File_Author: Matt Jensen -// Reform_Reference: https://www.donaldjtrump.com/policies/tax-plan -// Reform_Description: -// - New personal income tax schedule (regular/non-AMT/non-pass-through) (1) -// - New pass-through income tax schedule (2) -// - New long-term capital gains and qualified dividends tax schedule (3) -// - Repeal Alternative Minimum Tax (4) -// - Repeal Net Investment Income Tax (5) -// - Raise the Standard Deduction (6) -// - Repeal the Personal Exemption (7) -// - New above the line deduction for child and elder care (8) -// - Cap itemized deductions (9) -// Reform_Parameter_Map: -// - 1: _II_rt*, II_brk* -// - 2: _PT_* -// - 3: _CG_* -// - 4: _AMT_* -// - 5: _NIIT_rt -// - 6: _STD -// - 7: _II_em -// - 8: _ALD_Dependents* -// - 9: _ID_c -{ - "policy": { - "_II_rt1": { - "2017": [0.12], - "2018": [0.12] - }, - "_II_brk1": - {"2017": [[37500, 75000, 37500, 37500, 75000]]}, - "_II_rt2": - {"2017": [0.25]}, - "_II_brk2": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_II_rt3": - {"2017": [0.25]}, - "_II_brk3": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_II_rt4": - {"2017": [0.25]}, - "_II_brk4": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_II_rt5": - {"2017": [0.25]}, - "_II_brk5": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_II_rt6": - {"2017": [0.25]}, - "_II_brk6": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_II_rt7": - {"2017": [0.33]}, - "_PT_rt1": - {"2017": [0.12]}, - "_PT_brk1": - {"2017": [[37500, 75000, 37500, 37500, 75000]]}, - "_PT_rt2": - {"2017": [0.15]}, - "_PT_brk2": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_PT_rt3": - {"2017": [0.15]}, - "_PT_brk3": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_PT_rt4": - {"2017": [0.15]}, - "_PT_brk4": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_PT_rt5": - {"2017": [0.15]}, - "_PT_brk5": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_PT_rt6": - {"2017": [0.15]}, - "_PT_brk6": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_PT_rt7": - {"2017": [0.15]}, - "_CG_brk1": - {"2017": [[37500, 75000, 37500, 37500, 75000]]}, - "_CG_brk2": - {"2017": [[112500, 225000, 112500, 112500, 225000]]}, - "_AMT_rt1": - {"2017": [0]}, - "_AMT_rt2": - {"2017": [0]}, - "_NIIT_rt": - {"2017": [0]}, - "_STD": - {"2017": [[15000, 30000, 15000, 15000, 30000]]}, - "_II_em": - {"2017": [0]}, - "_ALD_Dependents_thd": - {"2017": [[250000, 500000, 250000, 500000, 500000]]}, - "_ALD_Dependents_Elder_c": - {"2017": [5000]}, - "_ALD_Dependents_Child_c": - {"2017": [7156]}, - "_ID_c": - {"2017": [[100000, 200000, 100000, 100000, 200000]]} - } -} - -// Note: Due to lack of detail, data, or modeling capability, many provisions cannot be scored. -// These omitted provisions include: -// - Allow expenssing for pass-through firms -// - Tax carried interest as ordinary business income -// - Repeal pass-through business tax expenditures -// - Corporate tax provisions -// - Estate tax provisions""" - - r1 = """// r1.json assumes reform with the following provisions: // - adhoc raises in OASDI maximum taxable earnings in 2018, 2019 and 2020, // with _SS_Earnings_c wage indexed in subsequent years diff --git a/webapp/apps/test_assets/utils.py b/webapp/apps/test_assets/utils.py index 07d0f039..3795f946 100644 --- a/webapp/apps/test_assets/utils.py +++ b/webapp/apps/test_assets/utils.py @@ -85,7 +85,9 @@ def check_posted_params(mock_compute, params_to_check, start_year): assert last_posted["first_budget_year"] == int(start_year) for year in params_to_check: for param in params_to_check[year]: - assert user_mods["policy"][str(year)][param] == params_to_check[year][param] + act = user_mods["policy"][str(year)][param] + exp = params_to_check[year][param] + assert exp == act def get_post_data(start_year, _ID_BenefitSurtax_Switches=True, quick_calc=False):