Skip to content

Commit

Permalink
Additionnal fields are no longer mandatory at marshmallow validation …
Browse files Browse the repository at this point in the history
…level - #2937
  • Loading branch information
TheoLechemia committed Mar 5, 2024
1 parent 3ddf17c commit dd18e40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
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
12 changes: 0 additions & 12 deletions contrib/occtax/backend/occtax/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +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):
Expand Down Expand Up @@ -79,7 +73,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 +87,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 +126,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

0 comments on commit dd18e40

Please sign in to comment.