Skip to content

Commit

Permalink
[#267] Fixed tests and general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Feb 27, 2025
1 parent 7ae59e6 commit d219378
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from glom import PathAccessError, glom
from rest_framework import serializers
from vng_api_common.serializers import GegevensGroepSerializer, NestedGegevensGroepMixin
from vng_api_common.utils import get_help_text

from openklant.components.klantinteracties.api.polymorphism import (
Discriminator,
Expand Down Expand Up @@ -395,7 +396,9 @@ class PartijIdentificatorSerializer(
sub_identificator_van = PartijIdentificatorForeignkeySerializer(
required=False,
allow_null=True,
help_text=_("Relatie sub_identificator_van"),
help_text=get_help_text(
"klantinteracties.PartijIdentificator", "sub_identificator_van"
),
)

class Meta:
Expand Down
17 changes: 8 additions & 9 deletions src/openklant/components/klantinteracties/models/partijen.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,14 @@ class Meta:
]

def clean_sub_identificator_van(self):
if self.sub_identificator_van:
if self.sub_identificator_van == self:
raise ValidationError(
{
"sub_identificator_van": _(
"Een `Partijidentificator` kan geen `subIdentificatorVan` zijn van zichzelf."
)
}
)
if self.sub_identificator_van and self.sub_identificator_van == self:
raise ValidationError(
{
"sub_identificator_van": _(
"Een `Partijidentificator` kan geen `subIdentificatorVan` zijn van zichzelf."
)
}
)

def save(self, *args, **kwargs):
self.full_clean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def test_valid_globally_unique(self):
partij_identificator_code_register="hr",
)

# different partij and different sub_identificator_van
partij_c = PartijFactory.create()
PartijIdentificator.objects.create(
partij=partij_c,
sub_identificator_van=partij_identificator_b,
partij_identificator_code_objecttype="vestiging",
partij_identificator_code_soort_object_id="vestigingsnummer",
partij_identificator_object_id="4567456745674567",
partij_identificator_code_register="hr",
)

# different values same sub_identificator_van
PartijIdentificator.objects.create(
partij=partij_a,
Expand Down Expand Up @@ -107,20 +118,20 @@ def test_scoped_identificator_globally_unique(self):
PartijIdentificator.objects.create(
partij=partij,
sub_identificator_van=sub_identificator_van,
partij_identificator_code_objecttype="natuurlijk_persoon",
partij_identificator_code_soort_object_id="bsn",
partij_identificator_object_id="123456782",
partij_identificator_code_register="brp",
partij_identificator_code_objecttype="vestiging",
partij_identificator_code_soort_object_id="vestigingsnummer",
partij_identificator_object_id="112233440001",
partij_identificator_code_register="hr",
)

with self.assertRaises(ValidationError) as error:
PartijIdentificator.objects.create(
partij=partij,
sub_identificator_van=sub_identificator_van,
partij_identificator_code_objecttype="natuurlijk_persoon",
partij_identificator_code_soort_object_id="bsn",
partij_identificator_object_id="123456782",
partij_identificator_code_register="brp",
partij_identificator_code_objecttype="vestiging",
partij_identificator_code_soort_object_id="vestigingsnummer",
partij_identificator_object_id="112233440001",
partij_identificator_code_register="hr",
)
self.assertEqual(
error.exception.message_dict,
Expand Down

0 comments on commit d219378

Please sign in to comment.