from backend.Property import Property
from recommendations.VentilationRecommendations import VentilationRecommendations
from recommendations.tests.test_data.materials import materials
from etl.epc.Record import EPCRecord


class TestVentilationRecommendations:

    def test_natural_ventilation(self):
        epc_record = EPCRecord()
        epc_record.prepared_epc = {"mechanical-ventilation": "natural"}
        input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)

        recommender = VentilationRecommendations(
            property_instance=input_property1,
            materials=materials
        )

        assert not recommender.recommendation

        recommender.recommend()

        assert len(recommender.recommendation) == 1

        assert recommender.recommendation[0]["total"] == 1000
        assert recommender.recommendation[0]["type"] == "mechanical_ventilation"
        assert len(recommender.recommendation[0]["parts"]) == 1
        assert recommender.recommendation[0]["parts"][0]["description"] == 'Mechanical Extract Ventilation'
        assert recommender.recommendation[0]["parts"][0]["quantity"] == 2

    def test_missing_ventilation(self):
        epc_record = EPCRecord()
        epc_record.prepared_epc = {"mechanical-ventilation": None}
        input_property2 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)

        recommender2 = VentilationRecommendations(
            property_instance=input_property2,
            materials=materials
        )

        assert not recommender2.recommendation

        recommender2.recommend()

        assert len(recommender2.recommendation) == 1

        assert recommender2.recommendation[0]["total"] == 1000
        assert recommender2.recommendation[0]["type"] == "mechanical_ventilation"
        assert len(recommender2.recommendation[0]["parts"]) == 1
        assert recommender2.recommendation[0]["parts"][0]["description"] == 'Mechanical Extract Ventilation'
        assert recommender2.recommendation[0]["parts"][0]["quantity"] == 2

    def test_nodata_ventilation(self):
        epc_record = EPCRecord()
        epc_record.prepared_epc = {"mechanical-ventilation": "NO DATA!!"}
        input_property3 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)

        recommender3 = VentilationRecommendations(
            property_instance=input_property3,
            materials=materials
        )

        assert not recommender3.recommendation

        recommender3.recommend()

        assert len(recommender3.recommendation) == 1

        assert recommender3.recommendation[0]["total"] == 1000
        assert recommender3.recommendation[0]["type"] == "mechanical_ventilation"
        assert len(recommender3.recommendation[0]["parts"]) == 1
        assert recommender3.recommendation[0]["parts"][0]["description"] == 'Mechanical Extract Ventilation'
        assert recommender3.recommendation[0]["parts"][0]["quantity"] == 2

    def test_existing_ventilation_1(self):
        epc_record = EPCRecord()
        epc_record.prepared_epc = {"mechanical-ventilation": "mechanical, extract only"}
        input_property4 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)

        recommender4 = VentilationRecommendations(
            property_instance=input_property4,
            materials=materials
        )

        assert not recommender4.recommendation

        recommender4.recommend()

        assert not recommender4.recommendation
        assert recommender4.has_ventilaion

    def test_existing_ventilation_2(self):
        epc_record = EPCRecord()
        epc_record.prepared_epc = {"mechanical-ventilation": "mechanical, supply and extract"}
        input_property5 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)

        recommender5 = VentilationRecommendations(
            property_instance=input_property5,
            materials=materials
        )

        assert not recommender5.recommendation

        recommender5.recommend()

        assert not recommender5.recommendation
        assert recommender5.has_ventilaion
