Skip to content

Commit

Permalink
enabled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBekendam committed Mar 17, 2023
1 parent d6002e3 commit a7b9f44
Show file tree
Hide file tree
Showing 29 changed files with 2,387 additions and 2,336 deletions.
45 changes: 22 additions & 23 deletions src/ztc/accounts/tests/test_user_manager.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# from django.test import TestCase
#
# from ..models import User
#
#
# class UserManagerTests(TestCase):
# def test_create_superuser(self):
# user = User.objects.create_superuser("god", "[email protected]", "praisejebus")
# self.assertIsNotNone(user.pk)
# self.assertTrue(user.is_staff)
# self.assertTrue(user.is_superuser)
# self.assertEqual(user.username, "god")
# self.assertEqual(user.email, "[email protected]")
# self.assertTrue(user.check_password("praisejebus"))
# self.assertNotEqual(user.password, "praisejebus")
#
# def test_create_user(self):
# user = User.objects.create_user("infidel")
# self.assertIsNotNone(user.pk)
# self.assertFalse(user.is_superuser)
# self.assertFalse(user.is_staff)
# self.assertFalse(user.has_usable_password())
#todo putback
from django.test import TestCase

from ..models import User


class UserManagerTests(TestCase):
def test_create_superuser(self):
user = User.objects.create_superuser("god", "[email protected]", "praisejebus")
self.assertIsNotNone(user.pk)
self.assertTrue(user.is_staff)
self.assertTrue(user.is_superuser)
self.assertEqual(user.username, "god")
self.assertEqual(user.email, "[email protected]")
self.assertTrue(user.check_password("praisejebus"))
self.assertNotEqual(user.password, "praisejebus")

def test_create_user(self):
user = User.objects.create_user("infidel")
self.assertIsNotNone(user.pk)
self.assertFalse(user.is_superuser)
self.assertFalse(user.is_staff)
self.assertFalse(user.has_usable_password())
12 changes: 9 additions & 3 deletions src/ztc/api/serializers/besluittype.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class Meta:
"required": True,
"allow_empty": True,
},
"zaaktypen": {"lookup_field": "uuid", "allow_empty": True, "read_only": True},
"zaaktypen": {
"lookup_field": "uuid",
"allow_empty": True,
"read_only": True,
},
"resultaattypen": {
"lookup_field": "uuid",
"read_only": True,
Expand Down Expand Up @@ -90,8 +94,10 @@ class Meta:


class BesluitTypeCreateSerializer(BesluitTypeSerializer):
informatieobjecttypen = serializers.ListSerializer(child=serializers.CharField(),
help_text="`Omschrijvingen` van het INFORMATIEOBJECTTYPE van informatieobjecten waarin besluiten van dit BESLUITTYPE worden vastgelegd.")
informatieobjecttypen = serializers.ListSerializer(
child=serializers.CharField(),
help_text="`Omschrijvingen` van het INFORMATIEOBJECTTYPE van informatieobjecten waarin besluiten van dit BESLUITTYPE worden vastgelegd.",
)


class BesluitTypeUpdateSerializer(BesluitTypeCreateSerializer):
Expand Down
1 change: 0 additions & 1 deletion src/ztc/api/serializers/informatieobjecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,3 @@ def __init__(self, *args, **kwargs):
self.fields[
"vertrouwelijkheidaanduiding"
].help_text += f"\n\n{value_display_mapping}"

11 changes: 8 additions & 3 deletions src/ztc/api/serializers/relatieklassen.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ def validate(self, attrs):
return validated_data


class ZaakTypeInformatieObjectTypeCreateSerializer(ZaakTypeInformatieObjectTypeSerializer):
class ZaakTypeInformatieObjectTypeCreateSerializer(
ZaakTypeInformatieObjectTypeSerializer
):
informatieobjecttype = serializers.CharField(
help_text="`Omschrijvingen` van het INFORMATIEOBJECTTYPE van informatieobjecten waarin besluiten van dit BESLUITTYPE worden vastgelegd.")
help_text="`Omschrijvingen` van het INFORMATIEOBJECTTYPE van informatieobjecten waarin besluiten van dit BESLUITTYPE worden vastgelegd."
)


class ZaakTypeInformatieObjectTypeUpdateSerializer(ZaakTypeInformatieObjectTypeCreateSerializer):
class ZaakTypeInformatieObjectTypeUpdateSerializer(
ZaakTypeInformatieObjectTypeCreateSerializer
):
pass
6 changes: 4 additions & 2 deletions src/ztc/api/serializers/resultaattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ def __init__(self, *args, **kwargs):


class ResultaatTypeCreateSerializer(ResultaatTypeSerializer):
besluittypen = serializers.ListSerializer(child=serializers.CharField(),
help_text="")
besluittypen = serializers.ListSerializer(
child=serializers.CharField(), help_text=""
)


class ResultaatTypeUpdateSerializer(ResultaatTypeCreateSerializer):
pass
16 changes: 11 additions & 5 deletions src/ztc/api/serializers/zaken.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def __init__(self, *args, **kwargs):


class ZaakTypenRelatieCreateSerializer(ZaakTypenRelatieSerializer):
zaaktype = serializers.CharField(help_text=_("`zaaktype.identificatie` naar het ZAAKTYPE."))
zaaktype = serializers.CharField(
help_text=_("`zaaktype.identificatie` naar het ZAAKTYPE.")
)


class ZaakTypeSerializer(
Expand Down Expand Up @@ -241,10 +243,14 @@ def validate(self, attrs):


class ZaakTypeCreateSerializer(ZaakTypeSerializer):
besluittypen = serializers.ListSerializer(child=serializers.CharField(),
help_text="`Omschrijvingen` van BESLUITTYPEN die mogelijk zijn binnen dit ZAAKTYPE.")
deelzaaktypen = serializers.ListSerializer(child=serializers.CharField(),
help_text="De `zaaktypen.identificaties` waaronder ZAAKen als deelzaak kunnen voorkomen bij ZAAKen van dit ZAAKTYPE.")
besluittypen = serializers.ListSerializer(
child=serializers.CharField(),
help_text="`Omschrijvingen` van BESLUITTYPEN die mogelijk zijn binnen dit ZAAKTYPE.",
)
deelzaaktypen = serializers.ListSerializer(
child=serializers.CharField(),
help_text="De `zaaktypen.identificaties` waaronder ZAAKen als deelzaak kunnen voorkomen bij ZAAKen van dit ZAAKTYPE.",
)
gerelateerde_zaaktypen = ZaakTypenRelatieCreateSerializer(
many=True,
source="zaaktypenrelaties",
Expand Down
4 changes: 3 additions & 1 deletion src/ztc/api/tests/test_besluittype.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_get_list_default_definitief(self):

def test_get_detail(self):
"""Retrieve the details of a single `BesluitType` object."""
zaaktype = ZaakTypeFactory(catalogus=self.catalogus, datum_begin_geldigheid="2018-01-01")
zaaktype = ZaakTypeFactory(
catalogus=self.catalogus, datum_begin_geldigheid="2018-01-01"
)

resultaattype = ResultaatTypeFactory(zaaktype=zaaktype)

Expand Down
4 changes: 3 additions & 1 deletion src/ztc/api/tests/test_relatieklassen.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def test_create_ziot_fail_not_concept_zaaktype_and_informatieobjecttype(self):
def test_create_ziot_fail_catalogus_mismatch(self):
zaaktype = ZaakTypeFactory.create()
zaaktype_url = reverse(zaaktype)
informatieobjecttype = InformatieObjectTypeFactory.create(concept=False, omschrijving="test") #todo make ticket omschrijving/identficatie verplicht veld
informatieobjecttype = InformatieObjectTypeFactory.create(
concept=False, omschrijving="test"
) # todo make ticket omschrijving/identficatie verplicht veld
informatieobjecttype_url = reverse(informatieobjecttype)
data = {
"zaaktype": f"http://testserver{zaaktype_url}",
Expand Down
8 changes: 6 additions & 2 deletions src/ztc/api/tests/test_resultaattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,18 @@ def test_create_resultaattype(self, mock_shape, mock_fetch):
m.register_uri(
"GET", resultaattypeomschrijving_url, json={"omschrijving": "test"}
)
response = self.client.post(self.list_url, data, SERVER_NAME="testserver.com")
response = self.client.post(
self.list_url, data, SERVER_NAME="testserver.com"
)

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

resultaattype = response.json()

self.assertEqual(resultaattype["omschrijvingGeneriek"], "test")
self.assertEqual(resultaattype["zaaktype"], f"http://testserver.com{zaaktype_url}")
self.assertEqual(
resultaattype["zaaktype"], f"http://testserver.com{zaaktype_url}"
)
self.assertEqual(
resultaattype["brondatumArchiefprocedure"]["afleidingswijze"],
Afleidingswijze.afgehandeld,
Expand Down
24 changes: 14 additions & 10 deletions src/ztc/api/utils/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

from django.db.models import Q

from ztc.datamodel.models import BesluitType, InformatieObjectType, ZaakType, ResultaatType
from ztc.datamodel.models import (
BesluitType,
InformatieObjectType,
ResultaatType,
ZaakType,
)


def is_url(pattern: str):
Expand Down Expand Up @@ -93,7 +98,7 @@ def m2m_array_of_str_to_url(request, m2m_fields: list, action: str):
search_parameter = (
Q(omschrijving=m2m_str)
if MAPPING_FIELD_TO_MODEL[m2m_field]
in [BesluitType, InformatieObjectType]
in [BesluitType, InformatieObjectType]
else Q(
identificatie=m2m_str
if m2m_field != "gerelateerde_zaaktypen"
Expand Down Expand Up @@ -143,15 +148,14 @@ def remove_invalid_m2m(serializer, m2m_fields: list, action: str, date=None):


def get_valid_m2m_objects(m2m_field: str, uuid_from_url, date=None):
search_parameter = Q(uuid=uuid_from_url,
datum_begin_geldigheid__lte=date if date else datetime.datetime.now(),
datum_einde_geldigheid__gte=date if date else datetime.datetime.now())

qs_old_version = MAPPING_FIELD_TO_MODEL[m2m_field].objects.filter(
search_parameter
search_parameter = Q(
uuid=uuid_from_url,
datum_begin_geldigheid__lte=date if date else datetime.datetime.now(),
datum_einde_geldigheid__gte=date if date else datetime.datetime.now(),
)

qs_old_version = MAPPING_FIELD_TO_MODEL[m2m_field].objects.filter(search_parameter)
if not qs_old_version:
search_parameter = Q(datum_einde_geldigheid=None,
uuid=uuid_from_url)
search_parameter = Q(datum_einde_geldigheid=None, uuid=uuid_from_url)
return MAPPING_FIELD_TO_MODEL[m2m_field].objects.filter(search_parameter)
return qs_old_version
22 changes: 15 additions & 7 deletions src/ztc/api/views/besluittype.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
SCOPE_CATALOGI_READ,
SCOPE_CATALOGI_WRITE,
)
from ..serializers import BesluitTypeSerializer, BesluitTypeCreateSerializer, BesluitTypeUpdateSerializer
from ..serializers import (
BesluitTypeCreateSerializer,
BesluitTypeSerializer,
BesluitTypeUpdateSerializer,
)
from ..utils.viewsets import m2m_array_of_str_to_url, remove_invalid_m2m
from .mixins import (
ConceptMixin,
Expand Down Expand Up @@ -129,15 +133,20 @@ def retrieve(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
self._check_query_params(request)
queryset = self.filter_queryset(self.get_queryset())
filters = self.filter_backends[0]().get_filterset_kwargs(self.request, queryset, self).get('data', {})
filters = (
self.filter_backends[0]()
.get_filterset_kwargs(self.request, queryset, self)
.get("data", {})
)

page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
serializer = remove_invalid_m2m(
serializer, ["zaaktypen", "informatieobjecttypen", "resultaattypen"], self.action,
filters.get("datum_geldigheid", None
)
serializer,
["zaaktypen", "informatieobjecttypen", "resultaattypen"],
self.action,
filters.get("datum_geldigheid", None),
)
return self.get_paginated_response(serializer.data)

Expand All @@ -146,8 +155,7 @@ def list(self, request, *args, **kwargs):
serializer,
["zaaktypen", "informatieobjecttypen", "resultaattypen"],
self.action,
filters.get("datum_geldigheid", None
)
filters.get("datum_geldigheid", None),
)

return Response(serializer.data)
Expand Down
20 changes: 15 additions & 5 deletions src/ztc/api/views/informatieobjecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,29 @@ def retrieve(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
self._check_query_params(request)
queryset = self.filter_queryset(self.get_queryset())
filters = self.filter_backends[0]().get_filterset_kwargs(self.request, queryset, self).get('data', {})
filters = (
self.filter_backends[0]()
.get_filterset_kwargs(self.request, queryset, self)
.get("data", {})
)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
serializer = remove_invalid_m2m(
serializer, ["besluittypen", "zaaktypen"], self.action, filters.get("datum_geldigheid", None
))
serializer,
["besluittypen", "zaaktypen"],
self.action,
filters.get("datum_geldigheid", None),
)
return self.get_paginated_response(serializer.data)

serializer = self.get_serializer(queryset, many=True)
serializer = remove_invalid_m2m(
serializer, ["besluittypen", "zaaktypen"], self.action, filters.get("datum_geldigheid", None
))
serializer,
["besluittypen", "zaaktypen"],
self.action,
filters.get("datum_geldigheid", None),
)

return Response(serializer.data)

Expand Down
9 changes: 6 additions & 3 deletions src/ztc/api/views/relatieklassen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
SCOPE_CATALOGI_READ,
SCOPE_CATALOGI_WRITE,
)
from ..serializers import ZaakTypeInformatieObjectTypeSerializer, ZaakTypeInformatieObjectTypeCreateSerializer, \
ZaakTypeInformatieObjectTypeUpdateSerializer
from ..serializers import (
ZaakTypeInformatieObjectTypeCreateSerializer,
ZaakTypeInformatieObjectTypeSerializer,
ZaakTypeInformatieObjectTypeUpdateSerializer,
)
from ..utils.viewsets import build_absolute_url
from .mixins import ConceptFilterMixin, ForcedCreateUpdateMixin

Expand Down Expand Up @@ -151,7 +154,7 @@ def update(self, request, *args, **kwargs):
search_parameter = Q(
informatieobjecttype__omschrijving=instance.informatieobjecttype.omschrijving,
informatieobjecttype__catalogus=instance.informatieobjecttype.catalogus,
zaaktype__catalogus=instance.zaaktype.catalogus
zaaktype__catalogus=instance.zaaktype.catalogus,
)
ziots = ZaakInformatieobjectType.objects.filter(search_parameter)

Expand Down
30 changes: 23 additions & 7 deletions src/ztc/api/views/resultaattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
SCOPE_CATALOGI_READ,
SCOPE_CATALOGI_WRITE,
)
from ..serializers import ResultaatTypeSerializer, ResultaatTypeCreateSerializer, ResultaatTypeUpdateSerializer
from ..serializers import (
ResultaatTypeCreateSerializer,
ResultaatTypeSerializer,
ResultaatTypeUpdateSerializer,
)
from ..utils.viewsets import m2m_array_of_str_to_url, remove_invalid_m2m
from .mixins import ForcedCreateUpdateMixin, ZaakTypeConceptMixin

Expand Down Expand Up @@ -78,6 +82,7 @@ class ResultaatTypeViewSet(
"partial_update": SCOPE_CATALOGI_WRITE | SCOPE_CATALOGI_FORCED_WRITE,
"destroy": SCOPE_CATALOGI_WRITE | SCOPE_CATALOGI_FORCED_DELETE,
}

@extend_schema(
request=ResultaatTypeCreateSerializer,
responses={201: ResultaatTypeSerializer},
Expand All @@ -104,18 +109,29 @@ def update(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
self._check_query_params(request)
queryset = self.filter_queryset(self.get_queryset())
filters = self.filter_backends[0]().get_filterset_kwargs(self.request, queryset, self).get('data', {})
filters = (
self.filter_backends[0]()
.get_filterset_kwargs(self.request, queryset, self)
.get("data", {})
)

page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
serializer = remove_invalid_m2m(serializer, ["besluittypen"], self.action,
filters.get("datum_geldigheid", None)
)
serializer = remove_invalid_m2m(
serializer,
["besluittypen"],
self.action,
filters.get("datum_geldigheid", None),
)
return self.get_paginated_response(serializer.data)

serializer = self.get_serializer(queryset, many=True)
serializer = remove_invalid_m2m(serializer, ["besluittypen"], self.action, filters.get("datum_geldigheid", None)
)
serializer = remove_invalid_m2m(
serializer,
["besluittypen"],
self.action,
filters.get("datum_geldigheid", None),
)

return Response(serializer.data)
Loading

0 comments on commit a7b9f44

Please sign in to comment.