forked from PnX-SI/gn_module_monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/edit categories module (PnX-SI#19)
* 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
Showing
4 changed files
with
44 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
18 changes: 14 additions & 4 deletions
18
backend/gn_module_monitoring/tests/test_monitoring/test_models/test_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters