Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additionnal fields are no longer mandatory at marshmallow validation … #2945

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions backend/geonature/tests/test_pr_occtax.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def releve_data(client: Any, datasets: dict[Any, TDatasets]):
"observers": [1],
"observers_txt": "tatatato",
"id_nomenclature_grp_typ": id_nomenclature_grp_typ,
"additional_fields": {"releve_addi_field": "Releve"},
},
}

Expand Down Expand Up @@ -154,7 +155,7 @@ def occurrence_data(client: Any, releve_occtax: Any):
"digital_proof": None,
"non_digital_proof": None,
"comment": "blah",
"additional_fields": {},
"additional_fields": {"occurrence_addi_field": "occ"},
"cor_counting_occtax": [
{
"id_nomenclature_life_stage": dict_nomenclatures["STADE_VIE"],
Expand All @@ -166,7 +167,6 @@ def occurrence_data(client: Any, releve_occtax: Any):
"count_min": 2,
"count_max": 2,
"medias": [],
"additional_fields": {},
},
{
"id_nomenclature_life_stage": dict_nomenclatures["STADE_VIE"],
Expand All @@ -178,7 +178,6 @@ def occurrence_data(client: Any, releve_occtax: Any):
"count_min": 1,
"count_max": 1,
"medias": [],
"additional_fields": {},
},
],
}
Expand Down Expand Up @@ -407,15 +406,26 @@ def test_post_occurrence(self, users: dict, occurrence_data: dict[str, Any]):
assert response.status_code == 200
json_resp = response.json
assert len(json_resp["cor_counting_occtax"]) == 2

occurrence_data["additional_fields"] = None
response = self.client.post(
url_for("pr_occtax.createOccurrence", id_releve=occurrence_data["id_releve_occtax"]),
json=occurrence_data,
# Test trigger to synthese
occurrence = (
db.session.execute(
select(TOccurrencesOccurrence).filter_by(
id_occurrence_occtax=json_resp["id_occurrence_occtax"]
)
)
.unique()
.scalar_one()
)
assert response.status_code == BadRequest.code

# TODO : test dans la synthese qu'il y a bien 2 ligne pour l'UUID couting
synthese_data = db.session.scalars(
select(Synthese).filter_by(unique_id_sinp_grp=occurrence.releve.unique_id_sinp_grp)
).all()
assert len(synthese_data) >= 2
synthese_reccord = synthese_data[0]
# test additionnal field concatenation
assert synthese_reccord.additional_data == {
"occurrence_addi_field": "occ",
"releve_addi_field": "Releve",
}

def test_update_occurrence(self, users: dict, occurrence: Any):
set_logged_user(self.client, users["user"])
Expand Down
13 changes: 0 additions & 13 deletions contrib/occtax/backend/occtax/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
from pypn_habref_api.schemas import HabrefSchema


@post_dump
def remove_additional_none_val(self, data, **kwargs):
if "additional_fields" in data and data["additional_fields"] is None:
data["additional_fields"] = {}
return data


class GeojsonSerializationField(fields.Field):
def _serialize(self, value, attr, obj):
if value is None:
Expand Down Expand Up @@ -79,7 +72,6 @@ class Meta:
load_instance = True

medias = MA.Nested(MediaSchema, many=True)
pre_dump_fn = remove_additional_none_val

@pre_load
def make_counting(self, data, **kwargs):
Expand All @@ -94,11 +86,8 @@ class Meta:
load_instance = True
include_fk = True

additional_fields = fields.Raw(allow_none=False, required=True)
# additional_fields = fields.Raw(load_only=True)
cor_counting_occtax = MA.Nested(CountingSchema, many=True)
taxref = MA.Nested(TaxrefSchema, dump_only=True)
pre_dump_fn = remove_additional_none_val


class ReleveSchema(MA.SQLAlchemyAutoSchema):
Expand Down Expand Up @@ -136,8 +125,6 @@ def make_releve(self, data, **kwargs):
data.pop("id_digitiser", None) # id_digitiser is dump_only
return data

pre_dump_fn = remove_additional_none_val


class GeojsonReleveSchema(MA.Schema):
# class Meta:
Expand Down
Loading