@@ -2146,6 +2146,206 @@ def _get_detail_url(partij: Partij) -> str:
2146
2146
received_adressen [0 ]["url" ], f"http://testserver{ expected_url } "
2147
2147
)
2148
2148
2149
+ def test_get_partij_and_partij_identificatoren (self ):
2150
+ partij = PartijFactory .create ()
2151
+ partij_identificator = PartijIdentificatorFactory .create (
2152
+ partij = partij ,
2153
+ partij_identificator_code_objecttype = "natuurlijk_persoon" ,
2154
+ partij_identificator_code_soort_object_id = "bsn" ,
2155
+ partij_identificator_object_id = "296648875" ,
2156
+ partij_identificator_code_register = "brp" ,
2157
+ )
2158
+ detail_url = reverse (
2159
+ "klantinteracties:partij-detail" , kwargs = {"uuid" : str (partij .uuid )}
2160
+ )
2161
+
2162
+ response = self .client .get (detail_url )
2163
+
2164
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2165
+ data = response .json ()
2166
+ url = "http://testserver/klantinteracties/api/v1"
2167
+ self .assertEqual (
2168
+ data ["partijIdentificatoren" ],
2169
+ [
2170
+ {
2171
+ "uuid" : str (partij_identificator .uuid ),
2172
+ "url" : f"{ url } /partij-identificatoren/{ str (partij_identificator .uuid )} " ,
2173
+ "identificeerdePartij" : {
2174
+ "uuid" : str (partij .uuid ),
2175
+ "url" : f"{ url } /partijen/{ str (partij .uuid )} " ,
2176
+ },
2177
+ "anderePartijIdentificator" : partij_identificator .andere_partij_identificator ,
2178
+ "partijIdentificator" : {
2179
+ "codeObjecttype" : partij_identificator .partij_identificator_code_objecttype ,
2180
+ "codeSoortObjectId" : partij_identificator .partij_identificator_code_soort_object_id ,
2181
+ "objectId" : partij_identificator .partij_identificator_object_id ,
2182
+ "codeRegister" : partij_identificator .partij_identificator_code_register ,
2183
+ },
2184
+ "subIdentificatorVan" : partij_identificator .sub_identificator_van ,
2185
+ }
2186
+ ],
2187
+ )
2188
+
2189
+ def test_create_partij_with_null_partij_identificator (self ):
2190
+ digitaal_adres = DigitaalAdresFactory .create ()
2191
+ rekeningnummer = RekeningnummerFactory .create ()
2192
+ list_url = reverse ("klantinteracties:partij-list" )
2193
+ data = {
2194
+ "digitaleAdressen" : [{"uuid" : str (digitaal_adres .uuid )}],
2195
+ "voorkeursDigitaalAdres" : {"uuid" : str (digitaal_adres .uuid )},
2196
+ "rekeningnummers" : [{"uuid" : str (rekeningnummer .uuid )}],
2197
+ "voorkeursRekeningnummer" : {"uuid" : str (rekeningnummer .uuid )},
2198
+ "soortPartij" : "persoon" ,
2199
+ "indicatieActief" : True ,
2200
+ }
2201
+ self .assertEqual (Partij .objects .all ().count (), 0 )
2202
+
2203
+ with self .subTest ("key_not_specified" ):
2204
+ self .assertFalse ("partijIdentificatoren" in data )
2205
+ response = self .client .post (list_url , data )
2206
+ response_data = response .json ()
2207
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2208
+ self .assertEqual (response_data ["partijIdentificatoren" ], [])
2209
+ partij = Partij .objects .get (uuid = str (response_data ["uuid" ]))
2210
+ self .assertEqual (partij .partijidentificator_set .count (), 0 )
2211
+ self .assertEqual (Partij .objects .all ().count (), 1 )
2212
+
2213
+ with self .subTest ("null_value" ):
2214
+ data ["partijIdentificatoren" ] = None
2215
+ response = self .client .post (list_url , data )
2216
+ response_data = response .json ()
2217
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2218
+ self .assertEqual (response_data ["partijIdentificatoren" ], [])
2219
+ partij = Partij .objects .get (uuid = str (response_data ["uuid" ]))
2220
+ self .assertEqual (partij .partijidentificator_set .count (), 0 )
2221
+ self .assertEqual (Partij .objects .all ().count (), 2 )
2222
+
2223
+ with self .subTest ("empty_list_value" ):
2224
+ data ["partijIdentificatoren" ] = []
2225
+ response = self .client .post (list_url , data )
2226
+ response_data = response .json ()
2227
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2228
+ self .assertEqual (response_data ["partijIdentificatoren" ], [])
2229
+ partij = Partij .objects .get (uuid = str (response_data ["uuid" ]))
2230
+ self .assertEqual (partij .partijidentificator_set .count (), 0 )
2231
+ self .assertEqual (Partij .objects .all ().count (), 3 )
2232
+
2233
+ def test_create_partij_with_new_partij_identificator (self ):
2234
+ digitaal_adres = DigitaalAdresFactory .create ()
2235
+ rekeningnummer = RekeningnummerFactory .create ()
2236
+ list_url = reverse ("klantinteracties:partij-list" )
2237
+ data = {
2238
+ "digitaleAdressen" : [{"uuid" : str (digitaal_adres .uuid )}],
2239
+ "voorkeursDigitaalAdres" : {"uuid" : str (digitaal_adres .uuid )},
2240
+ "rekeningnummers" : [{"uuid" : str (rekeningnummer .uuid )}],
2241
+ "partijIdentificatoren" : [
2242
+ {
2243
+ "anderePartijIdentificator" : "anderePartijIdentificator" ,
2244
+ "partijIdentificator" : {
2245
+ "codeObjecttype" : "natuurlijk_persoon" ,
2246
+ "codeSoortObjectId" : "bsn" ,
2247
+ "objectId" : "296648875" ,
2248
+ "codeRegister" : "brp" ,
2249
+ },
2250
+ }
2251
+ ],
2252
+ "voorkeursRekeningnummer" : {"uuid" : str (rekeningnummer .uuid )},
2253
+ "soortPartij" : "persoon" ,
2254
+ "indicatieActief" : True ,
2255
+ "partijIdentificatie" : {
2256
+ "contactnaam" : {
2257
+ "voorletters" : "P" ,
2258
+ "voornaam" : "Phil" ,
2259
+ "voorvoegselAchternaam" : "" ,
2260
+ "achternaam" : "Bozeman" ,
2261
+ }
2262
+ },
2263
+ }
2264
+
2265
+ response = self .client .post (list_url , data )
2266
+ response_data = response .json ()
2267
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2268
+ self .assertEqual (Partij .objects .all ().count (), 1 )
2269
+ self .assertEqual (PartijIdentificator .objects .all ().count (), 1 )
2270
+
2271
+ partij = Partij .objects .get (uuid = response_data ["uuid" ])
2272
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2273
+ self .assertEqual (len (response_data ["partijIdentificatoren" ]), 1 )
2274
+
2275
+ partij_identificator = partij .partijidentificator_set .get ()
2276
+ partij_identificator_dict = response_data ["partijIdentificatoren" ][0 ]
2277
+ self .assertEqual (
2278
+ partij_identificator_dict ["uuid" ],
2279
+ str (partij_identificator .uuid ),
2280
+ )
2281
+ self .assertEqual (
2282
+ partij_identificator_dict ["identificeerdePartij" ]["uuid" ],
2283
+ str (partij_identificator .partij .uuid ),
2284
+ )
2285
+ self .assertEqual (
2286
+ partij_identificator_dict ["partijIdentificator" ],
2287
+ {
2288
+ "codeObjecttype" : "natuurlijk_persoon" ,
2289
+ "codeSoortObjectId" : "bsn" ,
2290
+ "objectId" : "296648875" ,
2291
+ "codeRegister" : "brp" ,
2292
+ },
2293
+ )
2294
+ self .assertEqual (
2295
+ partij_identificator_dict ["subIdentificatorVan" ],
2296
+ partij_identificator .sub_identificator_van ,
2297
+ )
2298
+
2299
+ def test_invalid_create_partij_with_partij_identificator (self ):
2300
+ digitaal_adres = DigitaalAdresFactory .create ()
2301
+ rekeningnummer = RekeningnummerFactory .create ()
2302
+ list_url = reverse ("klantinteracties:partij-list" )
2303
+ partij = PartijFactory .create ()
2304
+ self .assertEqual (Partij .objects .all ().count (), 1 )
2305
+
2306
+ # identificeerdePartij' must not be selected.
2307
+ data = {
2308
+ "digitaleAdressen" : [{"uuid" : str (digitaal_adres .uuid )}],
2309
+ "voorkeursDigitaalAdres" : {"uuid" : str (digitaal_adres .uuid )},
2310
+ "rekeningnummers" : [{"uuid" : str (rekeningnummer .uuid )}],
2311
+ "partijIdentificatoren" : [
2312
+ {
2313
+ "identificeerdePartij" : {"uuid" : str (partij .uuid )},
2314
+ "anderePartijIdentificator" : "anderePartijIdentificator" ,
2315
+ "partijIdentificator" : {
2316
+ "codeObjecttype" : "natuurlijk_persoon" ,
2317
+ "codeSoortObjectId" : "bsn" ,
2318
+ "objectId" : "296648875" ,
2319
+ "codeRegister" : "brp" ,
2320
+ },
2321
+ }
2322
+ ],
2323
+ "voorkeursRekeningnummer" : {"uuid" : str (rekeningnummer .uuid )},
2324
+ "soortPartij" : "persoon" ,
2325
+ "indicatieActief" : True ,
2326
+ "partijIdentificatie" : {
2327
+ "contactnaam" : {
2328
+ "voorletters" : "P" ,
2329
+ "voornaam" : "Phil" ,
2330
+ "voorvoegselAchternaam" : "" ,
2331
+ "achternaam" : "Bozeman" ,
2332
+ }
2333
+ },
2334
+ }
2335
+
2336
+ response = self .client .post (list_url , data )
2337
+ self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
2338
+ error = get_validation_errors (
2339
+ response , "partijIdentificatoren.identificeerdePartij"
2340
+ )
2341
+ self .assertEqual (error ["code" ], "invalid" )
2342
+ self .assertEqual (
2343
+ error ["reason" ],
2344
+ "Het veld `identificeerde_partij` wordt automatisch ingesteld en hoeft niet te worden opgegeven." ,
2345
+ )
2346
+
2347
+ self .assertEqual (Partij .objects .all ().count (), 1 )
2348
+
2149
2349
2150
2350
class PartijIdentificatorTests (APITestCase ):
2151
2351
def test_list_partij_identificator (self ):
0 commit comments