Skip to content

Commit

Permalink
✅ [#397] Test new choices endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Oct 9, 2024
1 parent ace3d54 commit 40ba165
Show file tree
Hide file tree
Showing 2 changed files with 297 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/src/openarchiefbeheer/config/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ def test_record_manager_update(self):
self.client.force_login(user)
response = self.client.put(
reverse("api:archive-config"),
data={"zaaktypesShortProcess": ["http://tralala.nl"]},
data={
"zaaktypesShortProcess": ["http://tralala.nl"],
"bronorganisatie": "000000000",
"zaaktype": "http://bla.nl",
"statustype": "http://bla.nl",
"resultaattype": "http://bla.nl",
"informatieobjecttype": "http://bla.nl",
},
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down
289 changes: 289 additions & 0 deletions backend/src/openarchiefbeheer/zaken/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DestructionListItemReviewFactory,
DestructionListReviewFactory,
)
from openarchiefbeheer.zaken.utils import retrieve_paginated_type

from ..tasks import retrieve_and_cache_zaken_from_openzaak
from .factories import ZaakFactory
Expand Down Expand Up @@ -634,3 +635,291 @@ def test_response_cached(self, m):
self.client.get(endpoint.url)

self.assertEqual(len(m.request_history), 1)


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

self.addCleanup(cache.clear)
self.addCleanup(retrieve_paginated_type.cache_clear)

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

response = self.client.get(endpoint)

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

@Mocker()
def test_retrieve_choices(self, m):
ServiceFactory.create(
api_type=APITypes.ztc,
api_root="http://oz.nl/api/v1",
)
user = UserFactory.create()

m.get(
"http://oz.nl/api/v1/resultaattypen",
json={
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/resultaattypen/111-111-111",
"omschrijving": "Blabla 1",
},
{
"url": "http://oz.nl/api/v1/resultaattypen/222-222-222",
"omschrijving": "",
},
],
},
)

self.client.force_authenticate(user=user)
response = self.client.get(reverse("api:retrieve-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",
"label": "Blabla 1",
},
{
"value": "http://oz.nl/api/v1/resultaattypen/222-222-222",
"label": "http://oz.nl/api/v1/resultaattypen/222-222-222",
},
],
)

@Mocker()
def test_retrieve_choices_caches_request(self, m):
ServiceFactory.create(
api_type=APITypes.ztc,
api_root="http://oz.nl/api/v1",
)
user = UserFactory.create()

m.get(
"http://oz.nl/api/v1/resultaattypen",
json={
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/resultaattypen/111-111-111",
"omschrijving": "Blabla 1",
},
{
"url": "http://oz.nl/api/v1/resultaattypen/222-222-222",
"omschrijving": "",
},
],
},
)

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

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

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

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

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


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

self.addCleanup(cache.clear)
self.addCleanup(retrieve_paginated_type.cache_clear)

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

response = self.client.get(endpoint)

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

@Mocker()
def test_retrieve_choices(self, m):
ServiceFactory.create(
api_type=APITypes.ztc,
api_root="http://oz.nl/api/v1",
)
user = UserFactory.create()

m.get(
"http://oz.nl/api/v1/informatieobjecttypen",
json={
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111",
"omschrijving": "Blabla 1",
},
{
"url": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
"omschrijving": "",
},
],
},
)

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

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.json(),
[
{
"value": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111",
"label": "Blabla 1",
},
{
"value": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
"label": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
},
],
)

@Mocker()
def test_retrieve_choices_caches_request(self, m):
ServiceFactory.create(
api_type=APITypes.ztc,
api_root="http://oz.nl/api/v1",
)
user = UserFactory.create()

m.get(
"http://oz.nl/api/v1/informatieobjecttypen",
json={
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111",
"omschrijving": "Blabla 1",
},
{
"url": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222",
"omschrijving": "",
},
],
},
)

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

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

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

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

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


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

self.addCleanup(cache.clear)
self.addCleanup(retrieve_paginated_type.cache_clear)

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

response = self.client.get(endpoint)

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

@Mocker()
def test_retrieve_choices(self, m):
ServiceFactory.create(
api_type=APITypes.ztc,
api_root="http://oz.nl/api/v1",
)
user = UserFactory.create()

m.get(
"http://oz.nl/api/v1/statustypen",
json={
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/statustypen/111-111-111",
"omschrijving": "Blabla 1",
},
{
"url": "http://oz.nl/api/v1/statustypen/222-222-222",
"omschrijving": "",
},
],
},
)

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

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.json(),
[
{
"value": "http://oz.nl/api/v1/statustypen/111-111-111",
"label": "Blabla 1",
},
{
"value": "http://oz.nl/api/v1/statustypen/222-222-222",
"label": "http://oz.nl/api/v1/statustypen/222-222-222",
},
],
)

@Mocker()
def test_retrieve_choices_caches_request(self, m):
ServiceFactory.create(
api_type=APITypes.ztc,
api_root="http://oz.nl/api/v1",
)
user = UserFactory.create()

m.get(
"http://oz.nl/api/v1/statustypen",
json={
"count": 2,
"results": [
{
"url": "http://oz.nl/api/v1/statustypen/111-111-111",
"omschrijving": "Blabla 1",
},
{
"url": "http://oz.nl/api/v1/statustypen/222-222-222",
"omschrijving": "",
},
],
},
)

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

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

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

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

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

0 comments on commit 40ba165

Please sign in to comment.