Skip to content

Commit

Permalink
[#239] Fix case create without partij
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Jan 22, 2025
1 parent 8f46653 commit 14f0ae5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,14 @@ def update(self, instance, validated_data):

@transaction.atomic
def create(self, validated_data):
partij_uuid = str(validated_data.pop("partij").get("uuid"))
validated_data["partij"] = Partij.objects.get(uuid=partij_uuid)
partij = validated_data.pop("partij", None)
if not partij:
raise serializers.ValidationError(
{"identificeerde_partij": _("Dit veld is vereist.")},
code="required",
)

validated_data["partij"] = Partij.objects.get(uuid=str(partij.get("uuid")))
return super().create(validated_data)


Expand Down Expand Up @@ -721,12 +726,16 @@ def update(self, instance, validated_data):
if partij_identificatoren:
partij.partijidentificator_set.all().delete()
for partij_identificator in partij_identificatoren:
partij_identificator["partij"] = {"uuid": str(partij.uuid)}
partij_identificator["identificeerde_partij"] = {
"uuid": str(partij.uuid)
}
partij_identificator_serializer = PartijIdentificatorSerializer(
data=partij_identificator
)
partij_identificator_serializer.is_valid(raise_exception=True)
partij_identificator_serializer.create(partij_identificator)
partij_identificator_serializer.create(
partij_identificator_serializer.validated_data
)

if partij_identificatie:
serializer_class = self.discriminator.mapping[
Expand Down Expand Up @@ -828,12 +837,16 @@ def create(self, validated_data):

if partij_identificatoren:
for partij_identificator in partij_identificatoren:
partij_identificator["partij"] = {"uuid": str(partij.uuid)}
partij_identificator["identificeerde_partij"] = {
"uuid": str(partij.uuid)
}
partij_identificator_serializer = PartijIdentificatorSerializer(
data=partij_identificator
)
partij_identificator_serializer.is_valid(raise_exception=True)
partij_identificator_serializer.create(partij_identificator)
partij_identificator_serializer.create(
partij_identificator_serializer.validated_data
)

return partij

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,30 @@ def test_create_partij_indetificator(self):
},
)

def test_create_partij_indetificator_invalid_without_identificeerdePartij(self):
list_url = reverse("klantinteracties:partijidentificator-list")
data = {
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "bsn",
"objectId": "296648875",
"codeRegister": "brp",
},
}

response = self.client.post(list_url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["code"], "invalid")
self.assertEqual(response.data["title"], "Invalid input.")
self.assertEqual(
response.data["invalid_params"][0]["name"], "identificeerdePartij"
)
self.assertEqual(response.data["invalid_params"][0]["code"], "required")
self.assertEqual(
response.data["invalid_params"][0]["reason"], "Dit veld is vereist."
)

def test_update_partij_indetificator(self):
partij, partij2 = PartijFactory.create_batch(2)
partij_identificator = PartijIdentificatorFactory.create(
Expand Down

0 comments on commit 14f0ae5

Please sign in to comment.