Ejemplo n.º 1
0
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())
Ejemplo n.º 2
0
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 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())