@@ -2503,6 +2503,260 @@ def test_invalid_create_where_partij_is_selected(self):
2503
2503
2504
2504
self .assertEqual (Partij .objects .all ().count (), 1 )
2505
2505
2506
+ def test_partially_update_with_null_values (self ):
2507
+ partij = PartijFactory .create (
2508
+ nummer = "1298329191" ,
2509
+ interne_notitie = "interneNotitie" ,
2510
+ voorkeurs_digitaal_adres = None ,
2511
+ voorkeurs_rekeningnummer = None ,
2512
+ indicatie_geheimhouding = True ,
2513
+ voorkeurstaal = "ndl" ,
2514
+ indicatie_actief = True ,
2515
+ soort_partij = "persoon" ,
2516
+ )
2517
+
2518
+ detail_url = reverse (
2519
+ "klantinteracties:partij-detail" , kwargs = {"uuid" : str (partij .uuid )}
2520
+ )
2521
+
2522
+ with self .subTest ("partij_identificatoren_not_specified" ):
2523
+ data = {"soortPartij" : "organisatie" }
2524
+ self .assertEqual (partij .soort_partij , "persoon" )
2525
+ self .assertEqual (partij .partijidentificator_set .count (), 0 )
2526
+ response = self .client .patch (detail_url , data )
2527
+ response_data = response .json ()
2528
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2529
+ self .assertEqual (response_data ["partijIdentificatoren" ], [])
2530
+ self .assertEqual (response_data ["soortPartij" ], "organisatie" )
2531
+ self .assertEqual (partij .partijidentificator_set .count (), 0 )
2532
+
2533
+ BsnPartijIdentificatorFactory .create (
2534
+ partij = partij , partij_identificator_object_id = "296648875"
2535
+ )
2536
+ # Resend update request
2537
+ # No changes to the partij_identificator because the value wasn't specified in PATCH
2538
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2539
+ response = self .client .patch (detail_url , data )
2540
+ response_data = response .json ()
2541
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2542
+
2543
+ partij = Partij .objects .get (uuid = partij .uuid )
2544
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2545
+ self .assertEqual (len (response_data ["partijIdentificatoren" ]), 1 )
2546
+ self .assertEqual (response_data ["soortPartij" ], "organisatie" )
2547
+ self .assertEqual (partij .soort_partij , "organisatie" )
2548
+
2549
+ with self .subTest ("partij_identificatoren_null_value" ):
2550
+ data = {
2551
+ "soortPartij" : "persoon" ,
2552
+ "partijIdentificatoren" : None ,
2553
+ }
2554
+ self .assertEqual (partij .soort_partij , "organisatie" )
2555
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2556
+
2557
+ # No changes to the partij_identificator because the value was None in PATCH
2558
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2559
+ response = self .client .patch (detail_url , data )
2560
+ response_data = response .json ()
2561
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2562
+
2563
+ partij = Partij .objects .get (uuid = partij .uuid )
2564
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2565
+ self .assertEqual (len (response_data ["partijIdentificatoren" ]), 1 )
2566
+ self .assertEqual (response_data ["soortPartij" ], "persoon" )
2567
+ self .assertEqual (partij .soort_partij , "persoon" )
2568
+
2569
+ with self .subTest ("partij_identificatoren_empty_list_value" ):
2570
+ data = {
2571
+ "soortPartij" : "organisatie" ,
2572
+ "partijIdentificatoren" : [],
2573
+ }
2574
+ self .assertEqual (partij .soort_partij , "persoon" )
2575
+ self .assertEqual (partij .partijidentificator_set .count (), 1 )
2576
+
2577
+ # Delete all partij_identificatoren because the value was [] in PATCH
2578
+ response = self .client .patch (detail_url , data )
2579
+ response_data = response .json ()
2580
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2581
+ partij = Partij .objects .get (uuid = partij .uuid )
2582
+ self .assertEqual (partij .partijidentificator_set .count (), 0 )
2583
+ self .assertEqual (len (response_data ["partijIdentificatoren" ]), 0 )
2584
+ self .assertEqual (response_data ["soortPartij" ], "organisatie" )
2585
+ self .assertEqual (partij .soort_partij , "organisatie" )
2586
+
2587
+ def test_partially_update_where_all_partij_identificatoren_have_uuid (self ):
2588
+ partij = PartijFactory .create (
2589
+ nummer = "1298329191" ,
2590
+ interne_notitie = "interneNotitie" ,
2591
+ voorkeurs_digitaal_adres = None ,
2592
+ voorkeurs_rekeningnummer = None ,
2593
+ soort_partij = "persoon" ,
2594
+ indicatie_geheimhouding = True ,
2595
+ voorkeurstaal = "ndl" ,
2596
+ indicatie_actief = True ,
2597
+ )
2598
+ detail_url = reverse (
2599
+ "klantinteracties:partij-detail" , kwargs = {"uuid" : str (partij .uuid )}
2600
+ )
2601
+ bsn = BsnPartijIdentificatorFactory .create (
2602
+ partij = partij , partij_identificator_object_id = "296648875"
2603
+ )
2604
+ kvk_nummer = KvkNummerPartijIdentificatorFactory .create (
2605
+ partij = partij , partij_identificator_object_id = "12345678"
2606
+ )
2607
+ vestigingsnummer = VestigingsnummerPartijIdentificatorFactory .create (
2608
+ partij = partij , partij_identificator_object_id = "111122223333"
2609
+ )
2610
+
2611
+ # changes are only for objectId
2612
+ data = {
2613
+ "soortPartij" : "organisatie" ,
2614
+ "partijIdentificatoren" : [
2615
+ {
2616
+ "uuid" : str (bsn .uuid ),
2617
+ "partijIdentificator" : {
2618
+ "codeObjecttype" : "natuurlijk_persoon" ,
2619
+ "codeSoortObjectId" : "bsn" ,
2620
+ "objectId" : "123456782" ,
2621
+ "codeRegister" : "brp" ,
2622
+ },
2623
+ },
2624
+ {
2625
+ "uuid" : str (kvk_nummer .uuid ),
2626
+ "partijIdentificator" : {
2627
+ "codeObjecttype" : "niet_natuurlijk_persoon" ,
2628
+ "codeSoortObjectId" : "kvk_nummer" ,
2629
+ "objectId" : "11112222" ,
2630
+ "codeRegister" : "hr" ,
2631
+ },
2632
+ },
2633
+ {
2634
+ "uuid" : str (vestigingsnummer .uuid ),
2635
+ "sub_identificator_van" : {"uuid" : str (kvk_nummer .uuid )},
2636
+ "partijIdentificator" : {
2637
+ "codeObjecttype" : "vestiging" ,
2638
+ "codeSoortObjectId" : "vestigingsnummer" ,
2639
+ "objectId" : "444455556666" ,
2640
+ "codeRegister" : "hr" ,
2641
+ },
2642
+ },
2643
+ ],
2644
+ }
2645
+ response = self .client .patch (detail_url , data )
2646
+ response_data = response .json ()
2647
+
2648
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2649
+ partij = Partij .objects .get (pk = partij .pk )
2650
+
2651
+ self .assertEqual (len (response_data ["partijIdentificatoren" ]), 3 )
2652
+ self .assertEqual (response_data ["soortPartij" ], "organisatie" )
2653
+ self .assertEqual (partij .soort_partij , "organisatie" )
2654
+ new_bsn = partij .partijidentificator_set .get (
2655
+ partij_identificator_code_soort_object_id = "bsn"
2656
+ )
2657
+ new_kvk_nummer = partij .partijidentificator_set .get (
2658
+ partij_identificator_code_soort_object_id = "kvk_nummer"
2659
+ )
2660
+ new_vestigingsnummer = partij .partijidentificator_set .get (
2661
+ partij_identificator_code_soort_object_id = "vestigingsnummer"
2662
+ )
2663
+ # assert that they are the same objects
2664
+ self .assertEqual (new_bsn .uuid , bsn .uuid )
2665
+ self .assertEqual (new_kvk_nummer .uuid , kvk_nummer .uuid )
2666
+ self .assertEqual (new_vestigingsnummer .uuid , vestigingsnummer .uuid )
2667
+ # assert that the object_ids have been updated
2668
+ self .assertEqual (new_bsn .partij_identificator_object_id , "123456782" )
2669
+ self .assertEqual (new_kvk_nummer .partij_identificator_object_id , "11112222" )
2670
+ self .assertEqual (
2671
+ new_vestigingsnummer .partij_identificator_object_id , "444455556666"
2672
+ )
2673
+
2674
+ def test_partially_update_where_not_all_partij_identificatoren_have_uuid (self ):
2675
+ partij = PartijFactory .create (
2676
+ nummer = "1298329191" ,
2677
+ interne_notitie = "interneNotitie" ,
2678
+ voorkeurs_digitaal_adres = None ,
2679
+ voorkeurs_rekeningnummer = None ,
2680
+ soort_partij = "persoon" ,
2681
+ indicatie_geheimhouding = True ,
2682
+ voorkeurstaal = "ndl" ,
2683
+ indicatie_actief = True ,
2684
+ )
2685
+ detail_url = reverse (
2686
+ "klantinteracties:partij-detail" , kwargs = {"uuid" : str (partij .uuid )}
2687
+ )
2688
+ bsn = BsnPartijIdentificatorFactory .create (
2689
+ partij = partij , partij_identificator_object_id = "296648875"
2690
+ )
2691
+ kvk_nummer = KvkNummerPartijIdentificatorFactory .create (
2692
+ partij = partij , partij_identificator_object_id = "12345678"
2693
+ )
2694
+ vestigingsnummer = VestigingsnummerPartijIdentificatorFactory .create (
2695
+ partij = partij , partij_identificator_object_id = "111122223333"
2696
+ )
2697
+
2698
+ # changes are only for objectId
2699
+ data = {
2700
+ "soortPartij" : "organisatie" ,
2701
+ "partijIdentificatoren" : [
2702
+ {
2703
+ "partijIdentificator" : {
2704
+ "codeObjecttype" : "natuurlijk_persoon" ,
2705
+ "codeSoortObjectId" : "bsn" ,
2706
+ "objectId" : "123456782" ,
2707
+ "codeRegister" : "brp" ,
2708
+ },
2709
+ },
2710
+ {
2711
+ "uuid" : str (kvk_nummer .uuid ),
2712
+ "partijIdentificator" : {
2713
+ "codeObjecttype" : "niet_natuurlijk_persoon" ,
2714
+ "codeSoortObjectId" : "kvk_nummer" ,
2715
+ "objectId" : "11112222" ,
2716
+ "codeRegister" : "hr" ,
2717
+ },
2718
+ },
2719
+ {
2720
+ "uuid" : str (vestigingsnummer .uuid ),
2721
+ "sub_identificator_van" : {"uuid" : str (kvk_nummer .uuid )},
2722
+ "partijIdentificator" : {
2723
+ "codeObjecttype" : "vestiging" ,
2724
+ "codeSoortObjectId" : "vestigingsnummer" ,
2725
+ "objectId" : "444455556666" ,
2726
+ "codeRegister" : "hr" ,
2727
+ },
2728
+ },
2729
+ ],
2730
+ }
2731
+ response = self .client .patch (detail_url , data )
2732
+ response_data = response .json ()
2733
+
2734
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2735
+ partij = Partij .objects .get (pk = partij .pk )
2736
+ self .assertEqual (len (response_data ["partijIdentificatoren" ]), 3 )
2737
+ self .assertEqual (response_data ["soortPartij" ], "organisatie" )
2738
+ self .assertEqual (partij .soort_partij , "organisatie" )
2739
+ new_bsn = partij .partijidentificator_set .get (
2740
+ partij_identificator_code_soort_object_id = "bsn"
2741
+ )
2742
+ new_kvk_nummer = partij .partijidentificator_set .get (
2743
+ partij_identificator_code_soort_object_id = "kvk_nummer"
2744
+ )
2745
+ new_vestigingsnummer = partij .partijidentificator_set .get (
2746
+ partij_identificator_code_soort_object_id = "vestigingsnummer"
2747
+ )
2748
+ # assert bsn was deleted and then created again with new values
2749
+ self .assertNotEqual (new_bsn .uuid , bsn .uuid )
2750
+ # assert that they are the same objects
2751
+ self .assertEqual (new_kvk_nummer .uuid , kvk_nummer .uuid )
2752
+ self .assertEqual (new_vestigingsnummer .uuid , vestigingsnummer .uuid )
2753
+ # assert that the object_ids have been updated
2754
+ self .assertEqual (new_bsn .partij_identificator_object_id , "123456782" )
2755
+ self .assertEqual (new_kvk_nummer .partij_identificator_object_id , "11112222" )
2756
+ self .assertEqual (
2757
+ new_vestigingsnummer .partij_identificator_object_id , "444455556666"
2758
+ )
2759
+
2506
2760
2507
2761
class PartijIdentificatorTests (APITestCase ):
2508
2762
def test_list_partij_identificator (self ):
@@ -2576,6 +2830,7 @@ def test_update_partij_identificator(self):
2576
2830
partij , partij2 = PartijFactory .create_batch (2 )
2577
2831
partij_identificator = BsnPartijIdentificatorFactory .create (
2578
2832
partij = partij ,
2833
+ andere_partij_identificator = "anderePartijIdentificator" ,
2579
2834
partij_identificator_object_id = "296648875" ,
2580
2835
)
2581
2836
@@ -2916,7 +3171,7 @@ def test_invalid_create_partij_required(self):
2916
3171
def test_invalid_create_duplicate_code_soort_object_id_for_partij (self ):
2917
3172
BsnPartijIdentificatorFactory .create (
2918
3173
partij = self .partij ,
2919
- partij_identificator_object_id = "296648875 " ,
3174
+ partij_identificator_object_id = "123456782 " ,
2920
3175
)
2921
3176
2922
3177
data = {
0 commit comments