Skip to content

Commit

Permalink
Update and fix n2000 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Jul 6, 2023
1 parent 9c862fa commit f839557
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
19 changes: 12 additions & 7 deletions envergo/moulinette/regulations/natura2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,18 @@ class IOTA(CriterionEvaluator):
CODES = ["soumis", "non_soumis", "a_verifier"]

def evaluate(self):
iota = self.moulinette.loi_sur_leau.result
if iota in (RESULTS.soumis, RESULTS.interdit):
result = RESULTS.soumis
elif iota == RESULTS.non_soumis:
result = RESULTS.non_soumis
else:
result = RESULTS.a_verifier
try:
iota = self.moulinette.loi_sur_leau.result
if iota in (RESULTS.soumis, RESULTS.interdit):
result = RESULTS.soumis
elif iota == RESULTS.non_soumis:
result = RESULTS.non_soumis
else:
result = RESULTS.a_verifier
except AttributeError:
# If there is no Loi sur l'eau regulation
# for example, during unit tests
result = RESULTS.non_disponible

self._result_code, self._result = result, result

Expand Down
11 changes: 1 addition & 10 deletions envergo/moulinette/tests/test_loisurleau.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import pytest

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 CriterionFactory, RegulationFactory

pytestmark = pytest.mark.django_db


@pytest.fixture(autouse=True)
def loisurleau_criterions(france_map): # noqa
def loisurleau_criteria(france_map): # noqa
regulation = RegulationFactory(
title="Loi sur l'eau", slug="loi_sur_leau", perimeter=france_map
)
Expand Down Expand Up @@ -51,14 +50,6 @@ def moulinette_data(footprint):
}


def no_zones(_coords):
return []


def create_zones():
return [ZoneFactory()]


@pytest.mark.parametrize("footprint", [50])
def test_3310_small_footprint_outside_wetlands(moulinette_data):
"""Project with footprint < 700m² are not subject to the 3310."""
Expand Down
55 changes: 37 additions & 18 deletions envergo/moulinette/tests/test_natura2000.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
import pytest

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.natura2000.ZoneHumide44",
"envergo.moulinette.regulations.natura2000.ZoneInondable44",
"envergo.moulinette.regulations.natura2000.Lotissement44",
def n2000_criteria(france_map): # noqa
regulation = RegulationFactory(
title="Natura 2000", slug="natura2000", perimeter=france_map
)
criteria = [
CriterionFactory(
title="Zone humide 44",
slug="zone_humide_44",
regulation=regulation,
evaluator="envergo.moulinette.regulations.natura2000.ZoneHumide44",
perimeter=france_map,
),
CriterionFactory(
title="Zone inondable 44",
slug="zone_inondable_44",
regulation=regulation,
evaluator="envergo.moulinette.regulations.natura2000.ZoneInondable44",
perimeter=france_map,
),
CriterionFactory(
title="IOTA",
slug="iota",
regulation=regulation,
evaluator="envergo.moulinette.regulations.natura2000.IOTA",
perimeter=france_map,
),
]
perimeters = [PerimeterFactory(map=france_map, criterion=path) for path in classes]
return perimeters
return criteria


@pytest.fixture
Expand All @@ -32,20 +50,13 @@ def moulinette_data(footprint):
}


def no_zones(_coords):
return []


def create_zones():
return [ZoneFactory()]


@pytest.mark.parametrize("footprint", [50])
def test_zh_small_footprint_outside_wetlands(moulinette_data):
"""Project with footprint < 100m² are not subject to the 3310."""

moulinette = Moulinette(moulinette_data, moulinette_data)
moulinette.catalog["wetlands_within_25m"] = False
moulinette.evaluate()
assert moulinette.natura2000.zone_humide_44.result == "non_concerne"


Expand All @@ -55,6 +66,7 @@ def test_zh_small_footprint_inside_wetlands(moulinette_data):

moulinette = Moulinette(moulinette_data, moulinette_data)
moulinette.catalog["wetlands_within_25m"] = True
moulinette.evaluate()
assert moulinette.natura2000.zone_humide_44.result == "non_soumis"


Expand All @@ -64,6 +76,7 @@ def test_zh_large_footprint_within_wetlands(moulinette_data):

moulinette = Moulinette(moulinette_data, moulinette_data)
moulinette.catalog["wetlands_within_25m"] = True
moulinette.evaluate()
assert moulinette.natura2000.zone_humide_44.result == "soumis"


Expand All @@ -74,6 +87,7 @@ def test_zh_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.natura2000.zone_humide_44.result == "action_requise"


Expand All @@ -85,6 +99,7 @@ def test_zh_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.natura2000.zone_humide_44.result == "action_requise"


Expand All @@ -93,6 +108,7 @@ def test_zh_large_footprint_outside_wetlands(moulinette_data):
"""Project with footprint > 100m² outside a wetland."""

moulinette = Moulinette(moulinette_data, moulinette_data)
moulinette.evaluate()
assert moulinette.natura2000.zone_humide_44.result == "non_concerne"


Expand All @@ -103,6 +119,7 @@ def test_zi_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.natura2000.zone_inondable_44.result == "non_soumis"


Expand All @@ -112,6 +129,7 @@ def test_zi_medium_footprint_within_flood_zones(moulinette_data):

moulinette = Moulinette(moulinette_data, moulinette_data)
moulinette.catalog["flood_zones_within_12m"] = True
moulinette.evaluate()
assert moulinette.natura2000.zone_inondable_44.result == "soumis"


Expand All @@ -121,4 +139,5 @@ def test_zi_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.natura2000.zone_inondable_44.result == "non_concerne"

0 comments on commit f839557

Please sign in to comment.