def test_calculate_age_score_should_deduct_two(): profile = { "age": 25, "dependents": 1, "house": { "ownership_status": "wrong" }, "income": 1500, "marital_status": "married", "risk_questions": [0, 1, 0], "vehicle": { "year": 2018 } } rp_service = RiskProfileService(profile) score = rp_service.calculate_age_score() assert score == {"auto": -2, "disability": -2, "home": -2, "life": -2} assert rp_service.risk_profile == { "auto": "economic", "disability": "economic", "home": "economic", "life": "economic" }
def test_calculate_house_score_owned_house_should_do_nothing(): profile = { "age": 35, "dependents": 1, "income": 201000, "marital_status": "married", "house": { "ownership_status": "owned" }, "risk_questions": [0, 1, 0], "vehicle": { "year": 2018 } } rp_service = RiskProfileService(profile) score = rp_service.calculate_house_score() assert score == {"auto": 0, "disability": 0, "home": 0, "life": 0} assert rp_service.risk_profile == { "auto": "economic", "disability": "economic", "home": "economic", "life": "economic" }
def test_set_risk_from_score_should_work_without_ineligible(): rp_service = RiskProfileService(None) rp_service.score = {"auto": 3, "disability": 2, "home": 1, "life": 0} profile = rp_service.set_risk_from_score() assert profile == { "auto": "responsible", "disability": "regular", "home": "regular", "life": "economic" }
def test_calculate_vehicle_status_score_without_vehicle_should_be_ineligible(): profile = { "age": 35, "dependents": 2, "income": 201000, "marital_status": "single", "risk_questions": [0, 1, 0], } rp_service = RiskProfileService(profile) score = rp_service.calculate_vehicle_score() assert score == {"auto": 0, "disability": 0, "home": 0, "life": 0} assert rp_service.risk_profile == { "auto": "ineligible", "disability": "economic", "home": "economic", "life": "economic" }
def test_calculate_risk_profile_should_work_without_vehicle(): profile = { "age": 35, "dependents": 2, "income": 201000, "marital_status": "married", "house": { "ownership_status": "owned" }, "risk_questions": [0, 1, 0] } rp_service = RiskProfileService(profile) profile = rp_service.calculate_risk_profile() assert profile == { "auto": "ineligible", "disability": "economic", "home": "economic", "life": "regular" }
def test_calculate_vehicle_status_score_new_vehicle_should_add_one_auto(): profile = { "age": 35, "dependents": 2, "income": 201000, "marital_status": "single", "risk_questions": [0, 1, 0], "vehicle": { "year": datetime.now().year - 1 } } rp_service = RiskProfileService(profile) score = rp_service.calculate_vehicle_score() assert score == {"auto": 1, "disability": 0, "home": 0, "life": 0} assert rp_service.risk_profile == { "auto": "economic", "disability": "economic", "home": "economic", "life": "economic" }
def test_calculate_marital_status_score_single_should_not_change_score(): profile = { "age": 35, "dependents": 2, "income": 201000, "marital_status": "single", "risk_questions": [0, 1, 0], "vehicle": { "year": 2018 } } rp_service = RiskProfileService(profile) score = rp_service.calculate_relationship_score() assert score == {"auto": 0, "disability": 0, "home": 0, "life": 0} assert rp_service.risk_profile == { "auto": "economic", "disability": "economic", "home": "economic", "life": "economic" }
def test_calculate_dependent_score_two_dependents_should_add_one(): profile = { "age": 35, "dependents": 2, "income": 201000, "marital_status": "married", "risk_questions": [0, 1, 0], "vehicle": { "year": 2018 } } rp_service = RiskProfileService(profile) score = rp_service.calculate_dependent_score() assert score == {"auto": 0, "disability": 1, "home": 0, "life": 1} assert rp_service.risk_profile == { "auto": "economic", "disability": "economic", "home": "economic", "life": "economic" }
def post(self, data): profile_risk = RiskProfileService(data).calculate_risk_profile() return RiskProfileSchema().dump(profile_risk)