diff --git a/backend/gn_module_monitoring/routes/data_utils.py b/backend/gn_module_monitoring/routes/data_utils.py index 615796b11..9a8511684 100644 --- a/backend/gn_module_monitoring/routes/data_utils.py +++ b/backend/gn_module_monitoring/routes/data_utils.py @@ -30,8 +30,7 @@ from ..blueprint import blueprint from ..config.repositories import get_config - -from ..monitoring.models import TMonitoringSitesGroups, TMonitoringSites +from gn_module_monitoring.monitoring.models import TMonitoringSitesGroups, TMonitoringSites, BibCategorieSite model_dict = { 'habitat': Habref, @@ -39,6 +38,7 @@ 'user': User, 'taxonomy': Taxref, 'dataset': TDatasets, + "categorie": BibCategorieSite, 'observer_list': UserList, 'taxonomy_list': BibListes, 'sites_group': TMonitoringSitesGroups, diff --git a/backend/gn_module_monitoring/tests/fixtures/module.py b/backend/gn_module_monitoring/tests/fixtures/module.py index 6e0a5b1ac..41d946e37 100644 --- a/backend/gn_module_monitoring/tests/fixtures/module.py +++ b/backend/gn_module_monitoring/tests/fixtures/module.py @@ -1,5 +1,6 @@ +from uuid import uuid4 + import pytest -from geonature.core.gn_commons.models.base import TModules from geonature.utils.env import db from gn_module_monitoring.monitoring.models import TMonitoringModules @@ -7,15 +8,17 @@ @pytest.fixture -def monitoring_module(module, categories): - id_module = TModules.query.filter(TModules.id_module == module.id_module).one().id_module - t_monitoring_module = TMonitoringModules() +def monitoring_module(categories): + t_monitoring_module = TMonitoringModules( + module_code=uuid4(), + module_label="test", + active_frontend=True, + active_backend=False, + module_path="test", + categories=list(categories.values()), + ) - module_data = {"id_module": id_module, "categories": list(categories.values())} - t_monitoring_module.from_dict(module_data) - # monitoring = TMonitoringModules(id_module=id_module, categories=list(categories.values())) - monitoring = t_monitoring_module with db.session.begin_nested(): - db.session.add(monitoring) + db.session.add(t_monitoring_module) - return monitoring + return t_monitoring_module diff --git a/backend/gn_module_monitoring/tests/test_monitoring/test_models/test_module.py b/backend/gn_module_monitoring/tests/test_monitoring/test_models/test_module.py index e156a1614..60cca2e98 100644 --- a/backend/gn_module_monitoring/tests/test_monitoring/test_models/test_module.py +++ b/backend/gn_module_monitoring/tests/test_monitoring/test_models/test_module.py @@ -1,11 +1,21 @@ import pytest +from geonature.utils.env import db +from gn_module_monitoring.monitoring.models import TMonitoringModules from gn_module_monitoring.tests.fixtures.module import monitoring_module -from gn_module_monitoring.tests.fixtures.site import categories +from gn_module_monitoring.tests.fixtures.site import categories, site_type @pytest.mark.usefixtures("temporary_transaction") class TestModule: - def test_module(self, monitoring_module): - cateogories = monitoring_module.categories - assert False + def test_module(self, monitoring_module, categories): + cats = monitoring_module.categories + assert cats == list(categories.values()) + + def test_remove_categorie_from_module(self, monitoring_module, categories): + with db.session.begin_nested(): + monitoring_module.categories.pop(0) + + mon = TMonitoringModules.query.filter_by(id_module=monitoring_module.id_module).one() + + assert len(mon.categories) == len(categories) - 1 diff --git a/config/monitoring/generic/module.json b/config/monitoring/generic/module.json index 46af0de80..e2e794e7f 100644 --- a/config/monitoring/generic/module.json +++ b/config/monitoring/generic/module.json @@ -129,6 +129,21 @@ "attribut_label": "Afficher dans le menu ?", "definition": "Afficher le module dans le menu de GéoNature. (Recharger la page pour voir les modifications)." }, + + "categories": { + "type_widget": "datalist", + "attribut_label": "Liste des catégories", + "type_util": "categorie", + "keyValue": "id_categorie", + "keyLabel": "label", + "multiple": true, + "api" : "__MONITORINGS_PATH/sites/categories", + "application": "GeoNature", + "required": true, + "data_path": "categories", + "definition": "Permet de paramétrer la compatibilité de ce module avec les catégories de sites" + }, + "medias": { "type_widget": "medias", "attribut_label": "Médias",