class TestUnderThirtyYearsOld(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = UnderThirtyYearsOld() def test_product_score_is_deduct_in_2_when_person_is_under_thirty_years_old(self): person = self.person_builder.with_age(29).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual(-2, risk_analysis.get_products_in_risk_analysis()[DISABILITY_PRODUCT].get_score()) self.assertEqual(-2, risk_analysis.get_products_in_risk_analysis()[HOME_PRODUCT].get_score()) self.assertEqual(-2, risk_analysis.get_products_in_risk_analysis()[LIFE_PRODUCT].get_score()) self.assertEqual(-2, risk_analysis.get_products_in_risk_analysis()[VEHICLE_PRODUCT].get_score()) def test_product_score_is_not_deduct_in_2_when_person_is_over_thirty_years_old(self): person = self.person_builder.with_age(30).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[DISABILITY_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[HOME_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[LIFE_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[VEHICLE_PRODUCT].get_score())
class TestHasDependents(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = HasDependents() def test_product_score_is_add_in_1_when_person_has_dependents(self): person = self.person_builder.with_dependents(1).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual(+1, risk_analysis.get_products_in_risk_analysis()[DISABILITY_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[HOME_PRODUCT].get_score()) self.assertEqual(+1, risk_analysis.get_products_in_risk_analysis()[LIFE_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[VEHICLE_PRODUCT].get_score()) def test_product_score_is_not_add_in_1_when_person_has_not_dependents(self): person = self.person_builder.with_dependents(0).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[DISABILITY_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[HOME_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[LIFE_PRODUCT].get_score()) self.assertEqual(0, risk_analysis.get_products_in_risk_analysis()[VEHICLE_PRODUCT].get_score())
def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = IsHouseMortgaged()
def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = IsOverSixtyYearsOld()
def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = HasIncomeAboveTwoHundred()
def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = HasDependents()
def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = VehicleProducedLastFiveYears()
def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.person_builder.person.assets = [] self.rule = HasHouse()
class TestIsHouseMortgaged(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = IsHouseMortgaged() def test_product_score_is_add_in_1_when_house_is_mortgaged(self): house = House(ownership_status=OWNERSHIP_STATUS_MORTGAGED) person = self.person_builder.with_asset(asset=house).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( +1, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( +1, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score()) def test_product_score_remains_in_0_when_house_is_not_mortgaged(self): house = House(ownership_status=OWNERSHIP_STATUS_OWNED) self.person_builder.person.assets = [] person = self.person_builder.with_asset(asset=house).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score())
class TestIsOverSixtyYearsOld(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = IsOverSixtyYearsOld() def test_product_score_is_ineligible_when_person_is_over_sixty_years_old( self): person = self.person_builder.with_age(61).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_INELIGIBLE, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_INELIGIBLE, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_status()) def test_product_score_is_default_when_person_is_under_sixty_years_old( self): person = self.person_builder.with_age(60).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_status())
class TestHasHouse(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.person_builder.person.assets = [] self.rule = HasHouse() def test_home_product_status_is_ineligible_when_person_has_no_house(self): person = self.person_builder.build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( PRODUCT_SCORE_INELIGIBLE, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_status()) def test_home_product_status_is_default_when_person_has_house(self): house = House(ownership_status=OWNERSHIP_STATUS_OWNED) person = self.person_builder.with_asset(asset=house).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_status()) self.assertEqual( PRODUCT_SCORE_ECONOMIC, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_status())
class TestUnderThirtyYearsOld(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = BetweenThirtyAndFortyYearsOld() def test_is_truly_when_person_is_between_thirty_and_forty_years_old(self): person = self.person_builder.with_age(40).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score()) def test_is_falsely_when_person_is_not_between_thirty_and_forty_years_old( self): she = self.person_builder.with_age(29).build() risk_analysis_she = RiskAnalysis(person=she, risk_profile=self.risk_profile, rules_list=None) he = self.person_builder.with_age(41).build() risk_analysis_he = RiskAnalysis(person=he, risk_profile=self.risk_profile, rules_list=None) risk_analysis_she = self.rule.execute(risk_analysis=risk_analysis_she) risk_analysis_he = self.rule.execute(risk_analysis=risk_analysis_he) self.assertEqual( 0, risk_analysis_she.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_she.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_she.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_she.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_he.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_he.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_he.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis_he.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score())
class TestIsMarried(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = IsMarried() def test_product_score_is_add_in_1_and_deduct_in_1_when_person_is_married( self): person = self.person_builder.with_marital_status( MARITAL_STATUS_MARRIED).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( +1, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score()) def test_product_score_is_not_add_in_1_and_not_deduct_in_1_when_person_is_single( self): person = self.person_builder.with_marital_status( MARITAL_STATUS_SINGLE).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score())
class TestHasIncomeAboveTwoHundred(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = HasIncomeAboveTwoHundred() def test_product_score_is_deduct_in_1_when_person_has_income_above_two_hundred( self): person = self.person_builder.with_income(201.00).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( -1, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score()) def test_product_score_is_not_deduct_in_1_when_person_has_income_bellow_two_hundred( self): person = self.person_builder.with_income(200.00).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score())
class TestVehicleProducedLastFiveYears(TestCase): def setUp(self): risk_profile_builder = RiskProfileBuilder() self.risk_profile = risk_profile_builder \ .with_disability_product() \ .with_home_product() \ .with_life_product() \ .with_vehicle_product() \ .build() self.person_builder = PersonBuilder() self.rule = VehicleProducedLastFiveYears() @freeze_time("2020-01-01") def test_product_score_is_add_in_1_when_vehicle_was_produced_last_5_years( self): vehicle = Vehicle(year_manufactured=2015) person = self.person_builder.with_asset(asset=vehicle).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( +1, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) @freeze_time("2020") def test_product_score_is_not_add_in_1_when_vehicle_was_produced_last_5_years( self): vehicle = Vehicle(year_manufactured=2013) self.person_builder.person.assets = [] person = self.person_builder.with_asset(asset=vehicle).build() risk_analysis = RiskAnalysis(person=person, risk_profile=self.risk_profile, rules_list=None) risk_analysis = self.rule.execute(risk_analysis=risk_analysis) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [DISABILITY_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [HOME_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [LIFE_PRODUCT].get_score()) self.assertEqual( 0, risk_analysis.get_products_in_risk_analysis() [VEHICLE_PRODUCT].get_score())