@@ -126,24 +126,8 @@ def test_create_partij(self):
126
126
},
127
127
)
128
128
129
- with self .subTest ("voorkeurs_adres_must_be_given_digitaal_adres_validation" ):
130
- data ["voorkeursDigitaalAdres" ] = {"uuid" : str (digitaal_adres2 .uuid )}
131
- response = self .client .post (list_url , data )
132
-
133
- self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
134
- response_data = response .json ()
135
- self .assertEqual (
136
- response_data ["invalidParams" ],
137
- [
138
- {
139
- "name" : "voorkeursDigitaalAdres" ,
140
- "code" : "invalid" ,
141
- "reason" : "Het voorkeurs adres moet een gelinkte digitaal adres zijn." ,
142
- }
143
- ],
144
- )
145
-
146
129
with self .subTest ("create_partij_without_foreignkey_relations" ):
130
+ data ["nummer" ] = "1298329192"
147
131
data ["digitaleAdressen" ] = []
148
132
data ["voorkeursDigitaalAdres" ] = None
149
133
data ["vertegenwoordigde" ] = []
@@ -154,7 +138,7 @@ def test_create_partij(self):
154
138
155
139
response_data = response .json ()
156
140
157
- self .assertEqual (response_data ["nummer" ], "1298329191 " )
141
+ self .assertEqual (response_data ["nummer" ], "1298329192 " )
158
142
self .assertEqual (response_data ["interneNotitie" ], "interneNotitie" )
159
143
self .assertEqual (response_data ["digitaleAdressen" ], [])
160
144
self .assertIsNone (response_data ["voorkeursDigitaalAdres" ])
@@ -196,6 +180,56 @@ def test_create_partij(self):
196
180
},
197
181
)
198
182
183
+ with self .subTest ("auto_generate_max_nummer_plus_one" ):
184
+ data ["nummer" ] = ""
185
+ response = self .client .post (list_url , data )
186
+
187
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
188
+ response_data = response .json ()
189
+ self .assertEqual (response_data ["nummer" ], "1298329193" )
190
+
191
+ with self .subTest ("auto_generate_nummer_unique_validation" ):
192
+ data ["nummer" ] = "1298329193"
193
+ response = self .client .post (list_url , data )
194
+
195
+ self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
196
+ response_data = response .json ()
197
+ self .assertEqual (
198
+ response_data ["invalidParams" ][0 ]["reason" ],
199
+ "Er bestaat al een partij met eenzelfde nummer." ,
200
+ )
201
+
202
+ with self .subTest ("auto_generate_nummer_over_10_characters_error_message" ):
203
+ PartijFactory .create (nummer = "9999999999" )
204
+ data ["nummer" ] = ""
205
+ response = self .client .post (list_url , data )
206
+
207
+ self .assertEqual (response .status_code , status .HTTP_409_CONFLICT )
208
+ response_data = response .json ()
209
+ self .assertEqual (
210
+ response_data ["detail" ],
211
+ "Er kon niet automatisch een opvolgend nummer worden gegenereerd. "
212
+ "Het maximaal aantal tekens is bereikt." ,
213
+ )
214
+
215
+ with self .subTest ("voorkeurs_adres_must_be_given_digitaal_adres_validation" ):
216
+ data ["nummer" ] = "1298329194"
217
+ data ["voorkeursDigitaalAdres" ] = {"uuid" : str (digitaal_adres2 .uuid )}
218
+ response = self .client .post (list_url , data )
219
+
220
+ self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
221
+ response_data = response .json ()
222
+ self .assertEqual (
223
+ response_data ["invalidParams" ],
224
+ [
225
+ {
226
+ "name" : "voorkeursDigitaalAdres" ,
227
+ "code" : "invalid" ,
228
+ "reason" : "Het voorkeurs adres moet een gelinkte digitaal adres zijn." ,
229
+ }
230
+ ],
231
+ )
232
+
199
233
def test_create_persoon (self ):
200
234
list_url = reverse ("klantinteracties:partij-list" )
201
235
data = {
0 commit comments