Skip to content

Commit 8d4b20f

Browse files
[#239] Fix updatePartij and create tests
1 parent 91edb96 commit 8d4b20f

File tree

2 files changed

+168
-60
lines changed

2 files changed

+168
-60
lines changed

src/openklant/components/klantinteracties/api/serializers/partijen.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,14 @@ def update(self, instance, validated_data):
751751
data=partij_identificator
752752
)
753753
partij_identificator_serializer.is_valid(raise_exception=True)
754-
partij_identificator_serializer.create(
755-
partij_identificator_serializer.validated_data
756-
)
754+
if "uuid" in partij_identificator:
755+
PartijIdentificator.objects.filter(
756+
uuid=partij_identificator["uuid"]
757+
).update(partij=partij)
758+
else:
759+
partij_identificator_serializer.create(
760+
partij_identificator_serializer.validated_data
761+
)
757762

758763
if partij_identificatie:
759764
serializer_class = self.discriminator.mapping[

src/openklant/components/klantinteracties/api/tests/test_partijen.py

+160-57
Original file line numberDiff line numberDiff line change
@@ -1048,38 +1048,166 @@ def test_update_partij(self):
10481048
},
10491049
)
10501050

1051-
def test_update_partij_partijidentificator_empty_list(self):
1052-
partij = PartijFactory.create(
1053-
nummer="1298329191",
1054-
interne_notitie="interneNotitie",
1055-
voorkeurs_digitaal_adres=None,
1056-
voorkeurs_rekeningnummer=None,
1057-
soort_partij="persoon",
1058-
indicatie_geheimhouding=True,
1059-
voorkeurstaal="ndl",
1060-
indicatie_actief=True,
1061-
bezoekadres_nummeraanduiding_id="095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
1062-
bezoekadres_adresregel1="adres1",
1063-
bezoekadres_adresregel2="adres2",
1064-
bezoekadres_adresregel3="adres3",
1065-
bezoekadres_land="6030",
1066-
correspondentieadres_nummeraanduiding_id="095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
1067-
correspondentieadres_adresregel1="adres1",
1068-
correspondentieadres_adresregel2="adres2",
1069-
correspondentieadres_adresregel3="adres3",
1070-
correspondentieadres_land="6030",
1051+
def test_update_partij_partijidentificator(self):
1052+
partij = PartijFactory.create()
1053+
digitaal_adres2 = DigitaalAdresFactory.create()
1054+
partij_identificator = PartijIdentificatorFactory.create(
1055+
partij_identificator_code_objecttype="natuurlijk_persoon",
1056+
partij_identificator_code_soort_object_id="bsn",
1057+
partij_identificator_object_id="296648875",
1058+
partij_identificator_code_register="brp",
10711059
)
1072-
PersoonFactory.create(
1073-
partij=partij,
1074-
contactnaam_voorletters="P",
1075-
contactnaam_voornaam="Phil",
1076-
contactnaam_voorvoegsel_achternaam="",
1077-
contactnaam_achternaam="Bozeman",
1060+
detail_url = reverse(
1061+
"klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)}
10781062
)
1063+
response = self.client.get(detail_url)
1064+
data = response.json()
1065+
self.assertEqual(partij.partijidentificator_set.all().count(), 0)
10791066

1067+
data = {
1068+
"digitaleAdressen": [{"uuid": str(digitaal_adres2.uuid)}],
1069+
"voorkeursDigitaalAdres": {"uuid": str(digitaal_adres2.uuid)},
1070+
"rekeningnummers": [],
1071+
"voorkeursRekeningnummer": None,
1072+
"soortPartij": "persoon",
1073+
"indicatieActief": True,
1074+
"partijIdentificatoren": [
1075+
{
1076+
"uuid": str(partij_identificator.uuid),
1077+
},
1078+
],
1079+
}
1080+
1081+
response = self.client.put(detail_url, data)
1082+
self.assertEqual(response.status_code, status.HTTP_200_OK)
1083+
1084+
data = response.json()
1085+
self.assertEqual(len(data["partijIdentificatoren"]), 1)
1086+
self.assertEqual(partij.partijidentificator_set.all().count(), 1)
1087+
1088+
self.assertEqual(
1089+
data["partijIdentificatoren"][0]["partijIdentificator"],
1090+
{
1091+
"codeObjecttype": partij_identificator.partij_identificator_code_objecttype,
1092+
"codeSoortObjectId": partij_identificator.partij_identificator_code_soort_object_id,
1093+
"objectId": partij_identificator.partij_identificator_object_id,
1094+
"codeRegister": partij_identificator.partij_identificator_code_register,
1095+
},
1096+
)
1097+
1098+
def test_update_replace_partij_partijidentificator(self):
1099+
partij = PartijFactory.create()
10801100
digitaal_adres2 = DigitaalAdresFactory.create()
1081-
rekeningnummer2 = RekeningnummerFactory.create()
1101+
partij_identificator_1 = PartijIdentificatorFactory.create(
1102+
partij=partij,
1103+
partij_identificator_code_objecttype="natuurlijk_persoon",
1104+
partij_identificator_code_soort_object_id="bsn",
1105+
partij_identificator_object_id="296648875",
1106+
partij_identificator_code_register="brp",
1107+
)
1108+
partij_identificator_2 = PartijIdentificatorFactory.create(
1109+
partij_identificator_code_objecttype="niet_natuurlijk_persoon",
1110+
partij_identificator_code_soort_object_id="rsin",
1111+
partij_identificator_object_id="296648875",
1112+
partij_identificator_code_register="hr",
1113+
)
1114+
detail_url = reverse(
1115+
"klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)}
1116+
)
1117+
response = self.client.get(detail_url)
1118+
data = response.json()
1119+
self.assertEqual(len(data["partijIdentificatoren"]), 1)
1120+
self.assertEqual(partij.partijidentificator_set.all().count(), 1)
1121+
1122+
# Check simple GET
1123+
self.assertEqual(
1124+
data["partijIdentificatoren"][0]["partijIdentificator"],
1125+
{
1126+
"codeObjecttype": partij_identificator_1.partij_identificator_code_objecttype,
1127+
"codeSoortObjectId": partij_identificator_1.partij_identificator_code_soort_object_id,
1128+
"objectId": partij_identificator_1.partij_identificator_object_id,
1129+
"codeRegister": partij_identificator_1.partij_identificator_code_register,
1130+
},
1131+
)
1132+
# Update with specific partij_identificator (UUID)
1133+
data = {
1134+
"digitaleAdressen": [{"uuid": str(digitaal_adres2.uuid)}],
1135+
"voorkeursDigitaalAdres": {"uuid": str(digitaal_adres2.uuid)},
1136+
"rekeningnummers": [],
1137+
"voorkeursRekeningnummer": None,
1138+
"soortPartij": "persoon",
1139+
"indicatieActief": True,
1140+
"partijIdentificatoren": [
1141+
{
1142+
"uuid": str(partij_identificator_2.uuid),
1143+
},
1144+
],
1145+
}
1146+
1147+
response = self.client.put(detail_url, data)
1148+
self.assertEqual(response.status_code, status.HTTP_200_OK)
1149+
1150+
data = response.json()
1151+
self.assertEqual(len(data["partijIdentificatoren"]), 1)
1152+
self.assertEqual(partij.partijidentificator_set.all().count(), 1)
1153+
1154+
# Check new values
1155+
self.assertEqual(
1156+
data["partijIdentificatoren"][0]["partijIdentificator"],
1157+
{
1158+
"codeObjecttype": partij_identificator_2.partij_identificator_code_objecttype,
1159+
"codeSoortObjectId": partij_identificator_2.partij_identificator_code_soort_object_id,
1160+
"objectId": partij_identificator_2.partij_identificator_object_id,
1161+
"codeRegister": partij_identificator_2.partij_identificator_code_register,
1162+
},
1163+
)
1164+
partij_identificator_3 = PartijIdentificatorFactory.create(
1165+
partij_identificator_code_objecttype="niet_natuurlijk_persoon",
1166+
partij_identificator_code_soort_object_id="rsin",
1167+
partij_identificator_object_id="296648875",
1168+
partij_identificator_code_register="hr",
1169+
)
10821170

1171+
# Update with new partij_identificator and specific partij_identificator (UUID)
1172+
data = {
1173+
"digitaleAdressen": [{"uuid": str(digitaal_adres2.uuid)}],
1174+
"voorkeursDigitaalAdres": {"uuid": str(digitaal_adres2.uuid)},
1175+
"rekeningnummers": [],
1176+
"voorkeursRekeningnummer": None,
1177+
"soortPartij": "persoon",
1178+
"indicatieActief": True,
1179+
"partijIdentificatoren": [
1180+
{
1181+
"anderePartijIdentificator": "string",
1182+
"partijIdentificator": {
1183+
"codeObjecttype": "natuurlijk_persoon",
1184+
"codeSoortObjectId": "bsn",
1185+
"objectId": "296648875",
1186+
"codeRegister": "brp",
1187+
},
1188+
},
1189+
{
1190+
"uuid": str(partij_identificator_3.uuid),
1191+
},
1192+
],
1193+
}
1194+
1195+
response = self.client.put(detail_url, data)
1196+
self.assertEqual(response.status_code, status.HTTP_200_OK)
1197+
1198+
data = response.json()
1199+
self.assertEqual(len(data["partijIdentificatoren"]), 2)
1200+
self.assertEqual(partij.partijidentificator_set.all().count(), 2)
1201+
self.assertTrue(
1202+
str(partij_identificator_3.uuid)
1203+
in [
1204+
identificator["uuid"] for identificator in data["partijIdentificatoren"]
1205+
]
1206+
)
1207+
1208+
def test_update_partij_partijidentificator_empty_list(self):
1209+
partij = PartijFactory.create()
1210+
digitaal_adres2 = DigitaalAdresFactory.create()
10831211
partij_identificator = PartijIdentificatorFactory.create(
10841212
partij=partij,
10851213
partij_identificator_code_objecttype="natuurlijk_persoon",
@@ -1091,6 +1219,7 @@ def test_update_partij_partijidentificator_empty_list(self):
10911219
detail_url = reverse(
10921220
"klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)}
10931221
)
1222+
10941223
response = self.client.get(detail_url)
10951224
data = response.json()
10961225
self.assertEqual(partij.partijidentificator_set.all().count(), 1)
@@ -1105,45 +1234,19 @@ def test_update_partij_partijidentificator_empty_list(self):
11051234
)
11061235

11071236
data = {
1108-
"nummer": "6427834668",
1109-
"interneNotitie": "changed",
11101237
"digitaleAdressen": [{"uuid": str(digitaal_adres2.uuid)}],
11111238
"voorkeursDigitaalAdres": {"uuid": str(digitaal_adres2.uuid)},
1112-
"rekeningnummers": [{"uuid": str(rekeningnummer2.uuid)}],
1113-
"voorkeursRekeningnummer": {"uuid": str(rekeningnummer2.uuid)},
1239+
"rekeningnummers": [],
1240+
"voorkeursRekeningnummer": None,
11141241
"soortPartij": "persoon",
1115-
"indicatieGeheimhouding": None,
1116-
"voorkeurstaal": "ger",
1117-
"indicatieActief": False,
1118-
"bezoekadres": {
1119-
"nummeraanduidingId": "f78sd8f-uh45-34km-2o3n-aasdasdasc9g",
1120-
"adresregel1": "changed",
1121-
"adresregel2": "changed",
1122-
"adresregel3": "changed",
1123-
"land": "3060",
1124-
},
1125-
"correspondentieadres": {
1126-
"nummeraanduidingId": "sd76f7sd-j4nr-a9s8-83ec-sad89f79a7sd",
1127-
"adresregel1": "changed",
1128-
"adresregel2": "changed",
1129-
"adresregel3": "changed",
1130-
"land": "3060",
1131-
},
1132-
"partijIdentificatie": {
1133-
"contactnaam": {
1134-
"voorletters": "V",
1135-
"voornaam": "Vincent",
1136-
"voorvoegselAchternaam": "",
1137-
"achternaam": "Bennette",
1138-
}
1139-
},
1242+
"indicatieActief": True,
11401243
"partijIdentificatoren": [],
11411244
}
11421245

11431246
response = self.client.put(detail_url, data)
11441247
self.assertEqual(response.status_code, status.HTTP_200_OK)
1145-
data = response.json()
11461248

1249+
data = response.json()
11471250
self.assertEqual(len(data["partijIdentificatoren"]), 0)
11481251
self.assertEqual(partij.partijidentificator_set.all().count(), 0)
11491252

0 commit comments

Comments
 (0)