Skip to content

Commit

Permalink
set not null on synthese.id_source
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Dec 5, 2022
1 parent 536e2f2 commit 7f7134b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions backend/geonature/core/gn_synthese/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Synthese(DB.Model):
id_synthese = DB.Column(DB.Integer, primary_key=True)
unique_id_sinp = DB.Column(UUID(as_uuid=True))
unique_id_sinp_grp = DB.Column(UUID(as_uuid=True))
id_source = DB.Column(DB.Integer, ForeignKey(TSources.id_source))
id_source = DB.Column(DB.Integer, ForeignKey(TSources.id_source), nullable=False)
source = relationship(TSources)
id_module = DB.Column(DB.Integer, ForeignKey(TModules.id_module))
module = DB.relationship(TModules)
Expand Down Expand Up @@ -396,7 +396,7 @@ class VSyntheseForWebApp(DB.Model):
)
unique_id_sinp = DB.Column(UUID(as_uuid=True))
unique_id_sinp_grp = DB.Column(UUID(as_uuid=True))
id_source = DB.Column(DB.Integer)
id_source = DB.Column(DB.Integer, nullable=False)
entity_source_pk_value = DB.Column(DB.Integer)
id_dataset = DB.Column(DB.Integer)
dataset_name = DB.Column(DB.Integer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""set not-null on synthese.id_source
Revision ID: 4cf3fd5d06f5
Revises: 36d0bd313a47
Create Date: 2022-12-05 14:46:04.206294
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "4cf3fd5d06f5"
down_revision = "36d0bd313a47"
branch_labels = None
depends_on = None


def upgrade():
op.alter_column(
table_name="synthese",
column_name="id_source",
nullable=False,
schema="gn_synthese",
)


def downgrade():
op.alter_column(
table_name="synthese",
column_name="id_source",
nullable=True,
schema="gn_synthese",
)
9 changes: 8 additions & 1 deletion backend/geonature/tests/test_gn_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


def create_synthese_record(
source,
cd_nom=None,
date_min=datetime.now(),
date_max=datetime.now(),
Expand All @@ -51,6 +52,7 @@ def create_synthese_record(
geom_4326 = WKTElement(f"POINT({str(x)} {str(y)})", srid=4326)

return Synthese(
source=source,
cd_nom=cd_nom,
date_min=date_min,
date_max=date_max,
Expand Down Expand Up @@ -80,9 +82,12 @@ def cd_nom_for_profiles():


@pytest.fixture(scope="function")
def sample_synthese_records_for_profile(datasets, valid_status_for_profiles, cd_nom_for_profiles):
def sample_synthese_records_for_profile(
datasets, source, valid_status_for_profiles, cd_nom_for_profiles
):
# set a profile for taxon
synthese_record_for_profile = create_synthese_record(
source=source,
cd_nom=cd_nom_for_profiles,
x=6.12,
y=44.85,
Expand Down Expand Up @@ -114,10 +119,12 @@ def sample_synthese_records_for_profile(datasets, valid_status_for_profiles, cd_
@pytest.fixture(scope="function")
def wrong_sample_synthese_records_for_profile(
datasets,
source,
cd_nom_for_profiles,
):
# This obs will be not used for computing profiles as it has no dates
wrong_new_obs = create_synthese_record(
source=source,
cd_nom=cd_nom_for_profiles,
x=20.12,
y=55.85,
Expand Down
4 changes: 3 additions & 1 deletion backend/geonature/tests/test_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CorSensitivityCriteria,
)
from geonature.core.gn_synthese.models import Synthese
from geonature.tests.fixtures import source

from ref_geo.models import LAreas, BibAreasTypes
from apptax.taxonomie.models import Taxref
Expand Down Expand Up @@ -296,7 +297,7 @@ def test_get_id_nomenclature_sensitivity(self, app):
assert db.session.execute(query).scalar() == not_sensitive.mnemonique
transaction.rollback()

def test_synthese_sensitivity(self, app):
def test_synthese_sensitivity(self, app, source):
taxon = Taxref.query.first()
sensitivity_nomenc_type = BibNomenclaturesTypes.query.filter_by(
mnemonique="SENSIBILITE"
Expand All @@ -322,6 +323,7 @@ def test_synthese_sensitivity(self, app):
date_obs = datetime.now()
with db.session.begin_nested():
s = Synthese(
source=source,
cd_nom=taxon.cd_nom,
nom_cite="Sensitive taxon",
date_min=date_obs,
Expand Down

0 comments on commit 7f7134b

Please sign in to comment.