def test_is_single(): # No rule to apply user_info = { "age": 62, "dependents": 0, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = IsMaried() risk = rule.apply_rule(user_dto, user_base_risk) # User risk should not change assert risk.disability.risk == 2 assert risk.auto.risk == 2 assert risk.home.risk == 2 assert risk.life.risk == 2
def test_is_maried(): # IsMaried user_info = { "age": 62, "dependents": 2, "income": 0, "marital_status": "married", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = IsMaried() risk = rule.apply_rule(user_dto, user_base_risk) # User should not be eligible to disability assert risk.disability.risk == 1 assert risk.auto.risk == 2 assert risk.home.risk == 2 assert risk.life.risk == 3
def test_no_house(): # No house user_info = { "age": 62, "dependents": 2, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = HasMotgagedHouse() | HasNoHouse risk = rule.apply_rule(user_dto, user_base_risk) # User should not be eligible to home insurance assert risk.disability.risk == 2 assert risk.auto.risk == 2 assert risk.home.is_eligible == False assert risk.life.risk == 2
def test_has_no_income(): # HasNoIncome user_info = { "age": 62, "dependents": 2, "income": 0, "marital_status": "single", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = HasNoIncome() | IncomeAboveTwoHundredK risk = rule.apply_rule(user_dto, user_base_risk) # User should not be eligible to disability assert risk.disability.is_eligible == False assert risk.auto.risk == 2 assert risk.home.risk == 2 assert risk.life.risk == 2
def test_income_above_two_hundred(): # IncomeAboveTwoHundredK user_info = { "age": 62, "dependents": 0, "income": 220000, "marital_status": "single", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = HasNoIncome() | IncomeAboveTwoHundredK risk = rule.apply_rule(user_dto, user_base_risk) # All risk lines should be reduced by 1 assert risk.disability.risk == 1 assert risk.auto.risk == 1 assert risk.home.risk == 1 assert risk.life.risk == 1
def test_has_dependents(): # HasDependents user_info = { "age": 62, "dependents": 2, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = HasDependents() risk = rule.apply_rule(user_dto, user_base_risk) # User should have 1 score point added to life and disability assert risk.disability.risk == 3 assert risk.auto.risk == 2 assert risk.home.risk == 2 assert risk.life.risk == 3
def test_age_over_sixty(): # AgeOverSixty user1_info = { "age": 62, "dependents": 2, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user1_dto = UserInformationDTO(**user1_info) user1_base_risk = UserRisk(user1_dto) # Build rules set rule = (AgeOverSixty() | AgeBetweenThirtyAndForty | AgeUnderThirty ) risk = rule.apply_rule(user1_dto, user1_base_risk) # User 1 should not be eligible to life nor disability assert risk.disability.is_eligible == False assert risk.auto.risk == 2 assert risk.home.risk == 2 assert risk.life.is_eligible == False
def test_age_no_rule(): # No rule user4_info = { "age": 40, "dependents": 2, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user4_dto = UserInformationDTO(**user4_info) user4_base_risk = UserRisk(user4_dto) # Build rules set rule = (AgeOverSixty() | AgeBetweenThirtyAndForty | AgeUnderThirty ) risk = rule.apply_rule(user4_dto, user4_base_risk) # User 4 should have the same base score assert risk.disability.risk == 2 assert risk.auto.risk == 2 assert risk.home.risk == 2 assert risk.life.risk == 2
def test_age_between_thirty_and_forty(): # AgeBetweenThirtyAndForty user3_info = { "age": 38, "dependents": 2, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user3_dto = UserInformationDTO(**user3_info) user3_base_risk = UserRisk(user3_dto) # Build rules set rule = (AgeOverSixty() | AgeBetweenThirtyAndForty | AgeUnderThirty ) risk = rule.apply_rule(user3_dto, user3_base_risk) # User 3 should 1 risk point reduced in all lines assert risk.disability.risk == 1 assert risk.auto.risk == 1 assert risk.home.risk == 1 assert risk.life.risk == 1
def test_motgaged_house(): # MortgagedHouse user_info = { "age": 62, "dependents": 2, "house": { "ownership_status": "mortgaged" }, "income": 1000, "marital_status": "single", "risk_questions": [0, 1, 1], } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = HasMotgagedHouse() | HasNoHouse risk = rule.apply_rule(user_dto, user_base_risk) # User should have 1 score point added to home and disability assert risk.disability.risk == 3 assert risk.auto.risk == 2 assert risk.home.risk == 3 assert risk.life.risk == 2
def test_new_vehicle(): # HasNewVehicle user_info = { "age": 62, "dependents": 0, "income": 220000, "marital_status": "single", "risk_questions": [0, 1, 1], "vehicle": { "year": 2018 } } user_dto = UserInformationDTO(**user_info) user_base_risk = UserRisk(user_dto) # Build rules set rule = HasNoVehicle() | HasNewVehicle risk = rule.apply_rule(user_dto, user_base_risk) # All risk lines should be reduced by 1 assert risk.disability.risk == 2 assert risk.auto.risk == 3 assert risk.home.risk == 2 assert risk.life.risk == 2