Skip to content

Commit

Permalink
Update and fix LSE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Jul 6, 2023
1 parent b2f105e commit 9c862fa
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 19 deletions.
6 changes: 3 additions & 3 deletions envergo/moulinette/regulations/loisurleau.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions envergo/moulinette/regulations/natura2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
10 changes: 5 additions & 5 deletions envergo/moulinette/regulations/sage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down Expand Up @@ -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"]
Expand Down
22 changes: 21 additions & 1 deletion envergo/moulinette/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
50 changes: 43 additions & 7 deletions envergo/moulinette/tests/test_loisurleau.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"


Expand All @@ -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"

0 comments on commit 9c862fa

Please sign in to comment.