9
9
from openklant .components .klantinteracties .models .tests .factories .klantcontacten import (
10
10
BetrokkeneFactory ,
11
11
KlantcontactFactory ,
12
+ OnderwerpobjectFactory ,
12
13
)
13
14
from openklant .components .klantinteracties .models .tests .factories .partijen import (
14
15
CategorieFactory ,
@@ -25,23 +26,59 @@ class KlantcontactFilterSetTests(APITestCase):
25
26
def setUp (self ):
26
27
super ().setUp ()
27
28
(
28
- klantcontact ,
29
- klantcontact2 ,
30
- klantcontact3 ,
31
- klantcontact4 ,
29
+ self . klantcontact ,
30
+ self . klantcontact2 ,
31
+ self . klantcontact3 ,
32
+ self . klantcontact4 ,
32
33
self .klantcontact5 ,
33
34
) = KlantcontactFactory .create_batch (5 )
34
35
for betrokkene_klantcontact in [
35
- klantcontact ,
36
- klantcontact2 ,
37
- klantcontact3 ,
38
- klantcontact4 ,
36
+ self . klantcontact ,
37
+ self . klantcontact2 ,
38
+ self . klantcontact3 ,
39
+ self . klantcontact4 ,
39
40
self .klantcontact5 ,
40
41
]:
41
42
self .betrokkene = BetrokkeneFactory .create (
42
43
klantcontact = betrokkene_klantcontact
43
44
)
44
45
46
+ self .onderwerpobject = OnderwerpobjectFactory .create (
47
+ klantcontact = self .klantcontact ,
48
+ objectidentificator_objecttype = "1" ,
49
+ objectidentificator_soort_object_id = "1" ,
50
+ objectidentificator_object_id = "1" ,
51
+ objectidentificator_register = "1" ,
52
+ )
53
+ self .onderwerpobject2 = OnderwerpobjectFactory .create (
54
+ klantcontact = self .klantcontact2 ,
55
+ objectidentificator_objecttype = "2" ,
56
+ objectidentificator_soort_object_id = "2" ,
57
+ objectidentificator_object_id = "2" ,
58
+ objectidentificator_register = "2" ,
59
+ )
60
+ self .onderwerpobject3 = OnderwerpobjectFactory .create (
61
+ klantcontact = self .klantcontact3 ,
62
+ objectidentificator_objecttype = "3" ,
63
+ objectidentificator_soort_object_id = "3" ,
64
+ objectidentificator_object_id = "3" ,
65
+ objectidentificator_register = "3" ,
66
+ )
67
+ self .onderwerpobject4 = OnderwerpobjectFactory .create (
68
+ klantcontact = self .klantcontact4 ,
69
+ objectidentificator_objecttype = "4" ,
70
+ objectidentificator_soort_object_id = "4" ,
71
+ objectidentificator_object_id = "4" ,
72
+ objectidentificator_register = "4" ,
73
+ )
74
+ self .onderwerpobject5 = OnderwerpobjectFactory .create (
75
+ klantcontact = self .klantcontact5 ,
76
+ objectidentificator_objecttype = "5" ,
77
+ objectidentificator_soort_object_id = "5" ,
78
+ objectidentificator_object_id = "5" ,
79
+ objectidentificator_register = "5" ,
80
+ )
81
+
45
82
def test_filter_betrokkene_uuid (self ):
46
83
response = self .client .get (
47
84
self .url , {"had_betrokkene__uuid" : f"{ self .betrokkene .uuid } " }
@@ -94,6 +131,148 @@ def test_filter_betrokkene_url(self):
94
131
95
132
self .assertEqual (response .json ()["count" ], 0 )
96
133
134
+ def test_filter_onderwerpobject_uuid (self ):
135
+ response = self .client .get (
136
+ self .url , {"onderwerpobject__uuid" : f"{ self .onderwerpobject5 .uuid } " }
137
+ )
138
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
139
+
140
+ data = response .json ()["results" ]
141
+
142
+ self .assertEqual (1 , len (data ))
143
+ self .assertEqual (str (self .klantcontact5 .uuid ), data [0 ]["uuid" ])
144
+
145
+ with self .subTest ("no_matches_found_return_empty_query" ):
146
+ response = self .client .get (
147
+ self .url , {"onderwerpobject__uuid" : str (uuid4 ())}
148
+ )
149
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
150
+
151
+ self .assertEqual (response .json ()["count" ], 0 )
152
+
153
+ with self .subTest ("invalid_value_returns_empty_query" ):
154
+ response = self .client .get (
155
+ self .url , {"onderwerpobject__uuid" : "ValueError" }
156
+ )
157
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
158
+
159
+ self .assertEqual (response .json ()["count" ], 0 )
160
+
161
+ def test_filter_onderwerpobject__url (self ):
162
+ response = self .client .get (
163
+ self .url ,
164
+ {
165
+ "onderwerpobject__url" : f"http://testserver/klantinteracties/api/v1/onderwerpobjecten/{ self .onderwerpobject5 .uuid } "
166
+ },
167
+ )
168
+ data = response .json ()["results" ]
169
+
170
+ self .assertEqual (1 , len (data ))
171
+ self .assertEqual (str (self .klantcontact5 .uuid ), data [0 ]["uuid" ])
172
+
173
+ with self .subTest ("no_matches_found_return_nothing" ):
174
+ response = self .client .get (
175
+ self .url ,
176
+ {
177
+ "onderwerpobject__url" : f"http://testserver/klantinteracties/api/v1/onderwerpobjecten/{ str (uuid4 ())} "
178
+ },
179
+ )
180
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
181
+
182
+ self .assertEqual (response .json ()["count" ], 0 )
183
+
184
+ with self .subTest ("invalid_value_returns_empty_query" ):
185
+ response = self .client .get (self .url , {"onderwerpobject__url" : "ValueError" })
186
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
187
+
188
+ self .assertEqual (response .json ()["count" ], 0 )
189
+
190
+ def test_filter_onderwerpobject_objectidentificator_objecttype (self ):
191
+ response = self .client .get (
192
+ self .url ,
193
+ {"onderwerpobject__objectidentificator_objecttype" : "5" },
194
+ )
195
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
196
+
197
+ data = response .json ()["results" ]
198
+
199
+ self .assertEqual (1 , len (data ))
200
+ self .assertEqual (str (self .klantcontact5 .uuid ), data [0 ]["uuid" ])
201
+
202
+ with self .subTest ("no_matches_found_return_nothing" ):
203
+ response = self .client .get (
204
+ self .url ,
205
+ {"onderwerpobject__objectidentificator_objecttype" : "lorum impsum" },
206
+ )
207
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
208
+
209
+ self .assertEqual (response .json ()["count" ], 0 )
210
+
211
+ def test_filter_onderwerpobject_objectidentificator_soort_object_id (self ):
212
+ response = self .client .get (
213
+ self .url ,
214
+ {"onderwerpobject__objectidentificator_soort_object_id" : "5" },
215
+ )
216
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
217
+
218
+ data = response .json ()["results" ]
219
+
220
+ self .assertEqual (1 , len (data ))
221
+ self .assertEqual (str (self .klantcontact5 .uuid ), data [0 ]["uuid" ])
222
+
223
+ with self .subTest ("no_matches_found_return_nothing" ):
224
+ response = self .client .get (
225
+ self .url ,
226
+ {
227
+ "onderwerpobject__objectidentificator_soort_object_id" : "lorum impsum"
228
+ },
229
+ )
230
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
231
+
232
+ self .assertEqual (response .json ()["count" ], 0 )
233
+
234
+ def test_filter_objectidentificator_object_id (self ):
235
+ response = self .client .get (
236
+ self .url ,
237
+ {"onderwerpobject__objectidentificator_object_id" : "5" },
238
+ )
239
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
240
+
241
+ data = response .json ()["results" ]
242
+
243
+ self .assertEqual (1 , len (data ))
244
+ self .assertEqual (str (self .klantcontact5 .uuid ), data [0 ]["uuid" ])
245
+
246
+ with self .subTest ("no_matches_found_return_nothing" ):
247
+ response = self .client .get (
248
+ self .url ,
249
+ {"onderwerpobject__objectidentificator_object_id" : "lorum impsum" },
250
+ )
251
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
252
+
253
+ self .assertEqual (response .json ()["count" ], 0 )
254
+
255
+ def test_filter_objectidentificator_register (self ):
256
+ response = self .client .get (
257
+ self .url ,
258
+ {"onderwerpobject__objectidentificator_register" : "5" },
259
+ )
260
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
261
+
262
+ data = response .json ()["results" ]
263
+
264
+ self .assertEqual (1 , len (data ))
265
+ self .assertEqual (str (self .klantcontact5 .uuid ), data [0 ]["uuid" ])
266
+
267
+ with self .subTest ("no_matches_found_return_nothing" ):
268
+ response = self .client .get (
269
+ self .url ,
270
+ {"onderwerpobject__objectidentificator_register" : "lorum impsum" },
271
+ )
272
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
273
+
274
+ self .assertEqual (response .json ()["count" ], 0 )
275
+
97
276
98
277
class BetrokkeneFilterSetTests (APITestCase ):
99
278
url = reverse ("klantinteracties:betrokkene-list" )
0 commit comments