|
11 | 11 | from zgw_consumers.test.factories import ServiceFactory
|
12 | 12 |
|
13 | 13 | from openarchiefbeheer.accounts.tests.factories import UserFactory
|
| 14 | +from openarchiefbeheer.destruction.constants import ListItemStatus |
| 15 | +from openarchiefbeheer.destruction.tests.factories import ( |
| 16 | + DestructionListFactory, |
| 17 | + DestructionListItemFactory, |
| 18 | + DestructionListItemReviewFactory, |
| 19 | + DestructionListReviewFactory, |
| 20 | +) |
14 | 21 |
|
15 | 22 | from ..tasks import retrieve_and_cache_zaken_from_openzaak
|
16 | 23 | from .factories import ZaakFactory
|
@@ -172,6 +179,187 @@ def test_response_cached(self, m):
|
172 | 179 | history = m.request_history
|
173 | 180 | self.assertEqual(len(history), 1)
|
174 | 181 |
|
| 182 | + def test_retrieve_zaaktypen_choices_for_destruction_list(self): |
| 183 | + user = UserFactory.create(role__can_start_destruction=True) |
| 184 | + |
| 185 | + destruction_list = DestructionListFactory.create() |
| 186 | + # The zaaktypen of these items should be returned, |
| 187 | + # because they are in the destruction list with status 'suggested' |
| 188 | + items_in_list = DestructionListItemFactory.create_batch( |
| 189 | + 3, |
| 190 | + with_zaak=True, |
| 191 | + zaak__with_expand=True, |
| 192 | + destruction_list=destruction_list, |
| 193 | + status=ListItemStatus.suggested, |
| 194 | + ) |
| 195 | + # We simulate 2 items having different versions of the same zaaktype |
| 196 | + items_in_list[0].zaak._expand["zaaktype"]["identificatie"] = "ZAAKTYPE-1" |
| 197 | + items_in_list[0].zaak.save() |
| 198 | + items_in_list[1].zaak._expand["zaaktype"]["identificatie"] = "ZAAKTYPE-1" |
| 199 | + items_in_list[1].zaak.save() |
| 200 | + items_in_list[2].zaak._expand["zaaktype"]["identificatie"] = "ZAAKTYPE-2" |
| 201 | + items_in_list[2].zaak.save() |
| 202 | + |
| 203 | + # This zaaktype should NOT be returned because it has status 'removed' |
| 204 | + DestructionListItemFactory.create( |
| 205 | + with_zaak=True, |
| 206 | + destruction_list=destruction_list, |
| 207 | + status=ListItemStatus.removed, |
| 208 | + ) |
| 209 | + # These zaaktypen should NOT be returned because it is not related to the list |
| 210 | + DestructionListItemFactory.create_batch(2, with_zaak=True) |
| 211 | + |
| 212 | + self.client.force_authenticate(user=user) |
| 213 | + endpoint = furl(reverse("api:retrieve-zaaktypen-choices")) |
| 214 | + endpoint.args["destruction_list"] = destruction_list.uuid |
| 215 | + |
| 216 | + response = self.client.get(endpoint.url) |
| 217 | + |
| 218 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 219 | + |
| 220 | + choices = sorted(response.json(), key=lambda choice: choice["label"]) |
| 221 | + |
| 222 | + self.assertEqual(len(choices), 2) |
| 223 | + self.assertEqual(choices[0]["label"], "ZAAKTYPE-1") |
| 224 | + self.assertEqual(choices[1]["label"], "ZAAKTYPE-2") |
| 225 | + |
| 226 | + values = choices[0]["value"].split(",") |
| 227 | + |
| 228 | + self.assertEqual(len(values), 2) |
| 229 | + self.assertIn(items_in_list[0].zaak.zaaktype, values) |
| 230 | + self.assertIn(items_in_list[1].zaak.zaaktype, values) |
| 231 | + |
| 232 | + self.assertEqual(choices[1]["value"], items_in_list[2].zaak.zaaktype) |
| 233 | + |
| 234 | + @Mocker() |
| 235 | + def test_not_cached_if_query_param_chages(self, m): |
| 236 | + user = UserFactory.create(role__can_start_destruction=True) |
| 237 | + |
| 238 | + destruction_list = DestructionListFactory.create() |
| 239 | + |
| 240 | + items_in_list = DestructionListItemFactory.create_batch( |
| 241 | + 2, |
| 242 | + with_zaak=True, |
| 243 | + zaak__with_expand=True, |
| 244 | + destruction_list=destruction_list, |
| 245 | + status=ListItemStatus.suggested, |
| 246 | + ) |
| 247 | + items_in_list[0].zaak._expand["zaaktype"]["identificatie"] = "ZAAKTYPE-1" |
| 248 | + items_in_list[0].zaak.save() |
| 249 | + items_in_list[1].zaak._expand["zaaktype"]["identificatie"] = "ZAAKTYPE-2" |
| 250 | + items_in_list[1].zaak.save() |
| 251 | + |
| 252 | + ServiceFactory.create( |
| 253 | + api_type=APITypes.ztc, |
| 254 | + api_root="http://catalogi-api.nl/catalogi/api/v1", |
| 255 | + ) |
| 256 | + ZaakFactory.create( |
| 257 | + zaaktype="http://catalogi-api.nl/catalogi/api/v1/zaakypen/111-111-111", |
| 258 | + _expand={"zaaktype": {"identificatie": "ZAAKTYPE-3"}}, |
| 259 | + ) |
| 260 | + ZaakFactory.create( |
| 261 | + zaaktype="http://catalogi-api.nl/catalogi/api/v1/zaakypen/222-222-222", |
| 262 | + _expand={"zaaktype": {"identificatie": "ZAAKTYPE-4"}}, |
| 263 | + ) |
| 264 | + ZaakFactory.create( |
| 265 | + zaaktype="http://catalogi-api.nl/catalogi/api/v1/zaakypen/333-333-333", |
| 266 | + _expand={"zaaktype": {"identificatie": "ZAAKTYPE-5"}}, |
| 267 | + ) |
| 268 | + |
| 269 | + m.get( |
| 270 | + "http://catalogi-api.nl/catalogi/api/v1/zaaktypen", |
| 271 | + json={ |
| 272 | + "count": 2, |
| 273 | + "results": [ |
| 274 | + { |
| 275 | + "url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/111-111-111", |
| 276 | + "identificatie": "ZAAKTYPE-3", |
| 277 | + }, |
| 278 | + { |
| 279 | + "url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/222-222-222", |
| 280 | + "identificatie": "ZAAKTYPE-4", |
| 281 | + }, |
| 282 | + { |
| 283 | + "url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/333-333-333", |
| 284 | + "identificatie": "ZAAKTYPE-5", |
| 285 | + }, |
| 286 | + ], |
| 287 | + }, |
| 288 | + ) |
| 289 | + |
| 290 | + self.client.force_authenticate(user=user) |
| 291 | + endpoint = furl(reverse("api:retrieve-zaaktypen-choices")) |
| 292 | + endpoint.args["destruction_list"] = destruction_list.uuid |
| 293 | + |
| 294 | + response = self.client.get(endpoint.url) |
| 295 | + |
| 296 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 297 | + self.assertEqual(len(response.json()), 2) |
| 298 | + |
| 299 | + del endpoint.args["destruction_list"] |
| 300 | + response = self.client.get(endpoint.url) |
| 301 | + |
| 302 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 303 | + self.assertEqual(len(response.json()), 3) |
| 304 | + |
| 305 | + def test_retrieve_zaaktypen_choices_for_review(self): |
| 306 | + user = UserFactory.create(role__can_start_destruction=True) |
| 307 | + |
| 308 | + review = DestructionListReviewFactory.create() |
| 309 | + # The zaaktypen of these items should be returned, |
| 310 | + # because they are in the review |
| 311 | + review_items = DestructionListItemReviewFactory.create_batch( |
| 312 | + 3, |
| 313 | + destruction_list_item__with_zaak=True, |
| 314 | + destruction_list_item__zaak__with_expand=True, |
| 315 | + destruction_list=review.destruction_list, |
| 316 | + review=review, |
| 317 | + ) |
| 318 | + # We simulate 2 items having different versions of the same zaaktype |
| 319 | + review_items[0].destruction_list_item.zaak._expand["zaaktype"][ |
| 320 | + "identificatie" |
| 321 | + ] = "ZAAKTYPE-1" |
| 322 | + review_items[0].destruction_list_item.zaak.save() |
| 323 | + review_items[1].destruction_list_item.zaak._expand["zaaktype"][ |
| 324 | + "identificatie" |
| 325 | + ] = "ZAAKTYPE-1" |
| 326 | + review_items[1].destruction_list_item.zaak.save() |
| 327 | + review_items[2].destruction_list_item.zaak._expand["zaaktype"][ |
| 328 | + "identificatie" |
| 329 | + ] = "ZAAKTYPE-2" |
| 330 | + review_items[2].destruction_list_item.zaak.save() |
| 331 | + |
| 332 | + # These zaaktypen should NOT be returned because they are not in the review |
| 333 | + DestructionListItemReviewFactory.create_batch( |
| 334 | + 3, |
| 335 | + destruction_list_item__with_zaak=True, |
| 336 | + destruction_list_item__zaak__with_expand=True, |
| 337 | + ) |
| 338 | + |
| 339 | + self.client.force_authenticate(user=user) |
| 340 | + endpoint = furl(reverse("api:retrieve-zaaktypen-choices")) |
| 341 | + endpoint.args["review"] = review.pk |
| 342 | + |
| 343 | + response = self.client.get(endpoint.url) |
| 344 | + |
| 345 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 346 | + |
| 347 | + choices = sorted(response.json(), key=lambda choice: choice["label"]) |
| 348 | + |
| 349 | + self.assertEqual(len(choices), 2) |
| 350 | + self.assertEqual(choices[0]["label"], "ZAAKTYPE-1") |
| 351 | + self.assertEqual(choices[1]["label"], "ZAAKTYPE-2") |
| 352 | + |
| 353 | + values = choices[0]["value"].split(",") |
| 354 | + |
| 355 | + self.assertEqual(len(values), 2) |
| 356 | + self.assertIn(review_items[0].destruction_list_item.zaak.zaaktype, values) |
| 357 | + self.assertIn(review_items[1].destruction_list_item.zaak.zaaktype, values) |
| 358 | + |
| 359 | + self.assertEqual( |
| 360 | + choices[1]["value"], review_items[2].destruction_list_item.zaak.zaaktype |
| 361 | + ) |
| 362 | + |
175 | 363 |
|
176 | 364 | class SelectielijstklasseChoicesViewTests(APITestCase):
|
177 | 365 | def setUp(self):
|
|
0 commit comments