diff --git a/envergo/moulinette/regulations/loisurleau.py b/envergo/moulinette/regulations/loisurleau.py index 3cfe86d1e..8159e5360 100644 --- a/envergo/moulinette/regulations/loisurleau.py +++ b/envergo/moulinette/regulations/loisurleau.py @@ -53,19 +53,19 @@ class ZoneHumide(CriterionEvaluator): def get_catalog_data(self): data = super().get_catalog_data() - if "wetlands_25" not in data: + if "wetlands_25" not in self.catalog: data["wetlands_25"] = [ zone for zone in self.catalog["wetlands"] if zone.distance <= D(m=25) ] data["wetlands_within_25m"] = bool(data["wetlands_25"]) - if "wetlands_100" not in data: + if "wetlands_100" not in self.catalog: data["wetlands_100"] = [ zone for zone in self.catalog["wetlands"] if zone.distance <= D(m=100) ] data["wetlands_within_100m"] = bool(data["wetlands_100"]) - if "potential_wetlands_0" not in data: + if "potential_wetlands_0" not in self.catalog: data["potential_wetlands_0"] = [ zone for zone in self.catalog["potential_wetlands"] diff --git a/envergo/moulinette/regulations/natura2000.py b/envergo/moulinette/regulations/natura2000.py index ddd27ffb0..731f7d851 100644 --- a/envergo/moulinette/regulations/natura2000.py +++ b/envergo/moulinette/regulations/natura2000.py @@ -53,19 +53,19 @@ class ZoneHumide44(CriterionEvaluator): def get_catalog_data(self): data = super().get_catalog_data() - if "wetlands_25" not in data: + if "wetlands_25" not in self.catalog: data["wetlands_25"] = [ zone for zone in self.catalog["wetlands"] if zone.distance <= D(m=25) ] data["wetlands_within_25m"] = bool(data["wetlands_25"]) - if "wetlands_100" not in data: + if "wetlands_100" not in self.catalog: data["wetlands_100"] = [ zone for zone in self.catalog["wetlands"] if zone.distance <= D(m=100) ] data["wetlands_within_100m"] = bool(data["wetlands_100"]) - if "potential_wetlands_0" not in data: + if "potential_wetlands_0" not in self.catalog: data["potential_wetlands_0"] = [ zone for zone in self.catalog["potential_wetlands"] diff --git a/envergo/moulinette/regulations/sage.py b/envergo/moulinette/regulations/sage.py index ee082a5d1..1ca33f15c 100644 --- a/envergo/moulinette/regulations/sage.py +++ b/envergo/moulinette/regulations/sage.py @@ -52,13 +52,13 @@ def get_catalog_data(self): data = {} wetlands = self.catalog["forbidden_wetlands"] - if "forbidden_wetlands_25" not in data: + if "forbidden_wetlands_25" not in self.catalog: data["forbidden_wetlands_25"] = [ zone for zone in wetlands if zone.distance <= D(m=25) ] data["forbidden_wetlands_within_25m"] = bool(data["forbidden_wetlands_25"]) - if "forbidden_wetlands_100" not in data: + if "forbidden_wetlands_100" not in self.catalog: data["forbidden_wetlands_100"] = [ zone for zone in wetlands if zone.distance <= D(m=100) ] @@ -184,19 +184,19 @@ class ZoneHumideGMRE56(CriterionEvaluator): def get_catalog_data(self): data = {} - if "wetlands_25" not in data: + if "wetlands_25" not in self.catalog: data["wetlands_25"] = [ zone for zone in self.catalog["wetlands"] if zone.distance <= D(m=25) ] data["wetlands_within_25m"] = bool(data["wetlands_25"]) - if "wetlands_100" not in data: + if "wetlands_100" not in self.catalog: data["wetlands_100"] = [ zone for zone in self.catalog["wetlands"] if zone.distance <= D(m=100) ] data["wetlands_within_100m"] = bool(data["wetlands_100"]) - if "potential_wetlands_0" not in data: + if "potential_wetlands_0" not in self.catalog: data["potential_wetlands_0"] = [ zone for zone in self.catalog["potential_wetlands"] diff --git a/envergo/moulinette/tests/factories.py b/envergo/moulinette/tests/factories.py index 22ddbb402..461cfb908 100644 --- a/envergo/moulinette/tests/factories.py +++ b/envergo/moulinette/tests/factories.py @@ -2,7 +2,7 @@ from factory.django import DjangoModelFactory from envergo.geodata.tests.factories import DepartmentFactory, MapFactory -from envergo.moulinette.models import MoulinetteConfig, Perimeter +from envergo.moulinette.models import Criterion, MoulinetteConfig, Perimeter, Regulation class PerimeterFactory(DjangoModelFactory): @@ -20,3 +20,23 @@ class Meta: department = factory.SubFactory(DepartmentFactory) is_activated = True + + +class RegulationFactory(DjangoModelFactory): + class Meta: + model = Regulation + + title = "Loi sur l'eau" + slug = "loi_sur_leau" + perimeter = factory.SubFactory(MapFactory) + + +class CriterionFactory(DjangoModelFactory): + class Meta: + model = Criterion + + title = "Zone humide" + slug = "zone_humide" + regulation = factory.SubFactory(RegulationFactory) + evaluator = "envergo.moulinette.regulations.loisurleau.ZoneHumide" + perimeter = factory.SubFactory(MapFactory) diff --git a/envergo/moulinette/tests/test_loisurleau.py b/envergo/moulinette/tests/test_loisurleau.py index 1677d5ff1..2a9095109 100644 --- a/envergo/moulinette/tests/test_loisurleau.py +++ b/envergo/moulinette/tests/test_loisurleau.py @@ -3,20 +3,40 @@ from envergo.geodata.conftest import france_map # noqa from envergo.geodata.tests.factories import ZoneFactory from envergo.moulinette.models import Moulinette -from envergo.moulinette.tests.factories import PerimeterFactory +from envergo.moulinette.tests.factories import CriterionFactory, RegulationFactory pytestmark = pytest.mark.django_db @pytest.fixture(autouse=True) def loisurleau_criterions(france_map): # noqa - classes = [ - "envergo.moulinette.regulations.loisurleau.ZoneHumide", - "envergo.moulinette.regulations.loisurleau.ZoneInondable", - "envergo.moulinette.regulations.loisurleau.Ruissellement", + regulation = RegulationFactory( + title="Loi sur l'eau", slug="loi_sur_leau", perimeter=france_map + ) + criteria = [ + CriterionFactory( + title="Zone humide", + slug="zone_humide", + regulation=regulation, + evaluator="envergo.moulinette.regulations.loisurleau.ZoneHumide", + perimeter=france_map, + ), + CriterionFactory( + title="Zone inondable", + slug="zone_inondable", + regulation=regulation, + evaluator="envergo.moulinette.regulations.loisurleau.ZoneInondable", + perimeter=france_map, + ), + CriterionFactory( + title="Ruissellement", + slug="ruissellement", + regulation=regulation, + evaluator="envergo.moulinette.regulations.loisurleau.Ruissellement", + perimeter=france_map, + ), ] - perimeters = [PerimeterFactory(map=france_map, criterion=path) for path in classes] - return perimeters + return criteria @pytest.fixture @@ -45,6 +65,7 @@ def test_3310_small_footprint_outside_wetlands(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = False + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "non_concerne" @@ -54,6 +75,7 @@ def test_3310_small_footprint_inside_wetlands(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "non_soumis" @@ -63,6 +85,7 @@ def test_3310_medium_footprint_inside_wetlands(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "action_requise" @@ -72,6 +95,7 @@ def test_3310_medium_footprint_inside_wetlands_2(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "action_requise" @@ -83,6 +107,7 @@ def test_3310_medium_footprint_close_to_wetlands(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = False moulinette.catalog["wetlands_within_100m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "non_soumis" @@ -95,6 +120,7 @@ def test_3310_medium_footprint_inside_potential_wetlands(moulinette_data): moulinette.catalog["wetlands_within_25m"] = False moulinette.catalog["wetlands_within_100m"] = False moulinette.catalog["potential_wetlands_within_0m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "non_soumis" @@ -103,6 +129,7 @@ def test_3310_medium_footprint_outside_wetlands(moulinette_data): """Project with 700 < footprint < 1000m² outside a wetland.""" moulinette = Moulinette(moulinette_data, moulinette_data) + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "non_concerne" @@ -112,6 +139,7 @@ def test_3310_large_footprint_within_wetlands(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "soumis" @@ -122,6 +150,7 @@ def test_3310_large_footprint_close_to_wetlands(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["wetlands_within_25m"] = False moulinette.catalog["wetlands_within_100m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "action_requise" @@ -133,6 +162,7 @@ def test_3310_large_footprint_inside_potential_wetland(moulinette_data): moulinette.catalog["wetlands_within_25m"] = False moulinette.catalog["wetlands_within_100m"] = False moulinette.catalog["potential_wetlands_within_0m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "action_requise" @@ -141,6 +171,7 @@ def test_3310_large_footprint_outside_wetlands(moulinette_data): """Project with footprint > 1000m² outside a wetland.""" moulinette = Moulinette(moulinette_data, moulinette_data) + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_humide.result == "non_concerne" @@ -151,6 +182,7 @@ def test_3220_small_footprint(moulinette_data): # Make sure the project in in a flood zone moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["flood_zones_within_12m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_inondable.result == "non_soumis" @@ -160,6 +192,7 @@ def test_3220_medium_footprint_within_flood_zones(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["flood_zones_within_12m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_inondable.result == "action_requise" @@ -169,6 +202,7 @@ def test_3220_medium_footprint_outside_flood_zones(moulinette_data): # Make sure the project in in a flood zone moulinette = Moulinette(moulinette_data, moulinette_data) + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_inondable.result == "non_concerne" @@ -178,6 +212,7 @@ def test_3220_large_footprint_within_flood_zones(moulinette_data): moulinette = Moulinette(moulinette_data, moulinette_data) moulinette.catalog["flood_zones_within_12m"] = True + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_inondable.result == "soumis" @@ -187,4 +222,5 @@ def test_3220_large_footprint_outside_flood_zones(moulinette_data): # Make sure the project in in a flood zone moulinette = Moulinette(moulinette_data, moulinette_data) + moulinette.evaluate() assert moulinette.loi_sur_leau.zone_inondable.result == "non_concerne"