Skip to content

Commit

Permalink
Merge pull request #173 from open-zaak/issue/ziot-unique-fields
Browse files Browse the repository at this point in the history
add UniqueTogetherValidator to ZIOT serializer
  • Loading branch information
sergei-maertens committed Nov 7, 2019
2 parents ce18b18 + a2e5c2b commit 5528160
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.utils.translation import ugettext_lazy as _

from rest_framework import serializers
from rest_framework.validators import UniqueTogetherValidator
from vng_api_common.serializers import add_choice_values_help_text

from ...constants import RichtingChoices
Expand Down Expand Up @@ -31,7 +32,13 @@ class Meta:
"informatieobjecttype": {"lookup_field": "uuid"},
"statustype": {"lookup_field": "uuid"},
}
validators = [ZaakInformatieObjectTypeCatalogusValidator()]
validators = [
ZaakInformatieObjectTypeCatalogusValidator(),
UniqueTogetherValidator(
queryset=ZaakInformatieobjectType.objects.all(),
fields=["zaaktype", "volgnummer"],
),
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
19 changes: 19 additions & 0 deletions src/openzaak/components/catalogi/tests/test_relatieklassen.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ def test_create_ziot_fail_not_concept_informatieobjecttype(self):
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "non-concept-relation")

def test_create_ziot_fail_not_unique(self):
ziot = ZaakInformatieobjectTypeFactory(volgnummer=1)
informatieobjecttype = InformatieObjectTypeFactory.create(
catalogus=ziot.zaaktype.catalogus
)
data = {
"zaaktype": f"http://testserver.com{reverse(ziot.zaaktype)}",
"informatieobjecttype": f"http://testserver.com{reverse(informatieobjecttype)}",
"volgnummer": ziot.volgnummer,
"richting": RichtingChoices.inkomend,
}

response = self.client.post(self.list_url, data)

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

error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "unique")

def test_delete_ziot(self):
ziot = ZaakInformatieobjectTypeFactory.create()
ziot_url = reverse(ziot)
Expand Down

0 comments on commit 5528160

Please sign in to comment.