1
- from django .core . exceptions import ValidationError
1
+ from django .db import IntegrityError
2
2
from django .test import TestCase
3
3
4
- from openklant .components .klantinteracties .models .constants import (
5
- PartijIdentificatorCodeObjectType ,
6
- PartijIdentificatorCodeRegister ,
7
- PartijIdentificatorCodeSoortObjectId ,
8
- )
9
- from openklant .components .klantinteracties .models .partijen import (
10
- Partij ,
11
- PartijIdentificator ,
12
- )
13
- from openklant .components .klantinteracties .models .tests .factories .partijen import (
14
- PartijFactory ,
15
- )
16
-
17
- """
18
- # ALLOWED only one time, because it does not exist in any partij
19
- - partij_identificator(partij=partij, soortObjectId='bsn', object_id=123)
20
-
21
- # NOT ALLOWED because already exists one bsn for the same partij
22
- - partij_identificator(partij=partij, soortObjectId='bsn', object_id=456)
23
-
24
- # NOT ALLOWED because already exists one bsn=123 for another partij
25
- - partij_identificator(partij=partij1, soortObjectId='bsn', object_id=123)
26
-
27
- # ALLOWED only one time because vestigingsnummer=None
28
- - partij_identificator(partij=partij1, soortObjectId='kvk', object_id=123)
29
-
30
- # NOT ALLOWED because already exist one kvk_nummer=123 without vestigingsnummer in any partij
31
- - partij_identificator(partij=partij2, soortObjectId='kvk', object_id=123)
32
-
33
- # ALLOWED only one time, SAME kvk (123) NEW vestigingsnummer(123)
34
- - partij_identificator(partij=partij3, soortObjectId='kvk', object_id=123)
35
- - partij_identificator(partij=partij3, soortObjectId='vestigingsnummer', object_id=123)
36
-
37
- # NOT ALLOWED beacuse arleady exists this combination
38
- - partij_identificator(partij=partij4, soortObjectId='kvk', object_id=123)
39
- - partij_identificator(partij=partij4, soortObjectId='vestigingsnummer', object_id=123)
40
-
41
- # ALLOWED only one time, SAME kvk (123) NEW vestigingsnummer(456)
42
- - partij_identificator(partij=partij5, soortObjectId='kvk', object_id=123)
43
- - partij_identificator(partij=partij5, soortObjectId='vestigingsnummer', object_id=456)
44
-
45
- # ALLOWED only one time, NEW kvk (456) SAME vestigingsnummer(456)
46
- - partij_identificator(partij=partij6, soortObjectId='kvk', object_id=456)
47
- - partij_identificator(partij=partij6, soortObjectId='vestigingsnummer', object_id=456)
48
-
49
- Specificando Partij
50
- test_bsn
51
- test_1_bsn_in_partij
52
- test_n_bsn_in_partij
53
- test_1_bsn_in_multiple_partij
54
- test_n_bsn_in_multiple_partij
55
- test_diversin_bsn_in_diversi_partij
56
- test_same_bsn_in_diversi_partij
57
- test_bsn_non_deve_avere_il_parent
58
-
59
-
60
- test_kvk (uguali a bsn)
61
- test_kvk_in_partij
62
- test_kvk_in_partij_in_multiple_parti
63
-
64
-
65
-
66
-
67
-
68
- Senza specificare il partij
69
- test_constraint_partij_identificator (prova a fare lo stesso object_id)
70
- test_constraint_partij_identificator (prova a fare con diversi object_id)
71
-
72
-
73
-
74
- validator = PartijIdentificatorTypeValidator(
75
- code_objecttype="natuurlijk_persoon",
76
- code_soort_object_id="bsn",
77
- object_id="296648875",
78
- code_register=PartijIdentificatorCodeRegister.brp,
79
- )
80
- validator.validate()
81
- """
4
+ from openklant .components .klantinteracties .models .partijen import PartijIdentificator
82
5
83
6
84
7
class PartijIdentificatorModelConstraints (TestCase ):
85
- def setUp (self ):
86
- super ().setUp ()
87
- self .partij = PartijFactory .create (voorkeurs_digitaal_adres = None )
88
-
89
8
def test_valid_scoped_identificator_globally_unique (self ):
90
- PartijIdentificator .objects .create (
91
- sub_identificator_van = None ,
92
- partij_identificator_code_objecttype = "natuurlijk_persoon" ,
93
- partij_identificator_code_soort_object_id = "bsn" ,
94
- partij_identificator_object_id = "296648875" ,
95
- partij_identificator_code_register = "brp" ,
96
- )
97
- PartijIdentificator .objects .create (
98
- sub_identificator_van = None ,
99
- partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
100
- partij_identificator_code_soort_object_id = "rsin" ,
101
- partij_identificator_object_id = "296648875" ,
102
- partij_identificator_code_register = "hr" ,
103
- )
104
-
105
- def test_valid_non_scoped_identificator_globally_unique_different_sub_identificator_van (
106
- self ,
107
- ):
108
9
partij_identificator_a = PartijIdentificator .objects .create (
109
- sub_identificator_van = None ,
110
10
partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
111
11
partij_identificator_code_soort_object_id = "kvk_nummer" ,
112
12
partij_identificator_object_id = "12345678" ,
113
13
partij_identificator_code_register = "hr" ,
114
14
)
115
15
partij_identificator_b = PartijIdentificator .objects .create (
116
- sub_identificator_van = None ,
117
16
partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
118
17
partij_identificator_code_soort_object_id = "kvk_nummer" ,
119
18
partij_identificator_object_id = "87654321" ,
120
19
partij_identificator_code_register = "hr" ,
121
20
)
122
21
22
+ # different sub_identificator_van same identificator_values
123
23
PartijIdentificator .objects .create (
124
24
sub_identificator_van = partij_identificator_a ,
125
25
partij_identificator_code_objecttype = "vestiging" ,
@@ -136,44 +36,43 @@ def test_valid_non_scoped_identificator_globally_unique_different_sub_identifica
136
36
partij_identificator_code_register = "hr" ,
137
37
)
138
38
139
- def test_valid_non_scoped_identificator_globally_unique_different_values (self ):
140
- partij_identificator = PartijIdentificator .objects .create (
141
- sub_identificator_van = None ,
142
- partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
143
- partij_identificator_code_soort_object_id = "kvk_nummer" ,
144
- partij_identificator_object_id = "12345678" ,
145
- partij_identificator_code_register = "hr" ,
146
- )
147
-
39
+ # different identificator_values same sub_identificator_van
148
40
PartijIdentificator .objects .create (
149
- sub_identificator_van = partij_identificator ,
41
+ sub_identificator_van = partij_identificator_a ,
150
42
partij_identificator_code_objecttype = "vestiging" ,
151
43
partij_identificator_code_soort_object_id = "vestigingsnummer" ,
152
- partij_identificator_object_id = "123412341234 " ,
44
+ partij_identificator_object_id = "456745674567 " ,
153
45
partij_identificator_code_register = "hr" ,
154
46
)
155
-
156
47
PartijIdentificator .objects .create (
157
- sub_identificator_van = partij_identificator ,
48
+ sub_identificator_van = partij_identificator_a ,
158
49
partij_identificator_code_objecttype = "vestiging" ,
159
50
partij_identificator_code_soort_object_id = "vestigingsnummer" ,
160
- partij_identificator_object_id = "987698769876 " ,
51
+ partij_identificator_object_id = "567856785678 " ,
161
52
partij_identificator_code_register = "hr" ,
162
53
)
163
54
164
- def test_invalid_scoped_identificator_globally_unique (self ):
165
- return
55
+ def test_valid_non_scoped_identificator_globally_unique (self ):
166
56
PartijIdentificator .objects .create (
167
- sub_identificator_van = None ,
168
57
partij_identificator_code_objecttype = "natuurlijk_persoon" ,
169
58
partij_identificator_code_soort_object_id = "bsn" ,
170
59
partij_identificator_object_id = "296648875" ,
171
60
partij_identificator_code_register = "brp" ,
172
61
)
173
62
PartijIdentificator .objects .create (
174
- sub_identificator_van = None ,
175
- partij_identificator_code_objecttype = "natuurlijk_persoon" ,
176
- partij_identificator_code_soort_object_id = "bsn" ,
63
+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
64
+ partij_identificator_code_soort_object_id = "rsin" ,
177
65
partij_identificator_object_id = "296648875" ,
178
- partij_identificator_code_register = "brp" ,
66
+ partij_identificator_code_register = "hr" ,
67
+ )
68
+
69
+ def test_invalid_check_sub_identificator_van_not_self (self ):
70
+ partij_identificator = PartijIdentificator .objects .create (
71
+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
72
+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
73
+ partij_identificator_object_id = "87654321" ,
74
+ partij_identificator_code_register = "hr" ,
179
75
)
76
+ with self .assertRaises (IntegrityError ):
77
+ partij_identificator .sub_identificator_van = partij_identificator
78
+ partij_identificator .save ()
0 commit comments