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/site type categories and module categorie (PnX-SI#18)
* feat(api): add association table with alembic Add model in backend and alembic migration Reviewed-by: andriac [Refs ticket]: PnX-SI#3 * test: WIP add test to see new relationship Adding test to see if categories are showing up when we call module Reviewed-by: andriacap [Refs ticket]: PnX-SI#3 * feat: add type site - categorie relation WIP - add selectfield to get type site in admin module Reviewed-by: andriac [Refs ticket]: PnX-SI#3 * feat(api): Flask admin and routes categories Clean code for change label list and form selectfield for the BibCategorieView in Flask Admin Add utils routes to get all subtable relationship in order to get back the label type site Review-by: andriac [Refs ticket]: PnX-SI#3 * refactor: remove paginate_nested For depth in as_dict() * test: fix tests due to as_dict depth * style: applied black and isort * chore: remove unused import Co-authored-by: Andria Capai <[email protected]>
- Loading branch information
Showing
12 changed files
with
220 additions
and
17 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
backend/gn_module_monitoring/migrations/a54bafb13ce8_create_cor_module_category.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""create_cor_module_category | ||
Revision ID: a54bafb13ce8 | ||
Revises: | ||
Create Date: 2022-12-06 16:18:24.512562 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a54bafb13ce8" | ||
down_revision = "f24adb481f54" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
referent_schema = "gn_commons" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"cor_module_categorie", | ||
sa.Column( | ||
"id_categorie", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{monitorings_schema}.bib_categorie_site.id_categorie", | ||
name="fk_cor_module_categorie_id_categorie", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=False, | ||
), | ||
sa.Column("id_module", sa.Integer(),sa.ForeignKey( | ||
f"{referent_schema}.t_modules.id_module", | ||
name="fk_cor_module_categorie_id_module", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), nullable=False), | ||
sa.PrimaryKeyConstraint("id_categorie", "id_module", name="pk_cor_module_categorie"), | ||
schema=monitorings_schema, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("cor_module_categorie", schema=monitorings_schema) |
47 changes: 47 additions & 0 deletions
47
backend/gn_module_monitoring/migrations/e64bafb13ce8_create_cor_site_type_category.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""create_cor_site_type_category | ||
Revision ID: e64bafb13ce8 | ||
Revises: | ||
Create Date: 2022-12-06 16:18:24.512562 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e64bafb13ce8" | ||
down_revision = "a54bafb13ce8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
referent_schema = "ref_nomenclatures" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"cor_site_type_categorie", | ||
sa.Column( | ||
"id_categorie", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{monitorings_schema}.bib_categorie_site.id_categorie", | ||
name="fk_cor_site_type_categorie_id_categorie", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=False, | ||
), | ||
sa.Column("id_nomenclature", sa.Integer(),sa.ForeignKey( | ||
f"{referent_schema}.t_nomenclatures.id_nomenclature", | ||
name="fk_cor_site_type_categorie_id_type", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), nullable=False), | ||
sa.PrimaryKeyConstraint("id_categorie", "id_nomenclature", name="pk_cor_site_type_categorie"), | ||
schema=monitorings_schema, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("cor_site_type_categorie", schema=monitorings_schema) |
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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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() | ||
|
||
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) | ||
|
||
return monitoring |
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
Empty file.
11 changes: 11 additions & 0 deletions
11
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
|
||
from gn_module_monitoring.tests.fixtures.module import monitoring_module | ||
from gn_module_monitoring.tests.fixtures.site import categories | ||
|
||
|
||
@pytest.mark.usefixtures("temporary_transaction") | ||
class TestModule: | ||
def test_module(self, monitoring_module): | ||
cateogories = monitoring_module.categories | ||
assert False |
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