Skip to content

Commit d219378

Browse files
[#267] Fixed tests and general improvements
1 parent 7ae59e6 commit d219378

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/openklant/components/klantinteracties/api/serializers/partijen.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from glom import PathAccessError, glom
88
from rest_framework import serializers
99
from vng_api_common.serializers import GegevensGroepSerializer, NestedGegevensGroepMixin
10+
from vng_api_common.utils import get_help_text
1011

1112
from openklant.components.klantinteracties.api.polymorphism import (
1213
Discriminator,
@@ -395,7 +396,9 @@ class PartijIdentificatorSerializer(
395396
sub_identificator_van = PartijIdentificatorForeignkeySerializer(
396397
required=False,
397398
allow_null=True,
398-
help_text=_("Relatie sub_identificator_van"),
399+
help_text=get_help_text(
400+
"klantinteracties.PartijIdentificator", "sub_identificator_van"
401+
),
399402
)
400403

401404
class Meta:

src/openklant/components/klantinteracties/models/partijen.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,14 @@ class Meta:
460460
]
461461

462462
def clean_sub_identificator_van(self):
463-
if self.sub_identificator_van:
464-
if self.sub_identificator_van == self:
465-
raise ValidationError(
466-
{
467-
"sub_identificator_van": _(
468-
"Een `Partijidentificator` kan geen `subIdentificatorVan` zijn van zichzelf."
469-
)
470-
}
471-
)
463+
if self.sub_identificator_van and self.sub_identificator_van == self:
464+
raise ValidationError(
465+
{
466+
"sub_identificator_van": _(
467+
"Een `Partijidentificator` kan geen `subIdentificatorVan` zijn van zichzelf."
468+
)
469+
}
470+
)
472471

473472
def save(self, *args, **kwargs):
474473
self.full_clean()

src/openklant/components/klantinteracties/models/tests/test_partijen.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ def test_valid_globally_unique(self):
4848
partij_identificator_code_register="hr",
4949
)
5050

51+
# different partij and different sub_identificator_van
52+
partij_c = PartijFactory.create()
53+
PartijIdentificator.objects.create(
54+
partij=partij_c,
55+
sub_identificator_van=partij_identificator_b,
56+
partij_identificator_code_objecttype="vestiging",
57+
partij_identificator_code_soort_object_id="vestigingsnummer",
58+
partij_identificator_object_id="4567456745674567",
59+
partij_identificator_code_register="hr",
60+
)
61+
5162
# different values same sub_identificator_van
5263
PartijIdentificator.objects.create(
5364
partij=partij_a,
@@ -107,20 +118,20 @@ def test_scoped_identificator_globally_unique(self):
107118
PartijIdentificator.objects.create(
108119
partij=partij,
109120
sub_identificator_van=sub_identificator_van,
110-
partij_identificator_code_objecttype="natuurlijk_persoon",
111-
partij_identificator_code_soort_object_id="bsn",
112-
partij_identificator_object_id="123456782",
113-
partij_identificator_code_register="brp",
121+
partij_identificator_code_objecttype="vestiging",
122+
partij_identificator_code_soort_object_id="vestigingsnummer",
123+
partij_identificator_object_id="112233440001",
124+
partij_identificator_code_register="hr",
114125
)
115126

116127
with self.assertRaises(ValidationError) as error:
117128
PartijIdentificator.objects.create(
118129
partij=partij,
119130
sub_identificator_van=sub_identificator_van,
120-
partij_identificator_code_objecttype="natuurlijk_persoon",
121-
partij_identificator_code_soort_object_id="bsn",
122-
partij_identificator_object_id="123456782",
123-
partij_identificator_code_register="brp",
131+
partij_identificator_code_objecttype="vestiging",
132+
partij_identificator_code_soort_object_id="vestigingsnummer",
133+
partij_identificator_object_id="112233440001",
134+
partij_identificator_code_register="hr",
124135
)
125136
self.assertEqual(
126137
error.exception.message_dict,

0 commit comments

Comments
 (0)