From c909918f782a5b489113d0f6530b9d0a18b1d81e Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Mon, 25 Nov 2024 11:01:43 +0100 Subject: [PATCH] [#265] Fix adres__icontains + tests --- .../api/filterset/digitaal_adres.py | 1 + .../api/tests/test_filters.py | 37 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py b/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py index 75afb499..c156c383 100644 --- a/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py +++ b/src/openklant/components/klantinteracties/api/filterset/digitaal_adres.py @@ -55,6 +55,7 @@ class DigitaalAdresFilterSet(FilterSet): ), ) adres__icontains = filters.CharFilter( + field_name="adres", lookup_expr="icontains", help_text=_( "Zoek digitaal adres(sen) object(en) op basis van adres die de opgegeven waarden bevat." diff --git a/src/openklant/components/klantinteracties/api/tests/test_filters.py b/src/openklant/components/klantinteracties/api/tests/test_filters.py index b61ebf66..4386b9b1 100644 --- a/src/openklant/components/klantinteracties/api/tests/test_filters.py +++ b/src/openklant/components/klantinteracties/api/tests/test_filters.py @@ -1177,10 +1177,10 @@ def setUp(self): partij=self.partij3, betrokkene=self.betrokkene3 ) self.digitaal_adres4 = DigitaalAdresFactory.create( - partij=self.partij4, betrokkene=self.betrokkene4 + partij=self.partij4, betrokkene=self.betrokkene4, adres="adres_1234", ) self.digitaal_adres5 = DigitaalAdresFactory.create( - partij=self.partij5, betrokkene=self.betrokkene5 + partij=self.partij5, betrokkene=self.betrokkene5, adres="adres_5678", ) def test_filter_verstrekt_door_betrokkene_url(self): @@ -1243,3 +1243,36 @@ def test_filter_verstrekt_door_partij_url(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["count"], 0) + + def test_filter_adres_exact_parameter(self): + + response = self.client.get(self.url) + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + self.assertEqual(data["count"], 10) + + response = self.client.get(self.url, {"adres": "adres_1234"}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + self.assertEqual(data["count"], 1) + self.assertEqual(data["results"][0]["adres"], "adres_1234") + + + def test_filter_adres_icontains_parameter(self): + + response = self.client.get(self.url, {"adres__icontains": "adres_1234"}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + self.assertEqual(data["count"], 1) + self.assertEqual(data["results"][0]["adres"], "adres_1234") + + response = self.client.get(self.url, {"adres__icontains": "adres_5678"}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + self.assertEqual(data["count"], 1) + self.assertEqual(data["results"][0]["adres"], "adres_5678") + + response = self.client.get(self.url, {"adres__icontains": "adres"}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + self.assertEqual(data["count"], 2) \ No newline at end of file