Skip to content

Commit

Permalink
Merge pull request #289 from maykinmedia/265-fix-digitaleadressen-que…
Browse files Browse the repository at this point in the history
…ry-parameter

[#265] Fix adres__icontains + tests
  • Loading branch information
stevenbal authored Nov 29, 2024
2 parents d55e4c6 + 0567d71 commit bedc8fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1540,3 +1540,41 @@ 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):
betrokkene, betrokkene2 = BetrokkeneFactory.create_batch(2)
DigitaalAdresFactory.create(betrokkene=betrokkene, adres="adres_1234")
DigitaalAdresFactory.create(betrokkene=betrokkene2, adres="adres_5678")

response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
self.assertEqual(data["count"], 2)

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):
betrokkene, betrokkene2 = BetrokkeneFactory.create_batch(2)
DigitaalAdresFactory.create(betrokkene=betrokkene, adres="adres_1234")
DigitaalAdresFactory.create(betrokkene=betrokkene2, adres="adres_5678")

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)

0 comments on commit bedc8fd

Please sign in to comment.