def test_get_rates__rate_structure(self): """ ... get_rates, different values for rate_structure param.""" self.initialize_params() result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result), 2) self.assertEqual(len(result["data"]), 2) self.assertEqual(result["data"]["2.275"], 1) self.assertEqual(result["data"]["3.705"], 2) self.initialize_params({"rate_structure": "ARM"}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result["data"]), 1) self.assertEqual(result["data"]["0.125"], 1) self.initialize_params({"rate_structure": "ARM", "loan_term": 15}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result["data"]), 1) self.assertEqual(result["data"]["3.500"], 1) # loan_amount is less than min_loan_amt self.initialize_params( {"rate_structure": "ARM", "loan_term": 15, "loan_amount": 10000} ) result = get_rates(self.params.__dict__) self.assertFalse(result["data"]) self.assertTrue(result["timestamp"])
def test_get_rates__rate_structure(self): """ ... get_rates, different values for rate_structure param.""" self.initialize_params() result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result), 2) self.assertEqual(len(result['data']), 2) self.assertEqual(result['data']['2.275'], 1) self.assertEqual(result['data']['3.705'], 2) self.initialize_params({'rate_structure': 'ARM'}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['0.125'], 1) self.initialize_params({'rate_structure': 'ARM', 'loan_term': 15}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['3.500'], 1) # loan_amount is less than min_loan_amt self.initialize_params({ 'rate_structure': 'ARM', 'loan_term': 15, 'loan_amount': 10000 }) result = get_rates(self.params.__dict__) self.assertFalse(result['data']) self.assertTrue(result['timestamp'])
def test_get_rates__rate_structure(self): """ ... get_rates, different values for rate_structure param.""" self.initialize_params() result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result), 2) self.assertEqual(len(result['data']), 2) self.assertEqual(result['data']['2.275'], 1) self.assertEqual(result['data']['3.705'], 2) self.initialize_params({'rate_structure': 'ARM'}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['0.125'], 1) self.initialize_params({'rate_structure': 'ARM', 'loan_term': 15}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['3.500'], 1) # loan_amount is less than min_loan_amt self.initialize_params({'rate_structure': 'ARM', 'loan_term': 15, 'loan_amount': 10000}) result = get_rates(self.params.__dict__) self.assertFalse(result['data']) self.assertTrue(result['timestamp'])
def test_get_rates__data_load_testing(self): """ ... check that factor = -1 is applied to the results.""" self.initialize_params() self.params.state = 'MD' self.params.institution = 'Institution 8' result = get_rates(self.params.__dict__, data_load_testing=True) self.assertTrue(result) self.assertEqual(len(result['data']), 2) self.assertEqual(result['data']['1.995'], '-0.125') self.assertEqual(result['data']['1.985'], '-0.125') result = get_rates(self.params.__dict__, data_load_testing=False) self.assertTrue(result) self.assertEqual(len(result['data']), 2) self.assertEqual(result['data']['2.995'], 1) self.assertEqual(result['data']['2.985'], 1)
def test_get_rates__data_load_testing(self): """ ... check that factor = -1 is applied to the results.""" self.initialize_params() self.params.state = "MD" self.params.institution = "Institution 8" result = get_rates(self.params.__dict__, data_load_testing=True) self.assertTrue(result) self.assertEqual(len(result["data"]), 2) self.assertEqual(result["data"]["1.995"], "-0.125") self.assertEqual(result["data"]["1.985"], "-0.125") result = get_rates(self.params.__dict__, data_load_testing=False) self.assertTrue(result) self.assertEqual(len(result["data"]), 2) self.assertEqual(result["data"]["2.995"], 1) self.assertEqual(result["data"]["2.985"], 1)
def test_get_rates__no_results(self): """ ... get_rates with a valid state for which there's no data.""" self.initialize_params({"state": "IL"}) result = get_rates(self.params.__dict__, return_fees=True) self.assertFalse(result["data"]) self.assertFalse(result["timestamp"]) self.assertFalse("fees" in result)
def compare_scenarios_output(self, precalculated_results): """ Run scenarios thru API, compare results to <precalculated_results>.""" passed = True failed = [] for scenario_no in self.test_scenarios: # since these scenarios use loan_type=AGENCY if scenario_no in ['16', '42' ]: continue # rcparams = RateCheckerParameters() # rcparams.set_from_query_params(self.test_scenarios[scenario_no]) serializer = ParamsSerializer(data=self.test_scenarios[scenario_no]) api_result = get_rates(serializer.data, data_load_testing=True) expected_rate = "%s" % precalculated_results[scenario_no][0] expected_points = precalculated_results[scenario_no][1] if len(api_result['data']) > 1 or\ expected_rate not in api_result['data'] or\ expected_points != api_result['data'][expected_rate]: if expected_rate is not None and api_result['data']: passed = False failed.append(scenario_no) if not passed: failed.sort(key=int) self.messages.append("The following scenarios don't match: %s " % failed)
def compare_scenarios_output(self, precalculated_results): """ Run scenarios thru API, compare results to <precalculated_results>.""" passed = True failed = {} for scenario_no in self.test_scenarios: # since these scenarios use loan_type=AGENCY if scenario_no in ['16', '42' ]: continue serializer = ParamsSerializer(data=self.test_scenarios[scenario_no]) api_result = get_rates(serializer.data, data_load_testing=True) expected_rate = "%s" % precalculated_results[scenario_no][0] expected_points = precalculated_results[scenario_no][1] if len(api_result['data']) > 1 or\ expected_rate not in api_result['data'] or\ expected_points != api_result['data'][expected_rate]: if expected_rate is not None and api_result['data']: passed = False failed_str = ' scenario_no: ' + str(scenario_no) + \ ' Expected: ' + str(precalculated_results[scenario_no]) + \ ' Actual: ' + str(api_result['data']) + "<br>" failed[int(scenario_no)] = failed_str if not passed: sorted_failed = [] for i in sorted(failed): sorted_failed.append(failed[i]) self.messages.append("The following scenarios don't match: <br>%s" % sorted_failed)
def test_get_rates__no_results(self): """ ... get_rates with a valid state for which there's no data.""" self.initialize_params({'state': 'MD'}) result = get_rates(self.params.__dict__) self.assertFalse(result['data']) self.assertTrue(result['timestamp']) self.assertEqual(result['timestamp'].date(), self.NOW.date())
def compare_scenarios_output(self, precalculated_results): """ Run scenarios thru API, compare results to <precalculated_results>.""" passed = True failed = [] for scenario_no in self.test_scenarios: # since these scenarios use loan_type=AGENCY if scenario_no in ['16', '42']: continue # rcparams = RateCheckerParameters() # rcparams.set_from_query_params(self.test_scenarios[scenario_no]) serializer = ParamsSerializer( data=self.test_scenarios[scenario_no]) api_result = get_rates(serializer.data, data_load_testing=True) expected_rate = "%s" % precalculated_results[scenario_no][0] expected_points = precalculated_results[scenario_no][1] if len(api_result['data']) > 1 or\ expected_rate not in api_result['data'] or\ expected_points != api_result['data'][expected_rate]: if expected_rate is not None and api_result['data']: passed = False failed.append(scenario_no) if not passed: failed.sort(key=int) self.messages.append("The following scenarios don't match: %s " % failed)
def compare_scenarios_output(self, precalculated_results): """ Run scenarios thru API, compare results to <precalculated_results>.""" passed = True failed = {} for scenario_no in self.test_scenarios: # since these scenarios use loan_type=AGENCY if scenario_no in ['16', '42']: continue serializer = ParamsSerializer( data=self.test_scenarios[scenario_no]) api_result = get_rates(serializer.data, data_load_testing=True) expected_rate = "%s" % precalculated_results[scenario_no][0] expected_points = precalculated_results[scenario_no][1] if len(api_result['data']) > 1 or\ expected_rate not in api_result['data'] or\ expected_points != api_result['data'][expected_rate]: if expected_rate is not None and api_result['data']: passed = False failed_str = ' scenario_no: ' + str(scenario_no) + \ ' Expected: ' + str(precalculated_results[scenario_no]) + \ ' Actual: ' + str(api_result['data']) + "<br>" failed[int(scenario_no)] = failed_str if not passed: sorted_failed = [] for i in sorted(failed): sorted_failed.append(failed[i]) self.messages.append( "The following scenarios don't match: <br>%s" % sorted_failed)
def test_get_rates__plan_selection_logic(self): """ ... see that the correct selection is done when several row of same product_id are present.""" self.initialize_params({'loan_type': 'FHA'}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['2.005'], 1)
def test_get_rates__no_results(self): """ ... get_rates with a valid state for which there's no data.""" self.initialize_params({'state': 'IL'}) result = get_rates(self.params.__dict__, return_fees=True) self.assertFalse(result['data']) self.assertFalse(result['timestamp']) self.assertFalse('fees' in result)
def test_get_rates__loan_type(self): """ diff values for loan_type param.""" # actually only HighBalance ones self.initialize_params({'loan_type': 'FHA-HB', 'loan_term': 15, 'loan_amount': 10000, 'state': 'VA'}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['1.705'], 1)
def validate_scenario(self, scenario, expected_result): serializer = ParamsSerializer(data=scenario) serializer.is_valid(raise_exception=True) rates = get_rates(serializer.validated_data, data_load_testing=True) computed_rates = rates.get("data") return self.compare_result(computed_rates, expected_result)
def validate_scenario(self, scenario, expected_result): serializer = ParamsSerializer(data=scenario) serializer.is_valid(raise_exception=True) rates = get_rates(serializer.validated_data, data_load_testing=True) computed_rates = rates.get('data') return self.compare_result(computed_rates, expected_result)
def test_get_rates__rate_structure(self): """ ... get_rates, different values for rate_structure param.""" self.initialize_params() result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result), 2) self.assertEqual(len(result['data']), 2) self.assertEqual(result['data']['2.275'], 1) self.assertEqual(result['data']['3.705'], 2) self.params.property_type = 'SF' result = get_rates(self.params.__dict__, return_fees=True) self.assertTrue('fees' in result) threshold = 0.01 odollar = abs(result['fees']['origination_dollar'] - 1610.0) tparty = abs(result['fees']['third_party'] - 589.27) self.assertTrue(odollar < threshold) self.assertTrue(tparty < threshold) self.params.property_type = 'COOP' result = get_rates(self.params.__dict__, return_fees=True) self.assertTrue('fees' in result) threshold = 0.01 odollar = abs(result['fees']['origination_dollar'] - 1610.0) tparty = abs(result['fees']['third_party'] - 589.27) self.assertTrue(odollar < threshold) self.assertTrue(tparty < threshold) self.params.property_type = 'CONDO' result = get_rates(self.params.__dict__, return_fees=True) self.assertTrue('fees' in result) threshold = 0.01 odollar = abs(result['fees']['origination_dollar'] - 1608.0) tparty = abs(result['fees']['third_party'] - 587.27) self.assertTrue(odollar < threshold) self.assertTrue(tparty < threshold) self.initialize_params({'rate_structure': 'ARM'}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['0.125'], 1) self.initialize_params({'rate_structure': 'ARM', 'loan_term': 15}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['3.500'], 1) # loan_amount is less than min_loan_amt self.initialize_params({ 'rate_structure': 'ARM', 'loan_term': 15, 'loan_amount': 10000 }) result = get_rates(self.params.__dict__) self.assertFalse(result['data']) self.assertTrue(result['timestamp'])
def test_get_rates__rate_structure(self): """ ... get_rates, different values for rate_structure param.""" self.initialize_params() result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result), 2) self.assertEqual(len(result['data']), 2) self.assertEqual(result['data']['2.275'], 1) self.assertEqual(result['data']['3.705'], 2) self.params.property_type = 'SF' result = get_rates(self.params.__dict__, return_fees=True) self.assertTrue('fees' in result) threshold = 0.01 odollar = abs(result['fees']['origination_dollar'] - 1610.0) tparty = abs(result['fees']['third_party'] - 589.27) self.assertTrue(odollar < threshold) self.assertTrue(tparty < threshold) self.params.property_type = 'COOP' result = get_rates(self.params.__dict__, return_fees=True) self.assertTrue('fees' in result) threshold = 0.01 odollar = abs(result['fees']['origination_dollar'] - 1610.0) tparty = abs(result['fees']['third_party'] - 589.27) self.assertTrue(odollar < threshold) self.assertTrue(tparty < threshold) self.params.property_type = 'CONDO' result = get_rates(self.params.__dict__, return_fees=True) self.assertTrue('fees' in result) threshold = 0.01 odollar = abs(result['fees']['origination_dollar'] - 1608.0) tparty = abs(result['fees']['third_party'] - 587.27) self.assertTrue(odollar < threshold) self.assertTrue(tparty < threshold) self.initialize_params({'rate_structure': 'ARM'}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['0.125'], 1) self.initialize_params({'rate_structure': 'ARM', 'loan_term': 15}) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data']['3.500'], 1) # loan_amount is less than min_loan_amt self.initialize_params({'rate_structure': 'ARM', 'loan_term': 15, 'loan_amount': 10000}) result = get_rates(self.params.__dict__) self.assertFalse(result['data']) self.assertTrue(result['timestamp'])
def test_get_rates__loan_type(self): """ diff values for loan_type param.""" # actually only HighBalance ones self.initialize_params({ "loan_type": "FHA-HB", "loan_term": 15, "loan_amount": 10000, "state": "VA", }) result = get_rates(self.params.__dict__) self.assertTrue(result) self.assertEqual(len(result["data"]), 1) self.assertEqual(result["data"]["1.705"], 1)