Skip to content

Commit

Permalink
✅ [#706] Test internal resultaattype choices endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Feb 21, 2025
1 parent d1bfb0d commit 4c11c97
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 18 deletions.
171 changes: 155 additions & 16 deletions backend/src/openarchiefbeheer/zaken/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_retrieve_zaaktypen_choices(self):

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.json(),
sorted(response.json(), key=lambda choice: choice["label"]),
[
{
"value": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/111-111-111,http://catalogi-api.nl/catalogi/api/v1/zaakypen/222-222-222",
Expand All @@ -132,7 +132,7 @@ def test_retrieve_zaaktypen_choices_empty_identificatie(self):
ZaakFactory.create(
post___expand={
"zaaktype": {
"url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/111-111-111",
"url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/222-222-222",
"identificatie": "",
"omschrijving": "ZAAKTYPE 1.0",
"versiedatum": "2024-01-01",
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_retrieve_zaaktypen_choices_for_destruction_list_if_zaaktype_id_empty(se
status=ListItemStatus.suggested,
)
item.zaak._expand["zaaktype"] = {
"url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/111-111-111",
"url": "http://catalogi-api.nl/catalogi/api/v1/zaakypen/222-222-222",
"identificatie": "",
"omschrijving": "ZAAKTYPE 1.0",
"versiedatum": "2024-01-01",
Expand Down Expand Up @@ -685,7 +685,7 @@ def setUp(self):
self.addCleanup(retrieve_paginated_type.cache_clear)

def test_not_authenticated(self):
endpoint = reverse("api:retrieve-resultaattype-choices")
endpoint = reverse("api:retrieve-external-resultaattype-choices")

response = self.client.get(endpoint)

Expand All @@ -705,7 +705,7 @@ def test_retrieve_choices(self, m):
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/resultaattypen/111-111-111",
"url": "http://oz.nl/api/v1/resultaattypen/222-222-222",
"omschrijving": "Blabla 1",
},
{
Expand All @@ -717,14 +717,16 @@ def test_retrieve_choices(self, m):
)

self.client.force_authenticate(user=user)
response = self.client.get(reverse("api:retrieve-resultaattype-choices"))
response = self.client.get(
reverse("api:retrieve-external-resultaattype-choices")
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.json(),
[
{
"value": "http://oz.nl/api/v1/resultaattypen/111-111-111",
"value": "http://oz.nl/api/v1/resultaattypen/222-222-222",
"label": "Blabla 1",
},
{
Expand All @@ -748,7 +750,7 @@ def test_retrieve_choices_caches_request(self, m):
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/resultaattypen/111-111-111",
"url": "http://oz.nl/api/v1/resultaattypen/222-222-222",
"omschrijving": "Blabla 1",
},
{
Expand All @@ -760,12 +762,16 @@ def test_retrieve_choices_caches_request(self, m):
)

self.client.force_authenticate(user=user)
response = self.client.get(reverse("api:retrieve-resultaattype-choices"))
response = self.client.get(
reverse("api:retrieve-external-resultaattype-choices")
)

self.assertEqual(response.status_code, status.HTTP_200_OK)

# Repeat request
response = self.client.get(reverse("api:retrieve-resultaattype-choices"))
response = self.client.get(
reverse("api:retrieve-external-resultaattype-choices")
)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -801,7 +807,7 @@ def test_retrieve_choices(self, m):
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111",
"url": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
"omschrijving": "Blabla 1",
},
{
Expand All @@ -820,7 +826,7 @@ def test_retrieve_choices(self, m):
response.json(),
[
{
"value": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111",
"value": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
"label": "Blabla 1",
},
{
Expand All @@ -844,7 +850,7 @@ def test_retrieve_choices_caches_request(self, m):
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111",
"url": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
"omschrijving": "Blabla 1",
},
{
Expand Down Expand Up @@ -897,7 +903,7 @@ def test_retrieve_choices(self, m):
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/statustypen/111-111-111",
"url": "http://oz.nl/api/v1/statustypen/222-222-222",
"omschrijving": "Blabla 1",
},
{
Expand All @@ -916,7 +922,7 @@ def test_retrieve_choices(self, m):
response.json(),
[
{
"value": "http://oz.nl/api/v1/statustypen/111-111-111",
"value": "http://oz.nl/api/v1/statustypen/222-222-222",
"label": "Blabla 1",
},
{
Expand All @@ -940,7 +946,7 @@ def test_retrieve_choices_caches_request(self, m):
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/statustypen/111-111-111",
"url": "http://oz.nl/api/v1/statustypen/222-222-222",
"omschrijving": "Blabla 1",
},
{
Expand All @@ -963,3 +969,136 @@ def test_retrieve_choices_caches_request(self, m):

# Only one call to openzaak
self.assertEqual(len(m.request_history), 1)


class InternalResultaattypeChoicesViewTest(APITestCase):
def setUp(self):
super().setUp()

self.addCleanup(cache.clear)

def test_not_authenticated(self):
endpoint = reverse("api:retrieve-internal-resultaattype-choices")

response = self.client.get(endpoint)

self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_get_all_choices(self):
user = UserFactory.create()

ZaakFactory.create(
post___expand={
"resultaat": {
"url": "http://localhost:8003/zaken/api/v1/resultaten/821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"uuid": "821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"_expand": {
"resultaattype": {
"url": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111",
"omschrijving": "Afgehandeld",
}
},
"toelichting": "Testing resultaten",
"resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111",
}
},
)
ZaakFactory.create(
post___expand={
"resultaat": {
"url": "http://localhost:8003/zaken/api/v1/resultaten/821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"uuid": "821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"_expand": {
"resultaattype": {
"url": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222",
"omschrijving": "Lopend",
}
},
"toelichting": "Testing resultaten",
"resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222",
}
},
)

self.client.force_authenticate(user=user)
response = self.client.get(
reverse("api:retrieve-internal-resultaattype-choices")
)

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()

self.assertEqual(len(data), 2)
self.assertEqual(
[
{
"value": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111",
"label": "Afgehandeld",
},
{
"value": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222",
"label": "Lopend",
},
],
sorted(data, key=lambda choice: choice["value"]),
)

def test_get_choices_with_filters(self):
user = UserFactory.create()

ZaakFactory.create(
identificatie="ZAAK-01",
post___expand={
"resultaat": {
"url": "http://localhost:8003/zaken/api/v1/resultaten/821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"uuid": "821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"_expand": {
"resultaattype": {
"url": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111",
"omschrijving": "Afgehandeld",
}
},
"toelichting": "Testing resultaten",
"resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111",
}
},
)
ZaakFactory.create(
identificatie="ZAAK-02",
post___expand={
"resultaat": {
"url": "http://localhost:8003/zaken/api/v1/resultaten/821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"uuid": "821b4d8f-3244-4ece-8d33-791fa6d2a2f3",
"_expand": {
"resultaattype": {
"url": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222",
"omschrijving": "Lopend",
}
},
"toelichting": "Testing resultaten",
"resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222",
}
},
)

self.client.force_authenticate(user=user)
endpoint = furl(reverse("api:retrieve-internal-resultaattype-choices"))
endpoint.args["identificatie"] = "ZAAK-01"

response = self.client.get(endpoint.url)

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()

self.assertEqual(len(data), 1)
self.assertEqual(
[
{
"value": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111",
"label": "Afgehandeld",
},
],
data,
)
6 changes: 4 additions & 2 deletions backend/src/openarchiefbeheer/zaken/tests/vcr/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def test_retrieve_all_choices(self):
user = UserFactory.create()

self.client.force_authenticate(user=user)
response = self.client.get(reverse("api:retrieve-resultaattype-choices"))
response = self.client.get(
reverse("api:retrieve-external-resultaattype-choices")
)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand All @@ -120,7 +122,7 @@ def test_retrieve_all_choices(self):
def test_retrieve_choices_with_filters(self):
user = UserFactory.create()

endpoint = furl(reverse("api:retrieve-resultaattype-choices"))
endpoint = furl(reverse("api:retrieve-external-resultaattype-choices"))
endpoint.args["zaaktype"] = (
"http://localhost:8003/catalogi/api/v1/zaaktypen/be210495-20b6-48ff-8d3d-3e44f74c43a4"
)
Expand Down

0 comments on commit 4c11c97

Please sign in to comment.