Skip to content

Commit

Permalink
Merge pull request #143 from open-zaak/feature/query-parameter-valida…
Browse files Browse the repository at this point in the history
…tion

Feature/query parameter validation
  • Loading branch information
joeribekker committed Oct 29, 2019
2 parents 94da067 + 12f2b2c commit 68d7bea
Show file tree
Hide file tree
Showing 26 changed files with 249 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/openzaak/components/authorizations/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from vng_api_common.authorizations.models import Applicatie
from vng_api_common.authorizations.serializers import ApplicatieSerializer
from vng_api_common.notifications.viewsets import NotificationViewSetMixin
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -19,7 +20,9 @@
logger = logging.getLogger(__name__)


class ApplicatieViewSet(NotificationViewSetMixin, viewsets.ModelViewSet):
class ApplicatieViewSet(
CheckQueryParamsMixin, NotificationViewSetMixin, viewsets.ModelViewSet
):
"""
Uitlezen en configureren van autorisaties voor applicaties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,15 @@ def setUpTestData(cls):
def test_filter_client_id_hit(self):
url = get_operation_url("applicatie_list")

response = self.client.get(url, {"client_ids": "id2"})
response = self.client.get(url, {"clientIds": "id2"})

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 1)

def test_filter_client_id_miss(self):
url = get_operation_url("applicatie_list")

response = self.client.get(url, {"client_ids": "id3"})
response = self.client.get(url, {"clientIds": "id3"})

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 0)
Expand All @@ -312,6 +312,17 @@ def test_fetch_via_client_id(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["url"], f"http://testserver{reverse(app)}")

def test_validate_unknown_query_params(self):
ApplicatieFactory.create_batch(2)
url = reverse(Applicatie)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class UpdateAuthorizationsTests(JWTAuthMixin, APITestCase):
scopes = [str(SCOPE_AUTORISATIES_BIJWERKEN)]
Expand Down
1 change: 1 addition & 0 deletions src/openzaak/components/besluiten/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


class BesluitViewSet(
CheckQueryParamsMixin,
NotificationViewSetMixin,
AuditTrailViewsetMixin,
ListFilterByAuthorizationsMixin,
Expand Down
34 changes: 33 additions & 1 deletion src/openzaak/components/besluiten/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from rest_framework import status
from rest_framework.test import APITestCase
from vng_api_common.tests import get_validation_errors, reverse

from openzaak.components.catalogi.tests.factories import BesluitTypeFactory
from openzaak.components.catalogi.tests.utils import (
get_operation_url as get_catalogus_operation_url,
)
from openzaak.utils.tests import JWTAuthMixin

from .factories import BesluitFactory
from ..models import Besluit, BesluitInformatieObject
from .factories import BesluitFactory, BesluitInformatieObjectFactory
from .utils import get_operation_url


Expand All @@ -32,3 +34,33 @@ def test_filter_besluittype(self):

self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
self.assertEqual(response.data["count"], 3)


class BesluitAPIFilterTests(JWTAuthMixin, APITestCase):
heeft_alle_autorisaties = True

def test_validate_unknown_query_params(self):
BesluitFactory.create_batch(2)
url = reverse(Besluit)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class BesluitInformatieObjectAPIFilterTests(JWTAuthMixin, APITestCase):
heeft_alle_autorisaties = True

def test_validate_unknown_query_params(self):
BesluitInformatieObjectFactory.create_batch(2)
url = reverse(BesluitInformatieObject)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")
2 changes: 2 additions & 0 deletions src/openzaak/components/catalogi/api/viewsets/besluittype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -11,6 +12,7 @@


class BesluitTypeViewSet(
CheckQueryParamsMixin,
ConceptMixin,
M2MConceptCreateMixin,
mixins.CreateModelMixin,
Expand Down
5 changes: 4 additions & 1 deletion src/openzaak/components/catalogi/api/viewsets/catalogus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -9,7 +10,9 @@
from ..serializers import CatalogusSerializer


class CatalogusViewSet(mixins.CreateModelMixin, viewsets.ReadOnlyModelViewSet):
class CatalogusViewSet(
CheckQueryParamsMixin, mixins.CreateModelMixin, viewsets.ReadOnlyModelViewSet
):
"""
Opvragen en bewerken van CATALOGUSsen.
Expand Down
2 changes: 2 additions & 0 deletions src/openzaak/components/catalogi/api/viewsets/eigenschap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.components.catalogi.models import Eigenschap
from openzaak.utils.permissions import AuthRequired
Expand All @@ -11,6 +12,7 @@


class EigenschapViewSet(
CheckQueryParamsMixin,
ZaakTypeConceptMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -11,6 +12,7 @@


class InformatieObjectTypeViewSet(
CheckQueryParamsMixin,
ConceptMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework import mixins, viewsets
from rest_framework.exceptions import PermissionDenied
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -14,6 +15,7 @@


class ZaakTypeInformatieObjectTypeViewSet(
CheckQueryParamsMixin,
ConceptFilterMixin,
ConceptDestroyMixin,
mixins.CreateModelMixin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -11,6 +12,7 @@


class ResultaatTypeViewSet(
CheckQueryParamsMixin,
ZaakTypeConceptMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
Expand Down
2 changes: 2 additions & 0 deletions src/openzaak/components/catalogi/api/viewsets/statustype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -11,6 +12,7 @@


class StatusTypeViewSet(
CheckQueryParamsMixin,
ZaakTypeConceptMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
Expand Down
2 changes: 2 additions & 0 deletions src/openzaak/components/catalogi/api/viewsets/zaaktype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import mixins, viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.permissions import AuthRequired

Expand All @@ -11,6 +12,7 @@


class ZaakTypeViewSet(
CheckQueryParamsMixin,
ConceptMixin,
M2MConceptCreateMixin,
mixins.CreateModelMixin,
Expand Down
13 changes: 12 additions & 1 deletion src/openzaak/components/catalogi/tests/test_besluittype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import status
from vng_api_common.tests import get_validation_errors, reverse
from vng_api_common.tests import get_operation_url, get_validation_errors, reverse

from ..models import BesluitType
from .base import APITestCase
Expand Down Expand Up @@ -406,6 +406,17 @@ def test_filter_informatieobjecttypes(self):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{besluittype1_url}")

def test_validate_unknown_query_params(self):
BesluitTypeFactory.create_batch(2)
url = reverse(BesluitType)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class BesluitTypePaginationTestCase(APITestCase):
maxDiff = None
Expand Down
13 changes: 12 additions & 1 deletion src/openzaak/components/catalogi/tests/test_catalogus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import status
from vng_api_common.tests import reverse
from vng_api_common.tests import get_validation_errors, reverse

from ..models import Catalogus
from .base import APITestCase
Expand Down Expand Up @@ -111,6 +111,17 @@ def test_filter_rsin_in(self):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(catalogus1)}")

def test_validate_unknown_query_params(self):
CatalogusFactory.create_batch(2)
url = reverse(Catalogus)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class CatalogusPaginationTestCase(APITestCase):
maxDiff = None
Expand Down
13 changes: 12 additions & 1 deletion src/openzaak/components/catalogi/tests/test_eigenschap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import status
from vng_api_common.tests import TypeCheckMixin, reverse
from vng_api_common.tests import TypeCheckMixin, get_validation_errors, reverse

from ..constants import FormaatChoices
from ..models import Eigenschap
Expand Down Expand Up @@ -262,6 +262,17 @@ def test_filter_eigenschap_status_definitief(self):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{eigenschap2_url}")

def test_validate_unknown_query_params(self):
EigenschapFactory.create_batch(2)
url = reverse(Eigenschap)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class EigenschapPaginationTestCase(APITestCase):
maxDiff = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from unittest import skip

from django.urls import reverse

from rest_framework import status
from vng_api_common.constants import VertrouwelijkheidsAanduiding
from vng_api_common.tests import get_validation_errors, reverse

from ..models import InformatieObjectType
from .base import APITestCase
Expand Down Expand Up @@ -226,6 +225,17 @@ def test_filter_informatieobjecttype_status_definitief(self):
data[0]["url"], f"http://testserver{informatieobjecttype2_url}"
)

def test_validate_unknown_query_params(self):
InformatieObjectTypeFactory.create_batch(2)
url = reverse(InformatieObjectType)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class InformatieObjectTypePaginationTestCase(APITestCase):
maxDiff = None
Expand Down
13 changes: 12 additions & 1 deletion src/openzaak/components/catalogi/tests/test_relatieklassen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import skip

from rest_framework import status
from vng_api_common.tests import reverse, reverse_lazy
from vng_api_common.tests import get_validation_errors, reverse, reverse_lazy

from ..constants import RichtingChoices
from ..models import ZaakInformatieobjectType
Expand Down Expand Up @@ -273,6 +273,17 @@ def test_filter_ziot_status_definitief(self):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{ziot4_url}")

def test_validate_unknown_query_params(self):
ZaakInformatieobjectTypeFactory.create_batch(2)
url = reverse(ZaakInformatieobjectType)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class ZaakInformatieobjectTypePaginationTestCase(APITestCase):
maxDiff = None
Expand Down
11 changes: 11 additions & 0 deletions src/openzaak/components/catalogi/tests/test_resultaattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ def test_filter_resultaattype_status_definitief(self):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{resultaattype2_url}")

def test_validate_unknown_query_params(self):
ResultaatTypeFactory.create_batch(2)
url = reverse(ResultaatType)

response = self.client.get(url, {"someparam": "somevalue"})

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")


class ResultaatTypePaginationTestCase(APITestCase):
maxDiff = None
Expand Down

0 comments on commit 68d7bea

Please sign in to comment.