diff --git a/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py b/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py index 75afb499..98ea1401 100644 --- a/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py +++ b/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py @@ -1,5 +1,3 @@ -import uuid - from django.utils.translation import gettext_lazy as _ from django_filters.rest_framework import FilterSet, filters @@ -8,7 +6,7 @@ DigitaalAdresSerializer, ) from openklant.components.klantinteracties.models.digitaal_adres import DigitaalAdres -from openklant.components.utils.filters import ExpandFilter +from openklant.components.utils.filters import ExpandFilter, URLViewFilter class DigitaalAdresDetailFilterSet(FilterSet): @@ -22,11 +20,11 @@ class DigitaalAdresFilterSet(FilterSet): ), field_name="betrokkene__uuid", ) - verstrekt_door_betrokkene__url = filters.CharFilter( + verstrekt_door_betrokkene__url = URLViewFilter( help_text=_( "Zoek digitaal adres(sen) object(en) op basis van de betrokkene url." ), - method="filter_betrokkene_url", + field_name="betrokkene__uuid", ) verstrekt_door_betrokkene__rol = filters.ChoiceFilter( help_text=_( @@ -36,11 +34,11 @@ class DigitaalAdresFilterSet(FilterSet): ) verstrekt_door_partij__uuid = filters.UUIDFilter( help_text=_("Zoek digitaal adres(sen) object(en) op basis van de partij uuid."), - field_name="betrokkene__uuid", + field_name="partij__uuid", ) - verstrekt_door_partij__url = filters.CharFilter( + verstrekt_door_partij__url = URLViewFilter( help_text=_("Zoek digitaal adres(sen) object(en) op basis van de partij url."), - method="filter_partij_url", + field_name="partij__uuid", ) verstrekt_door_partij__soort_partij = filters.ChoiceFilter( help_text=_( @@ -90,17 +88,3 @@ class Meta: "soort_digitaal_adres", "omschrijving", ) - - def filter_betrokkene_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(betrokkene__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_partij_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(partij__uuid=url_uuid) - except ValueError: - return queryset.none() diff --git a/src/openklant/components/klantinteracties/api/filterset/internetaken.py b/src/openklant/components/klantinteracties/api/filterset/internetaken.py index cb99d757..564296b3 100644 --- a/src/openklant/components/klantinteracties/api/filterset/internetaken.py +++ b/src/openklant/components/klantinteracties/api/filterset/internetaken.py @@ -1,10 +1,9 @@ -import uuid - from django.utils.translation import gettext_lazy as _ from django_filters.rest_framework import FilterSet, filters from openklant.components.klantinteracties.models.internetaken import InterneTaak +from openklant.components.utils.filters import URLViewFilter class InternetaakFilterSet(FilterSet): @@ -12,9 +11,9 @@ class InternetaakFilterSet(FilterSet): help_text=_("Zoek internetaak object op basis van het toegewezen actor uuid."), field_name="actoren__uuid", ) - toegewezen_aan_actor__url = filters.CharFilter( + toegewezen_aan_actor__url = URLViewFilter( help_text=_("Zoek internetaak object op basis van het toegewezen actor url."), - method="filter_toegewezen_aan_actor_url", + field_name="actoren__uuid", ) aanleidinggevend_klantcontact__uuid = filters.UUIDFilter( help_text=_( @@ -22,11 +21,11 @@ class InternetaakFilterSet(FilterSet): ), field_name="klantcontact__uuid", ) - aanleidinggevend_klantcontact__url = filters.CharFilter( + aanleidinggevend_klantcontact__url = URLViewFilter( help_text=_( "Zoek internetaak object op basis van het aanleidingevende klantcontact url." ), - method="filter_aanleidinggevend_klantcontact_url", + field_name="klantcontact__uuid", ) class Meta: @@ -43,17 +42,3 @@ class Meta: "aanleidinggevend_klantcontact__uuid", "aanleidinggevend_klantcontact__url", ) - - def filter_toegewezen_aan_actor_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(actoren__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_aanleidinggevend_klantcontact_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(klantcontact__uuid=url_uuid) - except ValueError: - return queryset.none() diff --git a/src/openklant/components/klantinteracties/api/filterset/klantcontacten.py b/src/openklant/components/klantinteracties/api/filterset/klantcontacten.py index 13b3c69f..9ed5e3e7 100644 --- a/src/openklant/components/klantinteracties/api/filterset/klantcontacten.py +++ b/src/openklant/components/klantinteracties/api/filterset/klantcontacten.py @@ -1,5 +1,3 @@ -import uuid - from django.utils.translation import gettext_lazy as _ from django_filters.rest_framework import FilterSet, filters @@ -12,7 +10,7 @@ Betrokkene, Klantcontact, ) -from openklant.components.utils.filters import ExpandFilter +from openklant.components.utils.filters import ExpandFilter, URLViewFilter class KlantcontactDetailFilterSet(FilterSet): @@ -20,23 +18,31 @@ class KlantcontactDetailFilterSet(FilterSet): class KlantcontactFilterSet(FilterSet): - had_betrokkene__url = filters.CharFilter( + had_betrokkene__url = URLViewFilter( help_text=_("Zoek klantcontact object op basis van het betrokkene url."), - method="filter_betrokkene_url", + field_name="betrokkene__uuid", ) had_betrokkene__uuid = filters.UUIDFilter( help_text=_("Zoek klantcontact object op basis van het betrokkene uuid."), field_name="betrokkene__uuid", ) - onderwerpobject__url = filters.CharFilter( + had_betrokkene__was_partij__url = URLViewFilter( + help_text=_("Zoek klantcontact object op basis van de partij url."), + field_name="betrokkene__partij__uuid", + ) + had_betrokkene__was_partij__uuid = filters.UUIDFilter( + help_text=_("Zoek klantcontact object op basis van de partij uuid."), + field_name="betrokkene__partij__uuid", + ) + onderwerpobject__url = URLViewFilter( help_text=_("Zoek klantcontact object op basis van het onderwerpobject url."), - method="filter_onderwerpobject_url", + field_name="onderwerpobject__uuid", ) - was_onderwerpobject__url = filters.CharFilter( + was_onderwerpobject__url = URLViewFilter( help_text=_( "Zoek was klantcontact object op basis van het onderwerpobject url." ), - method="filter_was_onderwerpobject_url", + field_name="was_onderwerpobject__uuid", ) inhoud = filters.CharFilter( lookup_expr="icontains", @@ -54,6 +60,8 @@ class Meta: fields = ( "had_betrokkene__url", "had_betrokkene__uuid", + "had_betrokkene__was_partij__url", + "had_betrokkene__was_partij__uuid", "onderwerpobject__uuid", "onderwerpobject__url", "onderwerpobject__onderwerpobjectidentificator_code_objecttype", @@ -75,65 +83,44 @@ class Meta: "plaatsgevonden_op", ) - def filter_betrokkene_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(betrokkene__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_onderwerpobject_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(onderwerpobject__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_was_onderwerpobject_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(was_onderwerpobject__uuid=url_uuid) - except ValueError: - return queryset.none() - class BetrokkeneFilterSet(FilterSet): had_klantcontact__nummer = filters.CharFilter( help_text=_("Zoek betrokkene object op basis van het klantcontact nummer"), method="filter_had_klantcontact_nummer", ) - had_klantcontact__url = filters.CharFilter( + had_klantcontact__url = URLViewFilter( help_text=_("Zoek betrokkene object op basis van het klantcontact url"), - method="filter_had_klantcontact_url", + field_name="klantcontact__uuid", ) - had_klantcontact__uuid = filters.CharFilter( + had_klantcontact__uuid = filters.UUIDFilter( help_text=_("Zoek betrokkene object op basis van het klantcontact uuid"), - method="filter_had_klantcontact_uuid", + field_name="klantcontact__uuid", ) verstrektedigitaal_adres__adres = filters.CharFilter( help_text=_("Zoek betrokkene object op basis van het digitaaladres adres"), method="filter_digitaaladres_adres", ) - verstrektedigitaal_adres__url = filters.CharFilter( + verstrektedigitaal_adres__url = URLViewFilter( help_text=_("Zoek betrokkene object op basis van het digitaaladres url"), - method="filter_digitaaladres_url", + field_name="digitaaladres__uuid", ) - verstrektedigitaal_adres__uuid = filters.CharFilter( + verstrektedigitaal_adres__uuid = filters.UUIDFilter( help_text=_("Zoek betrokkene object op basis van het digitaaladres uuid"), - method="filter_digitaaladres_uuid", + field_name="digitaaladres__uuid", ) was_partij__nummer = filters.CharFilter( help_text=_("Zoek betrokkene object op basis van het partij nummer"), method="filter_partij_nummer", ) - was_partij__url = filters.CharFilter( + was_partij__url = URLViewFilter( help_text=_("Zoek betrokkene object op basis van het partij url"), - method="filter_partij_url", + field_name="partij__uuid", ) - was_partij__uuid = filters.CharFilter( + was_partij__uuid = filters.UUIDFilter( help_text=_("Zoek betrokkene object op basis van het partij uuid"), - method="filter_partij_uuid", + field_name="partij__uuid", ) class Meta: @@ -155,20 +142,6 @@ class Meta: "organisatienaam", ) - def filter_had_klantcontact_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(klantcontact__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_had_klantcontact_uuid(self, queryset, name, value): - try: - klantcontact_uuid = uuid.UUID(value) - return queryset.filter(klantcontact__uuid=klantcontact_uuid) - except ValueError: - return queryset.none() - def filter_had_klantcontact_nummer(self, queryset, name, value): try: return queryset.filter(klantcontact__nummer=value) @@ -178,48 +151,20 @@ def filter_had_klantcontact_nummer(self, queryset, name, value): def filter_digitaaladres_adres(self, queryset, name, value): return queryset.filter(digitaaladres__adres=value) - def filter_digitaaladres_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(digitaaladres__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_digitaaladres_uuid(self, queryset, name, value): - try: - digitaaladres_uuid = uuid.UUID(value) - return queryset.filter(digitaaladres__uuid=digitaaladres_uuid) - except ValueError: - return queryset.none() - def filter_partij_nummer(self, queryset, name, value): return queryset.filter(partij__nummer=value) - def filter_partij_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(partij__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_partij_uuid(self, queryset, name, value): - try: - partij_uuid = uuid.UUID(value) - return queryset.filter(partij__uuid=partij_uuid) - except ValueError: - return queryset.none() - class ActorKlantcontactFilterSet(FilterSet): - actor__url = filters.CharFilter( + actor__url = URLViewFilter( help_text=_("Zoek actor klantcontract object op basis van het actor url"), - method="filter_actor_url", + field_name="actor__uuid", ) - klantcontact__url = filters.CharFilter( + klantcontact__url = URLViewFilter( help_text=_( "Zoek actor klantcontract object op basis van het klantcontact url" ), - method="filter_klantcontact_url", + field_name="klantcontact__uuid", ) class Meta: @@ -230,17 +175,3 @@ class Meta: "klantcontact__uuid", "klantcontact__url", ) - - def filter_actor_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(actor__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_klantcontact_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(klantcontact__uuid=url_uuid) - except ValueError: - return queryset.none() diff --git a/src/openklant/components/klantinteracties/api/filterset/partijen.py b/src/openklant/components/klantinteracties/api/filterset/partijen.py index 2c59471c..3825a46e 100644 --- a/src/openklant/components/klantinteracties/api/filterset/partijen.py +++ b/src/openklant/components/klantinteracties/api/filterset/partijen.py @@ -1,5 +1,3 @@ -import uuid - from django.utils.translation import gettext_lazy as _ from django_filters.rest_framework import FilterSet, filters @@ -12,7 +10,7 @@ Partij, Vertegenwoordigden, ) -from openklant.components.utils.filters import ExpandFilter +from openklant.components.utils.filters import ExpandFilter, URLViewFilter class PartijDetailFilterSet(FilterSet): @@ -26,11 +24,11 @@ class PartijFilterSet(FilterSet): ), field_name="vertegenwoordigde__vertegenwoordigende_partij__uuid", ) - vertegenwoordigde_partij__url = filters.CharFilter( + vertegenwoordigde_partij__url = URLViewFilter( help_text=_( "Zoek partij object op basis van het vertegenwoordigde partij url." ), - method="filter_vertegenwoordigde_partij_url", + field_name="vertegenwoordigde__vertegenwoordigende_partij__uuid", ) partij_identificator__code_objecttype = filters.CharFilter( help_text=_( @@ -90,15 +88,6 @@ class Meta: "correspondentieadres_land", ) - def filter_vertegenwoordigde_partij_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter( - vertegenwoordigde__vertegenwoordigende_partij__uuid=url_uuid - ) - except ValueError: - return queryset.none() - def filter_identificator_code_objecttype(self, queryset, name, value): try: return queryset.filter( @@ -142,17 +131,17 @@ def filter_categorierelatie_categorie_naam(self, queryset, name, value): class VertegenwoordigdenFilterSet(FilterSet): - vertegenwoordigende_partij__url = filters.CharFilter( + vertegenwoordigende_partij__url = URLViewFilter( help_text=_( "Zoek Vertegenwoordigden object op basis van het vertegenwoordigende partij url." ), - method="filter_vertegenwoordigende_partij_url", + field_name="vertegenwoordigende_partij__uuid", ) - vertegenwoordigde_partij__url = filters.CharFilter( + vertegenwoordigde_partij__url = URLViewFilter( help_text=_( "Zoek Vertegenwoordigden object op basis van het vertegenwoordigde partij url." ), - method="filter_vertegenwoordigde_partij_url", + field_name="vertegenwoordigde_partij__uuid", ) class Meta: @@ -164,29 +153,14 @@ class Meta: "vertegenwoordigde_partij__url", ) - def filter_vertegenwoordigende_partij_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(vertegenwoordigende_partij__uuid=url_uuid) - except ValueError: - return queryset.none() - - def filter_vertegenwoordigde_partij_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(vertegenwoordigde_partij__uuid=url_uuid) - except ValueError: - return queryset.none() - class CategorieRelatieFilterSet(FilterSet): - partij__url = filters.CharFilter( + partij__url = URLViewFilter( help_text=_("Zoek categorie relatie object op basis van de partij url."), - method="filter_partij_url", + field_name="partij__uuid", ) - partij__uuid = filters.CharFilter( + partij__uuid = filters.UUIDFilter( help_text=_("Zoek categorie relatie object op basis van de partij uuid."), - method="filter_partij_uuid", ) partij__nummer = filters.CharFilter( help_text=_("Zoek categorie relatie object op basis van het partij nummer."), @@ -196,13 +170,12 @@ class CategorieRelatieFilterSet(FilterSet): help_text=_("Zoek categorie relatie object op basis van de categorie naam."), method="filter_categorie_naam", ) - categorie__uuid = filters.CharFilter( + categorie__uuid = filters.UUIDFilter( help_text=_("Zoek categorie relatie object op basis van de categorie uuid."), - method="filter_categorie_uuid", ) - categorie__url = filters.CharFilter( + categorie__url = URLViewFilter( help_text=_("Zoek categorie relatie object op basis van de categorie url."), - method="filter_categorie_url", + field_name="categorie__uuid", ) class Meta: @@ -218,40 +191,12 @@ class Meta: "eind_datum", ) - def filter_partij_uuid(self, queryset, name, value): - try: - partij_uuid = uuid.UUID(value) - return queryset.filter(partij__uuid=partij_uuid) - except ValueError: - return queryset.none() - - def filter_partij_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(partij__uuid=url_uuid) - except ValueError: - return queryset.none() - def filter_partij_nummer(self, queryset, name, value): try: return queryset.filter(partij__nummer=value) except ValueError: return queryset.none() - def filter_categorie_uuid(self, queryset, name, value): - try: - categorie_uuid = uuid.UUID(value) - return queryset.filter(categorie__uuid=categorie_uuid) - except ValueError: - return queryset.none() - - def filter_categorie_url(self, queryset, name, value): - try: - url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1]) - return queryset.filter(categorie__uuid=url_uuid) - except ValueError: - return queryset.none() - def filter_categorie_naam(self, queryset, name, value): try: return queryset.filter(categorie__naam=value) diff --git a/src/openklant/components/klantinteracties/api/tests/test_filters.py b/src/openklant/components/klantinteracties/api/tests/test_filters.py index b61ebf66..958aa702 100644 --- a/src/openklant/components/klantinteracties/api/tests/test_filters.py +++ b/src/openklant/components/klantinteracties/api/tests/test_filters.py @@ -31,148 +31,249 @@ class KlantcontactFilterSetTests(APITestCase): url = reverse("klantinteracties:klantcontact-list") - def setUp(self): - super().setUp() - ( - self.klantcontact, - self.klantcontact2, - self.klantcontact3, - self.klantcontact4, - self.klantcontact5, - ) = KlantcontactFactory.create_batch(5) - for betrokkene_klantcontact in [ - self.klantcontact, - self.klantcontact2, - self.klantcontact3, - self.klantcontact4, - self.klantcontact5, - ]: - self.betrokkene = BetrokkeneFactory.create( - klantcontact=betrokkene_klantcontact - ) - - self.onderwerpobject = OnderwerpobjectFactory.create( - klantcontact=self.klantcontact, - was_klantcontact=self.klantcontact5, - onderwerpobjectidentificator_code_objecttype="1", - onderwerpobjectidentificator_code_soort_object_id="1", - onderwerpobjectidentificator_object_id="1", - onderwerpobjectidentificator_code_register="1", - ) - self.onderwerpobject2 = OnderwerpobjectFactory.create( - klantcontact=self.klantcontact2, - was_klantcontact=self.klantcontact, - onderwerpobjectidentificator_code_objecttype="2", - onderwerpobjectidentificator_code_soort_object_id="2", - onderwerpobjectidentificator_object_id="2", - onderwerpobjectidentificator_code_register="2", - ) - self.onderwerpobject3 = OnderwerpobjectFactory.create( - klantcontact=self.klantcontact3, - was_klantcontact=self.klantcontact2, - onderwerpobjectidentificator_code_objecttype="3", - onderwerpobjectidentificator_code_soort_object_id="3", - onderwerpobjectidentificator_object_id="3", - onderwerpobjectidentificator_code_register="3", - ) - self.onderwerpobject4 = OnderwerpobjectFactory.create( - klantcontact=self.klantcontact4, - was_klantcontact=self.klantcontact3, - onderwerpobjectidentificator_code_objecttype="4", - onderwerpobjectidentificator_code_soort_object_id="4", - onderwerpobjectidentificator_object_id="4", - onderwerpobjectidentificator_code_register="4", - ) - self.onderwerpobject5 = OnderwerpobjectFactory.create( - klantcontact=self.klantcontact5, - was_klantcontact=self.klantcontact4, - onderwerpobjectidentificator_code_objecttype="5", - onderwerpobjectidentificator_code_soort_object_id="5", - onderwerpobjectidentificator_object_id="5", - onderwerpobjectidentificator_code_register="5", - ) + def test_filter_partij_url(self): + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + partij = PartijFactory.create() + partij2 = PartijFactory.create() + BetrokkeneFactory.create(klantcontact=klantcontact, partij=partij) + BetrokkeneFactory.create(klantcontact=klantcontact2, partij=partij2) + + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url + + response = self.client.get( + self.url, + {"hadBetrokkene__wasPartij__url": full_partij_url}, + ) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(klantcontact.uuid), data[0]["uuid"]) + + with self.subTest("no_matches_found_return_nothing"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} + ) + fake_party_url = "https://testserver.com" + partij_detail_url + + response = self.client.get( + self.url, + {"hadBetrokkene__wasPartij__url": fake_party_url}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + self.assertEqual(response.json()["count"], 0) + + with self.subTest("no url as value restults in 400"): + response = self.client.get(self.url, {"hadBetrokkene__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_party_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"hadBetrokkene__wasPartij__url": fake_party_url}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + self.assertEqual(response.json()["count"], 0) + + def test_filter_partij_uuid(self): + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + partij = PartijFactory.create() + partij2 = PartijFactory.create() + BetrokkeneFactory.create(klantcontact=klantcontact, partij=partij) + BetrokkeneFactory.create(klantcontact=klantcontact2, partij=partij2) - def test_filter_betrokkene_url(self): response = self.client.get( self.url, - { - "hadBetrokkene__url": f"http://testserver/klantinteracties/api/v1/klantcontact/{self.betrokkene.uuid}" - }, + {"hadBetrokkene__wasPartij__uuid": str(partij.uuid)}, ) data = response.json()["results"] self.assertEqual(1, len(data)) - self.assertEqual(str(self.klantcontact5.uuid), data[0]["uuid"]) + self.assertEqual(str(klantcontact.uuid), data[0]["uuid"]) + + def test_filter_betrokkene_url(self): + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + betrokkene = BetrokkeneFactory.create(klantcontact=klantcontact) + BetrokkeneFactory.create(klantcontact=klantcontact2) + + with self.subTest("happy flow"): + betrokkene_detail_url = reverse( + "klantinteracties:betrokkene-detail", + kwargs={"uuid": str(betrokkene.uuid)}, + ) + full_betrokkene_url = "https://testserver.com" + betrokkene_detail_url + + response = self.client.get( + self.url, + {"hadBetrokkene__url": full_betrokkene_url}, + ) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(klantcontact.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + betrokkene_detail_url = reverse( + "klantinteracties:betrokkene-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_betrokkene_url = "https://testserver.com" + betrokkene_detail_url + response = self.client.get( self.url, - { - "hadBetrokkene__url": f"http://testserver/klantinteracties/api/v1/klantcontact/{str(uuid4())}" - }, + {"hadBetrokkene__url": fake_betrokkene_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"hadBetrokkene__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + betrokkene_list_url = reverse("klantinteracties:betrokkene-list") + fake_betrokkene_url = ( + "https://testserver.com" + betrokkene_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"hadBetrokkene__url": fake_betrokkene_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_onderwerpobject__url(self): - url = f"http://testserver/klantinteracties/api/v1/onderwerpobjecten/{self.onderwerpobject5.uuid}" - response = self.client.get( - self.url, - {"onderwerpobject__url": url}, - ) - data = response.json()["results"] + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + OnderwerpobjectFactory.create(klantcontact=klantcontact) + onderwerpobject2 = OnderwerpobjectFactory.create(klantcontact=klantcontact2) + + with self.subTest("happy flow"): + onderwerpobject_detail_url = reverse( + "klantinteracties:onderwerpobject-detail", + kwargs={"uuid": str(onderwerpobject2.uuid)}, + ) + full_onderwerpobject_url = ( + "https://testserver.com" + onderwerpobject_detail_url + ) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.klantcontact5.uuid), data[0]["uuid"]) + response = self.client.get( + self.url, + {"onderwerpobject__url": full_onderwerpobject_url}, + ) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(klantcontact2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - url = f"http://testserver/klantinteracties/api/v1/onderwerpobjecten/{str(uuid4())}" + onderwerpobject_detail_url = reverse( + "klantinteracties:onderwerpobject-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_onderwerpobject_url = ( + "https://testserver.com" + onderwerpobject_detail_url + ) + response = self.client.get( self.url, - {"onderwerpobject__url": url}, + {"onderwerpobject__url": fake_onderwerpobject_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"onderwerpobject__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + onderwerpobject_list_url = reverse("klantinteracties:onderwerpobject-list") + fake_onderwerpobject_url = ( + "https://testserver.com" + onderwerpobject_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"onderwerpobject__url": fake_onderwerpobject_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_was_onderwerpobject__url(self): - url = f"http://testserver/klantinteracties/api/v1/onderwerpobjecten/{self.onderwerpobject5.uuid}" - response = self.client.get( - self.url, - {"wasOnderwerpobject__url": url}, - ) - data = response.json()["results"] + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + OnderwerpobjectFactory.create(was_klantcontact=klantcontact) + onderwerpobject2 = OnderwerpobjectFactory.create(was_klantcontact=klantcontact2) + + with self.subTest("happy flow"): + was_onderwerpobject_detail_url = reverse( + "klantinteracties:onderwerpobject-detail", + kwargs={"uuid": str(onderwerpobject2.uuid)}, + ) + full_was_onderwerpobject_url = ( + "https://testserver.com" + was_onderwerpobject_detail_url + ) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.klantcontact4.uuid), data[0]["uuid"]) + response = self.client.get( + self.url, + {"wasOnderwerpobject__url": full_was_onderwerpobject_url}, + ) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(klantcontact2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - url = f"http://testserver/klantinteracties/api/v1/onderwerpobjecten/{str(uuid4())}" + was_onderwerpobject_detail_url = reverse( + "klantinteracties:onderwerpobject-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_was_onderwerpobject_url = ( + "https://testserver.com" + was_onderwerpobject_detail_url + ) + response = self.client.get( self.url, - {"wasOnderwerpobject__url": url}, + {"wasOnderwerpobject__url": fake_was_onderwerpobject_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"wasOnderwerpobject__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + was_onderwerpobject_list_url = reverse( + "klantinteracties:onderwerpobject-list" + ) + fake_was_onderwerpobject_url = ( + "https://testserver.com" + was_onderwerpobject_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"wasOnderwerpobject__url": fake_was_onderwerpobject_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) @@ -181,74 +282,80 @@ def test_filter_was_onderwerpobject__url(self): class BetrokkeneFilterSetTests(APITestCase): url = reverse("klantinteracties:betrokkene-list") - def setUp(self): - super().setUp() - self.klantcontact = KlantcontactFactory.create(nummer="6237172371") - self.partij = PartijFactory.create(nummer="8123973457") - self.betrokkene = BetrokkeneFactory.create( - partij=self.partij, klantcontact=self.klantcontact - ) - self.digitaal_adres = DigitaalAdresFactory.create( - betrokkene=self.betrokkene, adres="search_param_adres" - ) - - partij2 = PartijFactory.create() - betrokkene2 = BetrokkeneFactory.create(partij=partij2) - DigitaalAdresFactory.create(betrokkene=betrokkene2) - - partij3 = PartijFactory.create() - betrokkene3 = BetrokkeneFactory.create(partij=partij3) - DigitaalAdresFactory.create(betrokkene=betrokkene3) - - partij4 = PartijFactory.create() - betrokkene4 = BetrokkeneFactory.create(partij=partij4) - DigitaalAdresFactory.create(betrokkene=betrokkene4) - - partij5 = PartijFactory.create() - betrokkene5 = BetrokkeneFactory.create(partij=partij5) - DigitaalAdresFactory.create(betrokkene=betrokkene5) - def test_filter_had_klantcontact_url(self): - klantcontact_url = f"http://testserver/klantinteracties/api/v1/klantcontact/{self.klantcontact.uuid}" - response = self.client.get( - self.url, - {"hadKlantcontact__url": klantcontact_url}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + betrokkene = BetrokkeneFactory.create(klantcontact=klantcontact) + BetrokkeneFactory.create(klantcontact=klantcontact2) + + with self.subTest("happy flow"): + klantcontact_detail_url = reverse( + "klantinteracties:klantcontact-detail", + kwargs={"uuid": str(klantcontact.uuid)}, + ) + full_klantcontact_url = "https://testserver.com" + klantcontact_detail_url - data = response.json()["results"] + response = self.client.get( + self.url, + {"hadKlantcontact__url": full_klantcontact_url}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + klantcontact_detail_url = reverse( + "klantinteracties:klantcontact-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_klantcontact_url = "https://testserver.com" + klantcontact_detail_url + response = self.client.get( self.url, - { - "hadKlantcontact__url": f"http://testserver/klantinteracties/api/v1/klantcontact/{str(uuid4())}" - }, + {"hadKlantcontact__url": fake_klantcontact_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"hadKlantcontact__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + klantcontact_list_url = reverse("klantinteracties:klantcontact-list") + fake_klantcontact_url = ( + "https://testserver.com" + klantcontact_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"hadKlantcontact__url": fake_klantcontact_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_had_klantcontact_uuid(self): - response = self.client.get( - self.url, - {"hadKlantcontact__uuid": str(self.klantcontact.uuid)}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + betrokkene = BetrokkeneFactory.create(klantcontact=klantcontact) + BetrokkeneFactory.create(klantcontact=klantcontact2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"hadKlantcontact__uuid": str(klantcontact.uuid)}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -259,25 +366,29 @@ def test_filter_had_klantcontact_uuid(self): self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"hadKlantcontact__uuid": "ValueError"} ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - - self.assertEqual(response.json()["count"], 0) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_filter_had_klantcontact_nummer(self): - response = self.client.get( - self.url, - {"hadKlantcontact__nummer": str(6237172371)}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + klantcontact = KlantcontactFactory.create(nummer="6237172371") + klantcontact2 = KlantcontactFactory.create(nummer="9999999999") + betrokkene = BetrokkeneFactory.create(klantcontact=klantcontact) + BetrokkeneFactory.create(klantcontact=klantcontact2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"hadKlantcontact__nummer": str(6237172371)}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -289,47 +400,85 @@ def test_filter_had_klantcontact_nummer(self): self.assertEqual(response.json()["count"], 0) def test_filter_verstrektedigitaal_adres_url(self): - digitaal_adres_url = f"http://testserver/klantinteracties/api/v1/digitaal_adres/{self.digitaal_adres.uuid}" - response = self.client.get( - self.url, - {"verstrektedigitaalAdres__url": digitaal_adres_url}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + betrokkene = BetrokkeneFactory.create() + betrokkene2 = BetrokkeneFactory.create() + digitaal_adres = DigitaalAdresFactory.create(betrokkene=betrokkene) + DigitaalAdresFactory.create(betrokkene=betrokkene2) - data = response.json()["results"] + with self.subTest("happy flow"): + digitaal_adres_detail_url = reverse( + "klantinteracties:digitaaladres-detail", + kwargs={"uuid": str(digitaal_adres.uuid)}, + ) + full_digitaal_adres_url = ( + "https://testserver.com" + digitaal_adres_detail_url + ) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + response = self.client.get( + self.url, + {"verstrektedigitaalAdres__url": full_digitaal_adres_url}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - none_existing_url = f"http://testserver/klantinteracties/api/v1/digitaal_adres/{str(uuid4())}" + digitaal_adres_detail_url = reverse( + "klantinteracties:digitaaladres-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_digitaal_adres_url = ( + "https://testserver.com" + digitaal_adres_detail_url + ) + response = self.client.get( self.url, - {"verstrektedigitaalAdres__url": none_existing_url}, + {"verstrektedigitaalAdres__url": fake_digitaal_adres_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"verstrektedigitaalAdres__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + digitaaladres_list_url = reverse("klantinteracties:digitaaladres-list") + fake_digitaaladres_url = ( + "https://testserver.com" + digitaaladres_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"verstrektedigitaalAdres__url": fake_digitaaladres_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_verstrektedigitaal_adres_uuid(self): - response = self.client.get( - self.url, - {"verstrektedigitaalAdres__uuid": str(self.digitaal_adres.uuid)}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + betrokkene = BetrokkeneFactory.create() + betrokkene2 = BetrokkeneFactory.create() + digitaal_adres = DigitaalAdresFactory.create(betrokkene=betrokkene) + DigitaalAdresFactory.create(betrokkene=betrokkene2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"verstrektedigitaalAdres__uuid": str(digitaal_adres.uuid)}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -340,25 +489,29 @@ def test_filter_verstrektedigitaal_adres_uuid(self): self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"verstrektedigitaalAdres__uuid": "ValueError"} ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - - self.assertEqual(response.json()["count"], 0) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_filter_verstrektedigitaal_adres_adres(self): - response = self.client.get( - self.url, - {"verstrektedigitaalAdres__adres": "search_param_adres"}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + betrokkene = BetrokkeneFactory.create() + betrokkene2 = BetrokkeneFactory.create() + DigitaalAdresFactory.create(betrokkene=betrokkene, adres="search_param_adres") + DigitaalAdresFactory.create(betrokkene=betrokkene2, adres="whatever") - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"verstrektedigitaalAdres__adres": "search_param_adres"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -370,47 +523,72 @@ def test_filter_verstrektedigitaal_adres_adres(self): self.assertEqual(response.json()["count"], 0) def test_filter_was_partij_url(self): - response = self.client.get( - self.url, - { - "wasPartij__url": f"http://testserver/klantinteracties/api/v1/partij/{self.partij.uuid}" - }, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - - data = response.json()["results"] + partij = PartijFactory.create() + partij2 = PartijFactory.create() + betrokkene = BetrokkeneFactory.create(partij=partij) + BetrokkeneFactory.create(partij=partij2) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url - with self.subTest("no_matches_found_return_nothing"): response = self.client.get( self.url, - { - "wasPartij__url": f"http://testserver/klantinteracties/api/v1/partij/{str(uuid4())}" - }, + {"wasPartij__url": full_partij_url}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) + + with self.subTest("no_matches_found_return_nothing"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} ) + fake_partij_url = "https://testserver.com" + partij_detail_url + + response = self.client.get(self.url, {"wasPartij__url": fake_partij_url}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"wasPartij__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_partij_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"wasPartij__url": fake_partij_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_was_partij_uuid(self): - response = self.client.get( - self.url, - {"wasPartij__uuid": str(self.partij.uuid)}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij = PartijFactory.create() + partij2 = PartijFactory.create() + betrokkene = BetrokkeneFactory.create(partij=partij) + BetrokkeneFactory.create(partij=partij2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"wasPartij__uuid": str(partij.uuid)}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -421,23 +599,27 @@ def test_filter_was_partij_uuid(self): self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"wasPartij__uuid": "ValueError"}) - self.assertEqual(response.status_code, status.HTTP_200_OK) - - self.assertEqual(response.json()["count"], 0) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_filter_was_partij_nummer(self): - response = self.client.get( - self.url, - {"wasPartij__nummer": "8123973457"}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij = PartijFactory.create(nummer="8123973457") + partij2 = PartijFactory.create(nummer="9999999999") + betrokkene = BetrokkeneFactory.create(partij=partij) + BetrokkeneFactory.create(partij=partij2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"wasPartij__nummer": "8123973457"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.betrokkene.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(betrokkene.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -452,117 +634,83 @@ def test_filter_was_partij_nummer(self): class PartijFilterSetTests(APITestCase): url = reverse("klantinteracties:partij-list") - def setUp(self): - super().setUp() - self.partij = PartijFactory.create(nummer="1111111111") - self.partij2 = PartijFactory.create(nummer="2222222222") - self.partij3 = PartijFactory.create(nummer="3333333333") - self.partij4 = PartijFactory.create(nummer="4444444444") - self.partij5 = PartijFactory.create(nummer="5555555555") - - for partij_obj in [ - self.partij, - self.partij2, - self.partij3, - self.partij4, - self.partij5, - ]: - self.partij_identificator = PartijIdentificatorFactory.create( - partij=partij_obj, - partij_identificator_code_objecttype=f"objecttype-{partij_obj.nummer}", - partij_identificator_code_soort_object_id=f"soort-object-id-{partij_obj.nummer}", - partij_identificator_object_id=f"object-id-{partij_obj.nummer}", - partij_identificator_code_register=f"register-{partij_obj.nummer}", - ) - - self.vertegenwoordigde = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij, - vertegenwoordigde_partij=self.partij2, - ) - self.vertegenwoordigde2 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij2, - vertegenwoordigde_partij=self.partij3, - ) - self.vertegenwoordigde3 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij3, - vertegenwoordigde_partij=self.partij4, - ) - self.vertegenwoordigde4 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij4, - vertegenwoordigde_partij=self.partij5, + def test_filter_vertegenwoordigde_partij_url(self): + partij, partij2, partij3, partij4 = PartijFactory.create_batch(4) + VertegenwoordigdenFactory.create( + vertegenwoordigende_partij=partij, vertegenwoordigde_partij=partij3 ) - self.vertegenwoordigde5 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij5, - vertegenwoordigde_partij=self.partij, + VertegenwoordigdenFactory.create( + vertegenwoordigende_partij=partij2, vertegenwoordigde_partij=partij4 ) - self.categorie = CategorieFactory.create(naam="een") - self.categorie2 = CategorieFactory.create(naam="twee") - self.categorie3 = CategorieFactory.create(naam="drie") - self.categorie4 = CategorieFactory.create(naam="vier") - self.categorie5 = CategorieFactory.create(naam="vijf") - - self.categorie_relatie = CategorieRelatieFactory.create( - partij=self.partij, categorie=self.categorie - ) - self.categorie_relatie2 = CategorieRelatieFactory.create( - partij=self.partij2, categorie=self.categorie2 - ) - self.categorie_relatie3 = CategorieRelatieFactory.create( - partij=self.partij3, categorie=self.categorie3 - ) - self.categorie_relatie4 = CategorieRelatieFactory.create( - partij=self.partij4, categorie=self.categorie4 - ) - self.categorie_relatie5 = CategorieRelatieFactory.create( - partij=self.partij5, categorie=self.categorie5 - ) + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url - def test_filter_vertegenwoordigde_partij_url(self): - partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}" - response = self.client.get( - self.url, {"vertegenwoordigdePartij__url": partij_url} - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + response = self.client.get( + self.url, {"vertegenwoordigdePartij__url": full_partij_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.json()["results"] + data = response.json()["results"] - self.assertEqual(1, len(data)) - self.assertEqual(str(self.partij.uuid), data[0]["uuid"]) + self.assertEqual(1, len(data)) + self.assertEqual(str(partij3.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - partij_url = ( - f"http://testserver/klantinteracties/api/v1/partijen/{str(uuid4())}" + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} ) + fake_partij_url = "https://testserver.com" + partij_detail_url + response = self.client.get( self.url, - {"vertegenwoordigdePartij__url": partij_url}, + {"vertegenwoordigdePartij__url": fake_partij_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"vertegenwoordigdePartij__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_partij_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"vertegenwoordigdePartij__url": fake_partij_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - def test_filter_partij_identificator_nummer(self): - response = self.client.get( - self.url, - { - "partijIdentificator__codeObjecttype": f"objecttype-{self.partij5.nummer}" - }, + def test_filter_partij_identificator_code_objecttype(self): + partij, partij2 = PartijFactory.create_batch(2) + PartijIdentificatorFactory.create( + partij=partij, partij_identificator_code_objecttype="one" + ) + PartijIdentificatorFactory.create( + partij=partij2, partij_identificator_code_objecttype="two" ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"partijIdentificator__codeObjecttype": "two"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.partij5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(partij2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -574,18 +722,25 @@ def test_filter_partij_identificator_nummer(self): self.assertEqual(response.json()["count"], 0) def test_filter_identificator_soort_object_id(self): - response = self.client.get( - self.url, - { - "partijIdentificator__codeSoortObjectId": f"soort-object-id-{self.partij5.nummer}" - }, + partij, partij2 = PartijFactory.create_batch(2) + PartijIdentificatorFactory.create( + partij=partij, partij_identificator_code_soort_object_id="one" + ) + PartijIdentificatorFactory.create( + partij=partij2, partij_identificator_code_soort_object_id="two" ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"partijIdentificator__codeSoortObjectId": "one"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.partij5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(partij.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -599,16 +754,25 @@ def test_filter_identificator_soort_object_id(self): self.assertEqual(response.json()["count"], 0) def test_filter_identificator_object_id(self): - response = self.client.get( - self.url, - {"partijIdentificator__objectId": f"object-id-{self.partij5.nummer}"}, + partij, partij2 = PartijFactory.create_batch(2) + PartijIdentificatorFactory.create( + partij=partij, partij_identificator_object_id="one" + ) + PartijIdentificatorFactory.create( + partij=partij2, partij_identificator_object_id="two" ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"partijIdentificator__objectId": "one"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.partij5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(partij.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -619,17 +783,26 @@ def test_filter_identificator_object_id(self): self.assertEqual(response.json()["count"], 0) - def test_filter_identificator_register(self): - response = self.client.get( - self.url, - {"partijIdentificator__codeRegister": f"register-{self.partij5.nummer}"}, + def test_filter_identificator_code_register(self): + partij, partij2 = PartijFactory.create_batch(2) + PartijIdentificatorFactory.create( + partij=partij, partij_identificator_code_register="one" + ) + PartijIdentificatorFactory.create( + partij=partij2, partij_identificator_code_register="two" ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"partijIdentificator__code_register": "two"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.partij5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(partij2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -641,16 +814,23 @@ def test_filter_identificator_register(self): self.assertEqual(response.json()["count"], 0) def test_filter_categorie_relaties_categorie_naam(self): - response = self.client.get( - self.url, - {"categorierelatie__categorie__naam": self.categorie5.naam}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij, partij2 = PartijFactory.create_batch(2) + categorie = CategorieFactory.create(naam="one") + categorie2 = CategorieFactory.create(naam="two") + CategorieRelatieFactory.create(partij=partij, categorie=categorie) + CategorieRelatieFactory.create(partij=partij2, categorie=categorie2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"categorierelatie__categorie__naam": "two"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.partij5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(partij2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -664,90 +844,85 @@ def test_filter_categorie_relaties_categorie_naam(self): with self.subTest("search_based_on_multiple_categorie_namen"): response = self.client.get( self.url, - { - "categorierelatie__categorie__naam": f"{self.categorie.naam},{self.categorie2.naam}" - }, + {"categorierelatie__categorie__naam": "one,two"}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json()["results"] - self.assertEqual(2, len(data)) - self.assertEqual(str(self.partij2.uuid), data[0]["uuid"]) - self.assertEqual(str(self.partij.uuid), data[1]["uuid"]) - - -class CategorieRelatieFiltersetTests(APITestCase): - url = reverse("klantinteracties:categorierelatie-list") - - def setUp(self): - super().setUp() - self.partij = PartijFactory.create(nummer="1111111111") - self.partij2 = PartijFactory.create(nummer="2222222222") - self.partij3 = PartijFactory.create(nummer="3333333333") - self.partij4 = PartijFactory.create(nummer="4444444444") - self.partij5 = PartijFactory.create(nummer="5555555555") - - self.categorie = CategorieFactory.create(naam="een") - self.categorie2 = CategorieFactory.create(naam="twee") - self.categorie3 = CategorieFactory.create(naam="drie") - self.categorie4 = CategorieFactory.create(naam="vier") - self.categorie5 = CategorieFactory.create(naam="vijf") - - self.categorie_relatie = CategorieRelatieFactory.create( - partij=self.partij, categorie=self.categorie - ) - self.categorie_relatie2 = CategorieRelatieFactory.create( - partij=self.partij2, categorie=self.categorie2 - ) - self.categorie_relatie3 = CategorieRelatieFactory.create( - partij=self.partij3, categorie=self.categorie3 - ) - self.categorie_relatie4 = CategorieRelatieFactory.create( - partij=self.partij4, categorie=self.categorie4 - ) - self.categorie_relatie5 = CategorieRelatieFactory.create( - partij=self.partij5, categorie=self.categorie5 - ) + self.assertEqual(2, len(data)) + self.assertEqual(str(partij2.uuid), data[0]["uuid"]) + self.assertEqual(str(partij.uuid), data[1]["uuid"]) + + +class CategorieRelatieFiltersetTests(APITestCase): + url = reverse("klantinteracties:categorierelatie-list") def test_filter_partij_url(self): - partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}" - response = self.client.get(self.url, {"partij__url": partij_url}) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij, partij2 = PartijFactory.create_batch(2) + CategorieRelatieFactory.create(partij=partij) + categorie_relatie2 = CategorieRelatieFactory.create(partij=partij2) - data = response.json()["results"] + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij2.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url - self.assertEqual(1, len(data)) - self.assertEqual(str(self.categorie_relatie5.uuid), data[0]["uuid"]) + response = self.client.get(self.url, {"partij__url": full_partij_url}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(categorie_relatie2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} + ) + fake_partij_url = "https://testserver.com" + partij_detail_url + response = self.client.get( self.url, - { - "partij__url": f"http://testserver/klantinteracties/api/v1/partijen/{str(uuid4())}" - }, + {"partij__url": fake_partij_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"partij__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_partij_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"partij__url": fake_partij_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_partij_uuid(self): - response = self.client.get( - self.url, - {"partij__uuid": str(self.partij5.uuid)}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij, partij2 = PartijFactory.create_batch(2) + categorie_relatie = CategorieRelatieFactory.create(partij=partij) + CategorieRelatieFactory.create(partij=partij2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"partij__uuid": str(partij.uuid)}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.categorie_relatie5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(categorie_relatie.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -758,23 +933,27 @@ def test_filter_partij_uuid(self): self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"partij__uuid": "ValueError"}) - self.assertEqual(response.status_code, status.HTTP_200_OK) - - self.assertEqual(response.json()["count"], 0) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_filter_partij_nummer(self): - response = self.client.get( - self.url, - {"partij__nummer": "5555555555"}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij = PartijFactory.create(nummer="1111111111") + partij2 = PartijFactory.create(nummer="2222222222") + categorie_relatie = CategorieRelatieFactory.create(partij=partij) + CategorieRelatieFactory.create(partij=partij2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"partij__nummer": "1111111111"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.categorie_relatie5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(categorie_relatie.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -786,43 +965,77 @@ def test_filter_partij_nummer(self): self.assertEqual(response.json()["count"], 0) def test_filter_categorie_url(self): - categorie_url = f"http://testserver/klantinteracties/api/v1/categorieen/{str(self.categorie5.uuid)}" - response = self.client.get(self.url, {"categorie__url": categorie_url}) - self.assertEqual(response.status_code, status.HTTP_200_OK) + categorie = CategorieFactory.create() + categorie2 = CategorieFactory.create() + categorie_relatie = CategorieRelatieFactory.create(categorie=categorie) + CategorieRelatieFactory.create(categorie=categorie2) + + with self.subTest("happy flow"): + categorie_detail_url = reverse( + "klantinteracties:categorie-detail", + kwargs={"uuid": str(categorie.uuid)}, + ) + full_categorie_url = "https://testserver.com" + categorie_detail_url - data = response.json()["results"] + response = self.client.get(self.url, {"categorie__url": full_categorie_url}) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.categorie_relatie5.uuid), data[0]["uuid"]) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(categorie_relatie.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + categorie_detail_url = reverse( + "klantinteracties:categorie-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_categorie_url = "https://testserver.com" + categorie_detail_url + response = self.client.get( self.url, - { - "categorie__url": f"http://testserver/klantinteracties/api/v1/categorieen/{str(uuid4())}" - }, + {"categorie__url": fake_categorie_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"categorie__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + categorie_list_url = reverse("klantinteracties:categorie-list") + fake_categorie_url = ( + "https://testserver.com" + categorie_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"categorie__url": fake_categorie_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_categorie_uuid(self): - response = self.client.get( - self.url, - {"categorie__uuid": str(self.categorie5.uuid)}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + categorie = CategorieFactory.create() + categorie2 = CategorieFactory.create() + categorie_relatie = CategorieRelatieFactory.create(categorie=categorie) + CategorieRelatieFactory.create(categorie=categorie2) - data = response.json()["results"] + with self.subTest("happy flow"): + response = self.client.get( + self.url, + {"categorie__uuid": str(categorie.uuid)}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.categorie_relatie5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(categorie_relatie.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -833,23 +1046,28 @@ def test_filter_categorie_uuid(self): self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"categorie__uuid": "ValueError"}) - self.assertEqual(response.status_code, status.HTTP_200_OK) - - self.assertEqual(response.json()["count"], 0) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_filter_categorie_naam(self): - response = self.client.get( - self.url, - {"categorie__naam": "vijf"}, - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + categorie = CategorieFactory.create(naam="one") + categorie2 = CategorieFactory.create(naam="two") + CategorieRelatieFactory.create(categorie=categorie) + categorie_relatie2 = CategorieRelatieFactory.create(categorie=categorie2) - data = response.json()["results"] + with self.subTest("happy flow"): - self.assertEqual(1, len(data)) - self.assertEqual(str(self.categorie_relatie5.uuid), data[0]["uuid"]) + response = self.client.get( + self.url, + {"categorie__naam": "two"}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(categorie_relatie2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): response = self.client.get( @@ -864,91 +1082,116 @@ def test_filter_categorie_naam(self): class ActorKlantcontactFilterSetTests(APITestCase): url = reverse("klantinteracties:actorklantcontact-list") - def setUp(self): - super().setUp() - ( - self.actor, - self.actor2, - self.actor3, - self.actor4, - self.actor5, - ) = ActorFactory.create_batch(5) - ( - self.klantcontact, - self.klantcontact2, - self.klantcontact3, - self.klantcontact4, - self.klantcontact5, - ) = KlantcontactFactory.create_batch(5) - - self.actor_klantcontact = ActorKlantcontactFactory.create( - actor=self.actor, klantcontact=self.klantcontact - ) - self.actor_klantcontact2 = ActorKlantcontactFactory.create( - actor=self.actor2, klantcontact=self.klantcontact2 - ) - self.actor_klantcontact3 = ActorKlantcontactFactory.create( - actor=self.actor3, klantcontact=self.klantcontact3 - ) - self.actor_klantcontact4 = ActorKlantcontactFactory.create( - actor=self.actor4, klantcontact=self.klantcontact4 - ) - self.actor_klantcontact5 = ActorKlantcontactFactory.create( - actor=self.actor5, klantcontact=self.klantcontact5 - ) - def test_filter_klantcontact_url(self): - klantcontact_url = f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(self.klantcontact5.uuid)}" - response = self.client.get(self.url, {"klantcontact__url": klantcontact_url}) - self.assertEqual(response.status_code, status.HTTP_200_OK) + actor = ActorFactory.create() + actor2 = ActorFactory.create() + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + actor_klantcontact = ActorKlantcontactFactory.create( + actor=actor, klantcontact=klantcontact + ) + ActorKlantcontactFactory.create(actor=actor2, klantcontact=klantcontact2) + + with self.subTest("happy flow"): + klantcontact_detail_url = reverse( + "klantinteracties:klantcontact-detail", + kwargs={"uuid": str(klantcontact.uuid)}, + ) + full_klantcontact_url = "https://testserver.com" + klantcontact_detail_url - data = response.json()["results"] + response = self.client.get( + self.url, {"klantcontact__url": full_klantcontact_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.actor_klantcontact5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(actor_klantcontact.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + klantcontact_detail_url = reverse( + "klantinteracties:klantcontact-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_klantcontact_url = "https://testserver.com" + klantcontact_detail_url + response = self.client.get( self.url, - { - "klantcontact__url": f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(uuid4())}" - }, + {"klantcontact__url": fake_klantcontact_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"klantcontact__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + klantcontact_list_url = reverse("klantinteracties:klantcontact-list") + fake_klantcontact_url = ( + "https://testserver.com" + klantcontact_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"klantcontact__url": fake_klantcontact_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_actor_url(self): - actor_url = ( - f"http://testserver/klantinteracties/api/v1/actoren/{str(self.actor5.uuid)}" - ) - response = self.client.get(self.url, {"actor__url": actor_url}) - self.assertEqual(response.status_code, status.HTTP_200_OK) + actor = ActorFactory.create() + actor2 = ActorFactory.create() + klantcontact = KlantcontactFactory.create() + klantcontact2 = KlantcontactFactory.create() + actor_klantcontact = ActorKlantcontactFactory.create( + actor=actor, klantcontact=klantcontact + ) + ActorKlantcontactFactory.create(actor=actor2, klantcontact=klantcontact2) + + with self.subTest("happy flow"): + actor_detail_url = reverse( + "klantinteracties:actor-detail", kwargs={"uuid": str(actor.uuid)} + ) + full_actor_url = "https://testserver.com" + actor_detail_url - data = response.json()["results"] + response = self.client.get(self.url, {"actor__url": full_actor_url}) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.actor_klantcontact5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(actor_klantcontact.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + actor_detail_url = reverse( + "klantinteracties:actor-detail", kwargs={"uuid": str(uuid4())} + ) + fake_actor_url = "https://testserver.com" + actor_detail_url + response = self.client.get( self.url, - { - "actor__url": f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(uuid4())}" - }, + {"actor__url": fake_actor_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get(self.url, {"actor__url": "ValueError"}) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + actor_list_url = reverse("klantinteracties:actor-list") + fake_actor_url = "https://testserver.com" + actor_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"actor__url": fake_actor_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) @@ -957,95 +1200,115 @@ def test_filter_actor_url(self): class VertegenwoordigdenFiltersetTests(APITestCase): url = reverse("klantinteracties:vertegenwoordigden-list") - def setUp(self): - super().setUp() - self.partij = PartijFactory.create(nummer="1111111111") - self.partij2 = PartijFactory.create(nummer="2222222222") - self.partij3 = PartijFactory.create(nummer="3333333333") - self.partij4 = PartijFactory.create(nummer="4444444444") - self.partij5 = PartijFactory.create(nummer="5555555555") - - self.vertegenwoordigde = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij, - vertegenwoordigde_partij=self.partij2, - ) - self.vertegenwoordigde2 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij2, - vertegenwoordigde_partij=self.partij3, - ) - self.vertegenwoordigde3 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij3, - vertegenwoordigde_partij=self.partij4, - ) - self.vertegenwoordigde4 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij4, - vertegenwoordigde_partij=self.partij5, + def test_filter_vertegenwoordigende_partij_url(self): + partij, partij2, partij3, partij4 = PartijFactory.create_batch(4) + + vertegenwoordigden = VertegenwoordigdenFactory.create( + vertegenwoordigende_partij=partij, vertegenwoordigde_partij=partij3 ) - self.vertegenwoordigde5 = VertegenwoordigdenFactory.create( - vertegenwoordigende_partij=self.partij5, - vertegenwoordigde_partij=self.partij, + VertegenwoordigdenFactory.create( + vertegenwoordigende_partij=partij2, vertegenwoordigde_partij=partij4 ) - def test_filter_vertegenwoordigende_partij_url(self): - partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}" - response = self.client.get( - self.url, {"vertegenwoordigendePartij__url": partij_url} - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url - data = response.json()["results"] + response = self.client.get( + self.url, {"vertegenwoordigendePartij__url": full_partij_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.vertegenwoordigde5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(vertegenwoordigden.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - vertegenwoordigde_partij_url = ( - f"http://testserver/klantinteracties/api/v1/partijen/{str(uuid4())}" + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} ) + fake_partij_url = "https://testserver.com" + partij_detail_url + response = self.client.get( self.url, - {"vertegenwoordigendePartij__url": vertegenwoordigde_partij_url}, + {"vertegenwoordigendePartij__url": fake_partij_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.json()["count"], 0) - - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"vertegenwoordigendePartij__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_partij_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"vertegenwoordigendePartij__url": fake_partij_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_vertegenwoordigde_partij_url(self): - partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}" - response = self.client.get( - self.url, {"vertegenwoordigdePartij__url": partij_url} + partij, partij2, partij3, partij4 = PartijFactory.create_batch(4) + vertegenwoordigden = VertegenwoordigdenFactory.create( + vertegenwoordigende_partij=partij, vertegenwoordigde_partij=partij3 + ) + VertegenwoordigdenFactory.create( + vertegenwoordigende_partij=partij2, vertegenwoordigde_partij=partij4 ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - data = response.json()["results"] + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij3.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url - self.assertEqual(1, len(data)) - self.assertEqual(str(self.vertegenwoordigde4.uuid), data[0]["uuid"]) + response = self.client.get( + self.url, {"vertegenwoordigdePartij__url": full_partij_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(vertegenwoordigden.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - partij_url = ( - f"http://testserver/klantinteracties/api/v1/partijen/{str(uuid4())}" + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} ) + fake_partij_url = "https://testserver.com" + partij_detail_url + response = self.client.get( self.url, - {"vertegenwoordigdePartij__url": partij_url}, + {"vertegenwoordigdePartij__url": fake_partij_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"vertegenwoordigdePartij__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_partij_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"vertegenwoordigdePartij__url": fake_partij_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) @@ -1054,95 +1317,111 @@ def test_filter_vertegenwoordigde_partij_url(self): class InterneTaakFilterSetTests(APITestCase): url = reverse("klantinteracties:internetaak-list") - def setUp(self): - super().setUp() - ( - self.actor, - self.actor2, - self.actor3, - self.actor4, - self.actor5, - ) = ActorFactory.create_batch(5) - ( - self.klantcontact, - self.klantcontact2, - self.klantcontact3, - self.klantcontact4, - self.klantcontact5, - ) = KlantcontactFactory.create_batch(5) - self.internetaak = InterneTaakFactory.create( - actoren=[self.actor], klantcontact=self.klantcontact - ) - self.internetaak2 = InterneTaakFactory.create( - actoren=[self.actor2], klantcontact=self.klantcontact2 - ) - self.internetaak3 = InterneTaakFactory.create( - actoren=[self.actor3], klantcontact=self.klantcontact3 - ) - self.internetaak4 = InterneTaakFactory.create( - actoren=[self.actor4], klantcontact=self.klantcontact4 - ) - self.internetaak5 = InterneTaakFactory.create( - actoren=[self.actor5], klantcontact=self.klantcontact5 - ) - def test_filter_toegewezen_aan_actor_url(self): - actor_url = ( - f"http://testserver/klantinteracties/api/v1/actoren/{str(self.actor5.uuid)}" - ) - response = self.client.get(self.url, {"toegewezenAanActor__url": actor_url}) - self.assertEqual(response.status_code, status.HTTP_200_OK) + actor, actor2 = ActorFactory.create_batch(2) + internetaak = InterneTaakFactory.create(actoren=[actor]) + InterneTaakFactory.create(actoren=[actor2]) - data = response.json()["results"] + with self.subTest("happy flow"): + actor_detail_url = reverse( + "klantinteracties:actor-detail", kwargs={"uuid": str(actor.uuid)} + ) + full_actor_url = "https://testserver.com" + actor_detail_url - self.assertEqual(1, len(data)) - self.assertEqual(str(self.internetaak5.uuid), data[0]["uuid"]) + response = self.client.get( + self.url, {"toegewezenAanActor__url": full_actor_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(internetaak.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + actor_detail_url = reverse( + "klantinteracties:actor-detail", kwargs={"uuid": str(uuid4())} + ) + fake_actor_url = "https://testserver.com" + actor_detail_url + response = self.client.get( - self.url, - { - "toegewezenAanActor__url": f"http://testserver/klantinteracties/api/v1/actoren/{str(uuid4())}" - }, + self.url, {"toegewezenAanActor__url": fake_actor_url} ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"toegewezenAanActor__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + actor_list_url = reverse("klantinteracties:actor-list") + fake_actor_url = "https://testserver.com" + actor_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"toegewezenAanActor__url": fake_actor_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_aanleidinggevend_klantcontact_url(self): - klantcontact_url = f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(self.klantcontact5.uuid)}" - response = self.client.get( - self.url, {"aanleidinggevendKlantcontact__url": klantcontact_url} - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + klantcontact, klantcontact2 = KlantcontactFactory.create_batch(2) + internetaak = InterneTaakFactory.create(klantcontact=klantcontact) + InterneTaakFactory.create(klantcontact=klantcontact2) + + with self.subTest("happy flow"): + klantcontact_detail_url = reverse( + "klantinteracties:klantcontact-detail", + kwargs={"uuid": str(klantcontact.uuid)}, + ) + full_klantcontact_url = "https://testserver.com" + klantcontact_detail_url - data = response.json()["results"] + response = self.client.get( + self.url, {"aanleidinggevendKlantcontact__url": full_klantcontact_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.internetaak5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(internetaak.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - klantcontacten_url = f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(uuid4())}" + klantcontact_detail_url = reverse( + "klantinteracties:klantcontact-detail", + kwargs={"uuid": str(uuid4())}, + ) + fake_klantcontact_url = "https://testserver.com" + klantcontact_detail_url + response = self.client.get( self.url, - {"aanleidinggevendKlantcontact__url": klantcontacten_url}, + {"aanleidinggevendKlantcontact__url": fake_klantcontact_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"aanleidinggevendKlantcontact__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + klantcontact_list_url = reverse("klantinteracties:klantcontact-list") + fake_klantcontact_url = ( + "https://testserver.com" + klantcontact_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"aanleidinggevendKlantcontact__url": fake_klantcontact_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) @@ -1151,95 +1430,113 @@ def test_filter_aanleidinggevend_klantcontact_url(self): class DigitaalAdresFilterSetTests(APITestCase): url = reverse("klantinteracties:digitaaladres-list") - def setUp(self): - super().setUp() - ( - self.betrokkene, - self.betrokkene2, - self.betrokkene3, - self.betrokkene4, - self.betrokkene5, - ) = BetrokkeneFactory.create_batch(5) - ( - self.partij, - self.partij2, - self.partij3, - self.partij4, - self.partij5, - ) = PartijFactory.create_batch(5) - self.digitaal_adres = DigitaalAdresFactory.create( - partij=self.partij, betrokkene=self.betrokkene - ) - self.digitaal_adres2 = DigitaalAdresFactory.create( - partij=self.partij2, betrokkene=self.betrokkene2 - ) - self.digitaal_adres3 = DigitaalAdresFactory.create( - partij=self.partij3, betrokkene=self.betrokkene3 - ) - self.digitaal_adres4 = DigitaalAdresFactory.create( - partij=self.partij4, betrokkene=self.betrokkene4 - ) - self.digitaal_adres5 = DigitaalAdresFactory.create( - partij=self.partij5, betrokkene=self.betrokkene5 - ) - def test_filter_verstrekt_door_betrokkene_url(self): - betrokkene_url = f"http://testserver/klantinteracties/api/v1/betrokkenen/{str(self.betrokkene5.uuid)}" - response = self.client.get( - self.url, {"verstrektDoorBetrokkene__url": betrokkene_url} - ) - self.assertEqual(response.status_code, status.HTTP_200_OK) + betrokkene, betrokkene2 = BetrokkeneFactory.create_batch(2) + DigitaalAdresFactory.create(betrokkene=betrokkene) + digitaal_adres2 = DigitaalAdresFactory.create(betrokkene=betrokkene2) + + with self.subTest("happy flow"): + betrokkene_detail_url = reverse( + "klantinteracties:betrokkene-detail", + kwargs={"uuid": str(betrokkene2.uuid)}, + ) + full_betrokkene_url = "https://testserver.com" + betrokkene_detail_url - data = response.json()["results"] + response = self.client.get( + self.url, {"verstrektDoorBetrokkene__url": full_betrokkene_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.digitaal_adres5.uuid), data[0]["uuid"]) + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(digitaal_adres2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): - betrokkene_url = ( - f"http://testserver/klantinteracties/api/v1/betrokkenen/{str(uuid4())}" + betrokkene_detail_url = reverse( + "klantinteracties:betrokkene-detail", + kwargs={"uuid": str(uuid4())}, ) + fake_betrokkene_url = "https://testserver.com" + betrokkene_detail_url + response = self.client.get( self.url, - {"verstrektDoorBetrokkene__url": betrokkene_url}, + {"verstrektDoorBetrokkene__url": fake_betrokkene_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"verstrektDoorBetrokkene__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + betrokkene_list_url = reverse("klantinteracties:betrokkene-list") + fake_betrokkene_url = ( + "https://testserver.com" + betrokkene_list_url + "/not-a-uuid" + ) + + response = self.client.get( + self.url, + {"verstrektDoorBetrokkene__url": fake_betrokkene_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) def test_filter_verstrekt_door_partij_url(self): - partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}" - response = self.client.get(self.url, {"verstrektDoorPartij__url": partij_url}) - self.assertEqual(response.status_code, status.HTTP_200_OK) + partij, partij2 = PartijFactory.create_batch(2) - data = response.json()["results"] + DigitaalAdresFactory.create(partij=partij) + digitaal_adres2 = DigitaalAdresFactory.create(partij=partij2) - self.assertEqual(1, len(data)) - self.assertEqual(str(self.digitaal_adres5.uuid), data[0]["uuid"]) + with self.subTest("happy flow"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(partij2.uuid)} + ) + full_partij_url = "https://testserver.com" + partij_detail_url + + response = self.client.get( + self.url, {"verstrektDoorPartij__url": full_partij_url} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + + self.assertEqual(1, len(data)) + self.assertEqual(str(digitaal_adres2.uuid), data[0]["uuid"]) with self.subTest("no_matches_found_return_nothing"): + partij_detail_url = reverse( + "klantinteracties:partij-detail", kwargs={"uuid": str(uuid4())} + ) + fake_partij_url = "https://testserver.com" + partij_detail_url + response = self.client.get( self.url, - { - "verstrektDoorPartij__url": f"http://testserver/klantinteracties/api/v1/partijen/{str(uuid4())}" - }, + {"verstrektDoorPartij__url": fake_partij_url}, ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) - with self.subTest("invalid_value_returns_empty_query"): + with self.subTest("no url as value restults in 400"): response = self.client.get( self.url, {"verstrektDoorPartij__url": "ValueError"} ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + with self.subTest("invalid_uuid_results_nothing"): + partij_list_url = reverse("klantinteracties:partij-list") + fake_partij_url = "https://testserver.com" + partij_list_url + "/not-a-uuid" + + response = self.client.get( + self.url, + {"verstrektDoorPartij__url": fake_partij_url}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) diff --git a/src/openklant/components/klantinteracties/openapi.yaml b/src/openklant/components/klantinteracties/openapi.yaml index 6575bb24..476dbb12 100644 --- a/src/openklant/components/klantinteracties/openapi.yaml +++ b/src/openklant/components/klantinteracties/openapi.yaml @@ -208,6 +208,7 @@ paths: name: actor__url schema: type: string + format: uri description: Zoek actor klantcontract object op basis van het actor url - in: query name: actor__uuid @@ -218,6 +219,7 @@ paths: name: klantcontact__url schema: type: string + format: uri description: Zoek actor klantcontract object op basis van het klantcontact url - in: query @@ -400,11 +402,13 @@ paths: name: hadKlantcontact__url schema: type: string + format: uri description: Zoek betrokkene object op basis van het klantcontact url - in: query name: hadKlantcontact__uuid schema: type: string + format: uuid description: Zoek betrokkene object op basis van het klantcontact uuid - in: query name: organisatienaam @@ -431,11 +435,13 @@ paths: name: verstrektedigitaalAdres__url schema: type: string + format: uri description: Zoek betrokkene object op basis van het digitaaladres url - in: query name: verstrektedigitaalAdres__uuid schema: type: string + format: uuid description: Zoek betrokkene object op basis van het digitaaladres uuid - in: query name: wasPartij__nummer @@ -446,11 +452,13 @@ paths: name: wasPartij__url schema: type: string + format: uri description: Zoek betrokkene object op basis van het partij url - in: query name: wasPartij__uuid schema: type: string + format: uuid description: Zoek betrokkene object op basis van het partij uuid tags: - betrokkenen @@ -774,11 +782,13 @@ paths: name: categorie__url schema: type: string + format: uri description: Zoek categorie relatie object op basis van de categorie url. - in: query name: categorie__uuid schema: type: string + format: uuid description: Zoek categorie relatie object op basis van de categorie uuid. - in: query name: eindDatum @@ -806,11 +816,13 @@ paths: name: partij__url schema: type: string + format: uri description: Zoek categorie relatie object op basis van de partij url. - in: query name: partij__uuid schema: type: string + format: uuid description: Zoek categorie relatie object op basis van de partij uuid. tags: - categorie relaties @@ -1165,6 +1177,7 @@ paths: name: verstrektDoorBetrokkene__url schema: type: string + format: uri description: Zoek digitaal adres(sen) object(en) op basis van de betrokkene url. - in: query @@ -1187,6 +1200,7 @@ paths: name: verstrektDoorPartij__url schema: type: string + format: uri description: Zoek digitaal adres(sen) object(en) op basis van de partij url. - in: query name: verstrektDoorPartij__uuid @@ -1351,6 +1365,7 @@ paths: name: aanleidinggevendKlantcontact__url schema: type: string + format: uri description: Zoek internetaak object op basis van het aanleidingevende klantcontact url. - in: query @@ -1403,6 +1418,7 @@ paths: name: toegewezenAanActor__url schema: type: string + format: uri description: Zoek internetaak object op basis van het toegewezen actor url. - in: query name: toegewezenAanActor__uuid @@ -1575,6 +1591,7 @@ paths: name: hadBetrokkene__url schema: type: string + format: uri description: Zoek klantcontact object op basis van het betrokkene url. - in: query name: hadBetrokkene__uuid @@ -1582,6 +1599,18 @@ paths: type: string format: uuid description: Zoek klantcontact object op basis van het betrokkene uuid. + - in: query + name: hadBetrokkene__wasPartij__url + schema: + type: string + format: uri + description: Zoek klantcontact object op basis van de partij url. + - in: query + name: hadBetrokkene__wasPartij__uuid + schema: + type: string + format: uuid + description: Zoek klantcontact object op basis van de partij uuid. - in: query name: indicatieContactGelukt schema: @@ -1624,6 +1653,7 @@ paths: name: onderwerpobject__url schema: type: string + format: uri description: Zoek klantcontact object op basis van het onderwerpobject url. - in: query name: onderwerpobject__uuid @@ -1671,6 +1701,7 @@ paths: name: wasOnderwerpobject__url schema: type: string + format: uri description: Zoek was klantcontact object op basis van het onderwerpobject url. - in: query @@ -2318,6 +2349,7 @@ paths: name: vertegenwoordigdePartij__url schema: type: string + format: uri description: Zoek partij object op basis van het vertegenwoordigde partij url. - in: query @@ -2660,6 +2692,7 @@ paths: name: vertegenwoordigdePartij__url schema: type: string + format: uri description: Zoek Vertegenwoordigden object op basis van het vertegenwoordigde partij url. - in: query @@ -2671,6 +2704,7 @@ paths: name: vertegenwoordigendePartij__url schema: type: string + format: uri description: Zoek Vertegenwoordigden object op basis van het vertegenwoordigende partij url. - in: query diff --git a/src/openklant/components/utils/filters.py b/src/openklant/components/utils/filters.py index b4ca668e..1b278dbc 100644 --- a/src/openklant/components/utils/filters.py +++ b/src/openklant/components/utils/filters.py @@ -1,6 +1,11 @@ +import uuid + +from django import forms +from django.db.models import QuerySet from django.utils.translation import gettext_lazy as _ -from django_filters import filters +from django_filters.rest_framework import filters +from drf_spectacular.types import OpenApiTypes from .expansion import get_expand_options_for_serializer @@ -21,3 +26,19 @@ def __init__(self, *args, **kwargs): def filter(self, qs, value): return qs + + +class URLViewFilter(filters.Filter): + field_class = forms.URLField + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def filter(self, qs, value: OpenApiTypes.URI) -> QuerySet: + if value: + try: + value = uuid.UUID(value.rstrip("/").split("/")[-1]) + except ValueError: + return qs.none() + + return super().filter(qs, value) diff --git a/src/openklant/utils/query.py b/src/openklant/utils/query.py index 2fd3b3c2..31b580d0 100644 --- a/src/openklant/utils/query.py +++ b/src/openklant/utils/query.py @@ -3,19 +3,40 @@ from drf_spectacular.contrib.django_filters import DjangoFilterExtension from vng_api_common.utils import underscore_to_camel +from openklant.components.utils.filters import URLViewFilter + class CamelizeFilterExtension(DjangoFilterExtension): priority = 1 - def get_schema_operation_parameters(self, auto_schema, *args, **kwargs): - """ - camelize query parameters - """ - parameters = super().get_schema_operation_parameters( - auto_schema, *args, **kwargs + def resolve_filter_field( + self, auto_schema, model, filterset_class, field_name, filter_field + ) -> list[dict]: + results = super().resolve_filter_field( + auto_schema, model, filterset_class, field_name, filter_field + ) + + for result in results: + result["name"] = underscore_to_camel(result["name"]) + + return results + + +class UUIDURLFilterExtension(CamelizeFilterExtension): + priority = 2 + + def resolve_filter_field( + self, auto_schema, model, filterset_class, field_name, filter_field + ) -> list[dict]: + results = super().resolve_filter_field( + auto_schema, model, filterset_class, field_name, filter_field ) - for parameter in parameters: - parameter["name"] = underscore_to_camel(parameter["name"]) + if not isinstance(filter_field, URLViewFilter): + return results + + for result in results: + schema = result.setdefault("schema", {}) + schema.update({"type": "string", "format": "uri"}) - return parameters + return results