|
| 1 | +import uuid |
1 | 2 | from unittest.mock import ANY, patch
|
2 | 3 |
|
3 | 4 | from django.conf import settings
|
4 | 5 | from django.contrib.auth import signals
|
5 | 6 | from django.core import mail
|
6 |
| -from django.test import override_settings |
| 7 | +from django.test import Client, TestCase, override_settings |
7 | 8 | from django.urls import reverse
|
8 | 9 | from django.utils.translation import gettext as _
|
9 | 10 |
|
|
31 | 32 | from open_inwoner.openklant.tests.data import CONTACTMOMENTEN_ROOT, KLANTEN_ROOT
|
32 | 33 | from open_inwoner.openklant.tests.factories import OpenKlant2ConfigFactory
|
33 | 34 | from open_inwoner.openklant.tests.mocks import MockOpenKlant2Service
|
34 |
| -from open_inwoner.openzaak.models import CatalogusConfig, OpenZaakConfig |
| 35 | +from open_inwoner.openzaak.models import ( |
| 36 | + CatalogusConfig, |
| 37 | + OpenZaakConfig, |
| 38 | + ZGWApiGroupConfig, |
| 39 | +) |
35 | 40 | from open_inwoner.openzaak.tests.factories import (
|
36 | 41 | ServiceFactory,
|
37 | 42 | ZaakTypeConfigFactory,
|
@@ -530,6 +535,14 @@ def test_form_success_with_api_esuite(
|
530 | 535 | self._setUpOpenKlantMocks(m)
|
531 | 536 |
|
532 | 537 | response = self.app.get(self.case_detail_url, user=self.user)
|
| 538 | + |
| 539 | + # Set the primary to the opposite API, to ensure we pick the connected |
| 540 | + # backend from the ZGWApiGroup |
| 541 | + self.klant_config.primary_backend = KlantenServiceType.OPENKLANT2.value |
| 542 | + self.klant_config.save() |
| 543 | + self.api_group.klant_backend = KlantenServiceType.ESUITE.value |
| 544 | + self.api_group.save() |
| 545 | + |
533 | 546 | form = response.forms["contact-form"]
|
534 | 547 | form.action = reverse(
|
535 | 548 | "cases:case_detail_contact_form",
|
@@ -595,8 +608,12 @@ def test_form_success_with_api_openklant(
|
595 | 608 | subject="oip_subject",
|
596 | 609 | )
|
597 | 610 |
|
598 |
| - self.klant_config.primary_backend = KlantenServiceType.OPENKLANT2.value |
| 611 | + # Set the primary to the opposite API, to ensure we pick the connected |
| 612 | + # backend from the ZGWApiGroup |
| 613 | + self.klant_config.primary_backend = KlantenServiceType.ESUITE.value |
599 | 614 | self.klant_config.save()
|
| 615 | + self.api_group.klant_backend = KlantenServiceType.OPENKLANT2.value |
| 616 | + self.api_group.save() |
600 | 617 |
|
601 | 618 | response = self.app.get(self.case_detail_url, user=self.user)
|
602 | 619 | form = response.forms["contact-form"]
|
@@ -886,3 +903,34 @@ def test_send_email_confirmation_is_configurable__send_disabled(
|
886 | 903 | form["question"] = "Sample text"
|
887 | 904 | response = form.submit()
|
888 | 905 | mock_send_confirm.assert_not_called()
|
| 906 | + |
| 907 | + |
| 908 | +@override_settings( |
| 909 | + ROOT_URLCONF="open_inwoner.cms.tests.urls", MIDDLEWARE=PATCHED_MIDDLEWARE |
| 910 | +) |
| 911 | +class CasesContactFormInvalidParamsTestCase(TestCase): |
| 912 | + def setUp(self) -> None: |
| 913 | + super().setUp() |
| 914 | + self. user = DigidUserFactory( bsn="900222086", email="[email protected]") |
| 915 | + self.client = Client() |
| 916 | + self.client.force_login(self.user) |
| 917 | + |
| 918 | + def test_non_existent_zgw_api_group_yields_404(self): |
| 919 | + fake_group_id = 8888 |
| 920 | + self.assertFalse(ZGWApiGroupConfig.objects.filter(id=fake_group_id).exists()) |
| 921 | + |
| 922 | + for method in ("get", "post"): |
| 923 | + with self.subTest(method): |
| 924 | + action = getattr(self.client, method) |
| 925 | + response = action( |
| 926 | + reverse( |
| 927 | + "cases:case_detail_contact_form", |
| 928 | + kwargs={ |
| 929 | + "object_id": str(uuid.uuid4()), |
| 930 | + "api_group_id": fake_group_id, |
| 931 | + }, |
| 932 | + ), |
| 933 | + user=self.user, |
| 934 | + ) |
| 935 | + |
| 936 | + self.assertEqual(response.status_code, 404) |
0 commit comments