Skip to content

Commit 992480b

Browse files
committed
✅ [#256] test klantcontact filters to retrieve klantcontact based on betrokkene -> partij uuid/url
1 parent 8d7f179 commit 992480b

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

src/openklant/components/klantinteracties/api/tests/test_filters.py

+68-11
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,31 @@ def setUp(self):
4040
self.klantcontact4,
4141
self.klantcontact5,
4242
) = KlantcontactFactory.create_batch(5)
43-
for betrokkene_klantcontact in [
44-
self.klantcontact,
45-
self.klantcontact2,
46-
self.klantcontact3,
47-
self.klantcontact4,
48-
self.klantcontact5,
49-
]:
50-
self.betrokkene = BetrokkeneFactory.create(
51-
klantcontact=betrokkene_klantcontact
52-
)
43+
44+
self.partij, self.partij2, self.partij3, self.partij4, self.partij5 = (
45+
PartijFactory.create_batch(5)
46+
)
47+
48+
self.betrokkene = BetrokkeneFactory.create(
49+
klantcontact=self.klantcontact,
50+
partij=self.partij,
51+
)
52+
self.betrokkene2 = BetrokkeneFactory.create(
53+
klantcontact=self.klantcontact2,
54+
partij=self.partij2,
55+
)
56+
self.betrokkene3 = BetrokkeneFactory.create(
57+
klantcontact=self.klantcontact3,
58+
partij=self.partij3,
59+
)
60+
self.betrokkene4 = BetrokkeneFactory.create(
61+
klantcontact=self.klantcontact4,
62+
partij=self.partij4,
63+
)
64+
self.betrokkene5 = BetrokkeneFactory.create(
65+
klantcontact=self.klantcontact5,
66+
partij=self.partij5,
67+
)
5368

5469
self.onderwerpobject = OnderwerpobjectFactory.create(
5570
klantcontact=self.klantcontact,
@@ -92,6 +107,48 @@ def setUp(self):
92107
onderwerpobjectidentificator_code_register="5",
93108
)
94109

110+
def test_filter_partij_url(self):
111+
partij_url = (
112+
f"http://testserver/klantinteracties/api/v1/klantcontact/{self.partij.uuid}"
113+
)
114+
response = self.client.get(
115+
self.url,
116+
{"hadBetrokkene__wasPartij__url": partij_url},
117+
)
118+
data = response.json()["results"]
119+
120+
self.assertEqual(1, len(data))
121+
self.assertEqual(str(self.klantcontact.uuid), data[0]["uuid"])
122+
123+
with self.subTest("no_matches_found_return_nothing"):
124+
response = self.client.get(
125+
self.url,
126+
{
127+
"hadBetrokkene__url": f"http://testserver/klantinteracties/api/v1/klantcontact/{str(uuid4())}"
128+
},
129+
)
130+
self.assertEqual(response.status_code, status.HTTP_200_OK)
131+
132+
self.assertEqual(response.json()["count"], 0)
133+
134+
with self.subTest("invalid_value_returns_empty_query"):
135+
response = self.client.get(self.url, {"hadBetrokkene__url": "ValueError"})
136+
self.assertEqual(response.status_code, status.HTTP_200_OK)
137+
138+
self.assertEqual(response.json()["count"], 0)
139+
140+
def test_filter_partij_uuid(self):
141+
response = self.client.get(
142+
self.url,
143+
{
144+
"hadBetrokkene__wasPartij__uuid": str(self.partij.uuid)
145+
},
146+
)
147+
data = response.json()["results"]
148+
149+
self.assertEqual(1, len(data))
150+
self.assertEqual(str(self.klantcontact.uuid), data[0]["uuid"])
151+
95152
def test_filter_betrokkene_url(self):
96153
response = self.client.get(
97154
self.url,
@@ -102,7 +159,7 @@ def test_filter_betrokkene_url(self):
102159
data = response.json()["results"]
103160

104161
self.assertEqual(1, len(data))
105-
self.assertEqual(str(self.klantcontact5.uuid), data[0]["uuid"])
162+
self.assertEqual(str(self.klantcontact.uuid), data[0]["uuid"])
106163

107164
with self.subTest("no_matches_found_return_nothing"):
108165
response = self.client.get(

0 commit comments

Comments
 (0)