Skip to content

Commit

Permalink
Merge pull request #1489 from open-zaak/feature/1485-catalogi-new-que…
Browse files Browse the repository at this point in the history
…ry-params

Feature/1485 catalogi new query params
  • Loading branch information
annashamray committed Nov 1, 2023
2 parents 59f9bca + 98b518d commit 1f5dbc9
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 14 deletions.
85 changes: 78 additions & 7 deletions src/openzaak/components/catalogi/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* `concept`: Toon objecten waarvan het attribuut `concept` true is.
* `definitief`: Toon objecten waarvan het attribuut `concept` false is (standaard).
"""
DATUM_GELDIGHEID_HELP_TEXT = "filter objecten op hun geldigheids datum."


class StatusChoices(models.TextChoices):
Expand Down Expand Up @@ -58,6 +59,14 @@ def m2m_filter(queryset, name, value):
return queryset.filter(**{name: object})


def geldigheid_filter(queryset, name, value):
"""return objects which have geldigheid dates between certain date"""
return queryset.filter(datum_begin_geldigheid__lte=value).filter(
models.Q(datum_einde_geldigheid__gte=value)
| models.Q(datum_einde_geldigheid__isnull=True)
)


class CharArrayFilter(filters.BaseInFilter, filters.CharFilter):
pass

Expand All @@ -69,10 +78,23 @@ class RolTypeFilter(FilterSet):
help_text=STATUS_HELP_TEXT,
choices=StatusChoices.choices,
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)
zaaktype_identificatie = filters.CharFilter(
field_name="zaaktype__identificatie",
help_text=get_help_text("catalogi.ZaakType", "identificatie"),
)

class Meta:
model = RolType
fields = ("zaaktype", "omschrijving_generiek", "status")
fields = (
"zaaktype",
"omschrijving_generiek",
"status",
"datum_geldigheid",
"zaaktype_identificatie",
)


class ZaakTypeInformatieObjectTypeFilter(FilterSet):
Expand Down Expand Up @@ -107,10 +129,17 @@ class ResultaatTypeFilter(FilterSet):
help_text=STATUS_HELP_TEXT,
choices=StatusChoices.choices,
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)
zaaktype_identificatie = filters.CharFilter(
field_name="zaaktype__identificatie",
help_text=get_help_text("catalogi.ZaakType", "identificatie"),
)

class Meta:
model = ResultaatType
fields = ("zaaktype", "status")
fields = ("zaaktype", "status", "datum_geldigheid", "zaaktype_identificatie")


class StatusTypeFilter(FilterSet):
Expand All @@ -120,10 +149,17 @@ class StatusTypeFilter(FilterSet):
help_text=STATUS_HELP_TEXT,
choices=StatusChoices.choices,
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)
zaaktype_identificatie = filters.CharFilter(
field_name="zaaktype__identificatie",
help_text=get_help_text("catalogi.ZaakType", "identificatie"),
)

class Meta:
model = StatusType
fields = ("zaaktype", "status")
fields = ("zaaktype", "status", "datum_geldigheid", "zaaktype_identificatie")


class EigenschapFilter(FilterSet):
Expand All @@ -133,10 +169,17 @@ class EigenschapFilter(FilterSet):
help_text=STATUS_HELP_TEXT,
choices=StatusChoices.choices,
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)
zaaktype_identificatie = filters.CharFilter(
field_name="zaaktype__identificatie",
help_text=get_help_text("catalogi.ZaakType", "identificatie"),
)

class Meta:
model = Eigenschap
fields = ("zaaktype", "status")
fields = ("zaaktype", "status", "datum_geldigheid", "zaaktype_identificatie")


class ZaakTypeFilter(FilterSet):
Expand All @@ -147,10 +190,19 @@ class ZaakTypeFilter(FilterSet):
choices=StatusChoices.choices,
)
trefwoorden = CharArrayFilter(field_name="trefwoorden", lookup_expr="contains")
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)

class Meta:
model = ZaakType
fields = ("catalogus", "identificatie", "trefwoorden", "status")
fields = (
"catalogus",
"identificatie",
"trefwoorden",
"status",
"datum_geldigheid",
)


class InformatieObjectTypeFilter(FilterSet):
Expand All @@ -160,10 +212,13 @@ class InformatieObjectTypeFilter(FilterSet):
help_text=STATUS_HELP_TEXT,
choices=StatusChoices.choices,
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)

class Meta:
model = InformatieObjectType
fields = ("catalogus", "status")
fields = ("catalogus", "status", "omschrijving", "datum_geldigheid")


class BesluitTypeFilter(FilterSet):
Expand All @@ -190,10 +245,20 @@ class BesluitTypeFilter(FilterSet):
help_text=STATUS_HELP_TEXT,
choices=StatusChoices.choices,
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)

class Meta:
model = BesluitType
fields = ("catalogus", "zaaktypen", "informatieobjecttypen", "status")
fields = (
"catalogus",
"zaaktypen",
"informatieobjecttypen",
"status",
"omschrijving",
"datum_geldigheid",
)


class CatalogusFilter(FilterSet):
Expand All @@ -208,6 +273,9 @@ class ZaakObjectTypeFilter(FilterSet):
queryset=Catalogus.objects.all(),
help_text=get_help_text("catalogi.ZaakType", "catalogus"),
)
datum_geldigheid = filters.DateFilter(
method=geldigheid_filter, help_text=DATUM_GELDIGHEID_HELP_TEXT,
)
zaaktype_identificatie = filters.CharFilter(
field_name="zaaktype__identificatie",
help_text=get_help_text("catalogi.ZaakType", "identificatie"),
Expand All @@ -220,6 +288,9 @@ class Meta:
"catalogus",
"objecttype",
"relatie_omschrijving",
"datum_begin_geldigheid",
"datum_einde_geldigheid",
"datum_geldigheid",
"zaaktype",
"zaaktype_identificatie",
)
41 changes: 39 additions & 2 deletions src/openzaak/components/catalogi/tests/test_besluittype.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2019 - 2020 Dimpact
from datetime import date

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

from openzaak.tests.utils import ClearCachesMixin

from ..api.scopes import SCOPE_CATALOGI_READ, SCOPE_CATALOGI_WRITE
from ..api.validators import (
Expand Down Expand Up @@ -681,8 +685,9 @@ def test_partial_update_besluittype_einde_geldigheid_related_to_non_concept_reso
besluittype.delete()


class BesluitTypeFilterAPITests(APITestCase):
class BesluitTypeFilterAPITests(ClearCachesMixin, APITestCase):
maxDiff = None
url = reverse_lazy("besluittype-list")

def test_filter_besluittype_status_alles(self):
BesluitTypeFactory.create(concept=True)
Expand Down Expand Up @@ -776,6 +781,38 @@ def test_validate_unknown_query_params(self):
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")

def test_filter_omschrijving(self):
besluittype1 = BesluitTypeFactory.create(omschrijving="some", concept=False)
BesluitTypeFactory.create(omschrijving="other", concept=False)

response = self.client.get(self.url, {"omschrijving": "some"})

self.assertEqual(response.status_code, 200)

data = response.json()["results"]

self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(besluittype1)}")

def test_filter_geldigheid(self):
besluittype = BesluitTypeFactory.create(
concept=False,
datum_begin_geldigheid=date(2020, 1, 1),
zaaktypen=[],
datum_einde_geldigheid=date(2020, 2, 1),
)
BesluitTypeFactory.create(
concept=False, datum_begin_geldigheid=date(2020, 2, 1),
)

response = self.client.get(self.url, {"datumGeldigheid": "2020-01-10"})
self.assertEqual(response.status_code, 200)

data = response.json()["results"]

self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(besluittype)}")


class BesluitTypePaginationTestCase(APITestCase):
maxDiff = None
Expand Down
42 changes: 41 additions & 1 deletion src/openzaak/components/catalogi/tests/test_eigenschap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

from rest_framework import status
from vng_api_common.constants import ComponentTypes
from vng_api_common.tests import TypeCheckMixin, get_validation_errors, reverse
from vng_api_common.tests import (
TypeCheckMixin,
get_validation_errors,
reverse,
reverse_lazy,
)

from ..api.scopes import SCOPE_CATALOGI_READ, SCOPE_CATALOGI_WRITE
from ..api.validators import ZaakTypeConceptValidator
Expand Down Expand Up @@ -755,6 +760,7 @@ def test_patch_eigenschap_with_statustype_another_zaaktype_fail(self):

class EigenschapFilterAPITests(APITestCase):
maxDiff = None
url = reverse_lazy("eigenschap-list")

def test_filter_eigenschap_status_alles(self):
EigenschapFactory.create(zaaktype__concept=True)
Expand Down Expand Up @@ -811,6 +817,40 @@ def test_validate_unknown_query_params(self):
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")

def test_filter_zaaktype_identificatie(self):
eigenschap = EigenschapFactory.create(
zaaktype__identificatie="some", zaaktype__concept=False
)
EigenschapFactory.create(
zaaktype__identificatie="other", zaaktype__concept=False
)

response = self.client.get(self.url, {"zaaktypeIdentificatie": "some"})

self.assertEqual(response.status_code, 200)

data = response.json()["results"]
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(eigenschap)}")

def test_filter_geldigheid(self):
eigenschap = EigenschapFactory.create(
datum_begin_geldigheid=date(2020, 1, 1),
datum_einde_geldigheid=date(2020, 2, 1),
zaaktype__concept=False,
)
EigenschapFactory.create(
datum_begin_geldigheid=date(2020, 2, 1), zaaktype__concept=False
)

response = self.client.get(self.url, {"datumGeldigheid": "2020-01-10"})

self.assertEqual(response.status_code, 200)

data = response.json()["results"]
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(eigenschap)}")


class EigenschapPaginationTestCase(APITestCase):
maxDiff = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2019 - 2020 Dimpact
from datetime import date

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

from ..api.scopes import SCOPE_CATALOGI_READ, SCOPE_CATALOGI_WRITE
from ..api.validators import ConceptUpdateValidator, M2MConceptUpdateValidator
Expand Down Expand Up @@ -601,6 +603,7 @@ def test_partial_update_informatieobjecttype_einde_geldigheid_related_to_non_con

class InformatieObjectTypeFilterAPITests(APITestCase):
maxDiff = None
url = reverse_lazy("informatieobjecttype-list")

def test_filter_informatieobjecttype_status_alles(self):
InformatieObjectTypeFactory.create(concept=True)
Expand Down Expand Up @@ -663,6 +666,37 @@ def test_validate_unknown_query_params(self):
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unknown-parameters")

def test_filter_omschrijving(self):
iotype = InformatieObjectTypeFactory.create(omschrijving="some", concept=False)
InformatieObjectTypeFactory.create(omschrijving="other", concept=False)

response = self.client.get(self.url, {"omschrijving": "some"})

self.assertEqual(response.status_code, 200)

data = response.json()["results"]

self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(iotype)}")

def test_filter_geldigheid(self):
iotype = InformatieObjectTypeFactory.create(
datum_begin_geldigheid=date(2020, 1, 1),
datum_einde_geldigheid=date(2020, 2, 1),
concept=False,
)
InformatieObjectTypeFactory.create(
datum_begin_geldigheid=date(2020, 2, 1), concept=False
)

response = self.client.get(self.url, {"datumGeldigheid": "2020-01-10"})

self.assertEqual(response.status_code, 200)

data = response.json()["results"]
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["url"], f"http://testserver{reverse(iotype)}")


class InformatieObjectTypePaginationTestCase(APITestCase):
maxDiff = None
Expand Down

0 comments on commit 1f5dbc9

Please sign in to comment.