Skip to content

Commit

Permalink
Feat/edit categories module (#19)
Browse files Browse the repository at this point in the history
* tests: make tests and fixtures work for modules

By changing the way a monitoring module is created in the fixture
Add two tests to check the relationship

* feat(api): add categories in edit module

* style: applied black
  • Loading branch information
mvergez authored and amandine-sahl committed Oct 5, 2023
1 parent f2b0f3f commit b55b380
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
15 changes: 15 additions & 0 deletions backend/gn_module_monitoring/config/generic/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@
"attribut_label": "Afficher dans le menu ?",
"definition": "Afficher le module dans le menu de GeoNature. (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",
Expand Down
4 changes: 2 additions & 2 deletions backend/gn_module_monitoring/routes/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
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,
"nomenclature": TNomenclatures,
"user": User,
"taxonomy": Taxref,
"dataset": TDatasets,
"categorie": BibCategorieSite,
"observer_list": UserList,
"taxonomy_list": BibListes,
"sites_group": TMonitoringSitesGroups,
Expand Down
23 changes: 13 additions & 10 deletions backend/gn_module_monitoring/tests/fixtures/module.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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
from gn_module_monitoring.tests.fixtures.site import categories


@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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b55b380

Please sign in to comment.