Skip to content

Commit 7fb4ce5

Browse files
[#267] PR suggestions
1 parent 07af204 commit 7fb4ce5

File tree

7 files changed

+49
-35
lines changed

7 files changed

+49
-35
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def clean(self):
5252
partij_identificator=partij_identificator,
5353
sub_identificator_van=cleaned_data["sub_identificator_van"],
5454
partij=cleaned_data["partij"],
55-
).validate()
55+
)()
5656

5757
return cleaned_data
5858

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class Meta:
373373
}
374374

375375
def validate(self, attrs):
376-
PartijIdentificatorTypesValidator(partij_identificator=attrs).validate()
376+
PartijIdentificatorTypesValidator(partij_identificator=attrs)()
377377
return super().validate(attrs)
378378

379379

@@ -433,7 +433,7 @@ def validate(self, attrs):
433433
partij_identificator=partij_identificator,
434434
sub_identificator_van=sub_identificator_van,
435435
partij=partij,
436-
).validate()
436+
)()
437437

438438
attrs["sub_identificator_van"] = get_field_instance_by_uuid(
439439
self, attrs, "sub_identificator_van", PartijIdentificator

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ def test_invalid_update_unique_set_sub_identificator_van_self(self):
25012501
self.assertEqual(response.data["title"], "Invalid input.")
25022502
self.assertEqual(
25032503
response.data["invalid_params"][0]["reason"],
2504-
"Kan zichzelf niet selecteren als `sub_identificator_van`.",
2504+
"Kan zichzelf niet selecteren als `subIdentificatorVan`.",
25052505
)
25062506

25072507
def test_vestigingsnummer_valid_create(self):
@@ -2545,7 +2545,7 @@ def test_vestigingsnummer_invalid_create_without_sub_identificator_van(self):
25452545
self.assertEqual(response.data["code"], "invalid")
25462546
self.assertEqual(response.data["title"], "Invalid input.")
25472547
self.assertTrue(
2548-
"`sub_identifier_van` met CodeSoortObjectId = `kvk_nummer` te kiezen."
2548+
"`sub_identifier_van` met codeSoortObjectId = `kvk_nummer` te kiezen."
25492549
in response.data["invalid_params"][0]["reason"]
25502550
)
25512551

@@ -2754,7 +2754,7 @@ def test_vestigingsnummer_invalid_update_set_sub_identificator_van_null(self):
27542754
self.assertEqual(response.data["code"], "invalid")
27552755
self.assertEqual(response.data["title"], "Invalid input.")
27562756
self.assertTrue(
2757-
"`sub_identifier_van` met CodeSoortObjectId = `kvk_nummer` te kiezen."
2757+
"`sub_identifier_van` met codeSoortObjectId = `kvk_nummer` te kiezen."
27582758
in response.data["invalid_params"][0]["reason"]
27592759
)
27602760

src/openklant/components/klantinteracties/migrations/0028_partijidentificator_sub_identificator_van.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class Migration(migrations.Migration):
1919
name="sub_identificator_van",
2020
field=models.ForeignKey(
2121
blank=True,
22-
help_text="Expresses that one PartijIdentificator is bound to another one",
22+
help_text=(
23+
"The parent PartijIdentificator under which this PartijIdentificator is unique "
24+
"(e.g. the parent identificator could specify a KVK number and the child identificator "
25+
"could specify a vestigingsnummer that is unique for the KVK number)."
26+
),
2327
null=True,
2428
on_delete=django.db.models.deletion.SET_NULL,
2529
related_name="parent_partij_identificator",

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ class PartijIdentificator(models.Model):
338338
"self",
339339
on_delete=models.SET_NULL,
340340
verbose_name=_("sub identificator van"),
341-
help_text=_("Expresses that one PartijIdentificator is bound to another one"),
341+
help_text=_(
342+
"The parent PartijIdentificator under which this PartijIdentificator is unique "
343+
"(e.g. the parent identificator could specify a KVK number and the child "
344+
"identificator could specify a vestigingsnummer that is unique for the KVK number)."
345+
),
342346
blank=True,
343347
null=True,
344348
related_name="parent_partij_identificator",

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

+20-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
validate_rsin,
88
)
99

10-
from openklant.components.klantinteracties.models.partijen import PartijIdentificator
10+
from openklant.components.klantinteracties.models.partijen import (
11+
Partij,
12+
PartijIdentificator,
13+
)
1114

1215
from .constants import (
1316
PartijIdentificatorCodeObjectType,
@@ -20,11 +23,17 @@
2023

2124

2225
class PartijIdentificatorUniquenessValidator:
23-
def __init__(self, *args, **kwargs):
24-
self.partij_identificator = kwargs.get("partij_identificator")
25-
self.sub_identificator_van = kwargs.get("sub_identificator_van")
26-
self.instance = kwargs.get("instance")
27-
self.partij = kwargs.get("partij")
26+
def __init__(
27+
self,
28+
partij_identificator: dict | None = {},
29+
sub_identificator_van: PartijIdentificator | None = None,
30+
instance: PartijIdentificator | None = None,
31+
partij: Partij | None = None,
32+
):
33+
self.partij_identificator = partij_identificator
34+
self.sub_identificator_van = sub_identificator_van
35+
self.instance = instance
36+
self.partij = partij
2837
self.queryset = PartijIdentificator.objects.all()
2938

3039
if self.instance:
@@ -33,7 +42,7 @@ def __init__(self, *args, **kwargs):
3342
if not self.partij_identificator:
3443
raise ValueError("partij_identificator is required")
3544

36-
def validate(self):
45+
def __call__(self):
3746
self.validate_not_self_assigned()
3847
if (
3948
self.partij_identificator["code_soort_object_id"]
@@ -51,7 +60,7 @@ def validate_not_self_assigned(self):
5160
raise ValidationError(
5261
{
5362
"sub_identificator_van": _(
54-
"Kan zichzelf niet selecteren als `sub_identificator_van`."
63+
"Kan zichzelf niet selecteren als `subIdentificatorVan`."
5564
)
5665
}
5766
)
@@ -70,8 +79,8 @@ def validate_sub_identificator_van_for_vestigingsnummer(self):
7079
raise ValidationError(
7180
{
7281
"sub_identificator_van": _(
73-
"Voor de Identificator met CodeSoortObjectId = `vestigingsnummer` is het verplicht om"
74-
" een `sub_identifier_van` met CodeSoortObjectId = `kvk_nummer` te kiezen."
82+
"Voor de Identificator met codeSoortObjectId = `vestigingsnummer` is het verplicht om"
83+
" een `sub_identifier_van` met codeSoortObjectId = `kvk_nummer` te kiezen."
7584
)
7685
}
7786
)
@@ -224,7 +233,7 @@ def __init__(self, partij_identificator: dict) -> None:
224233
self.code_soort_object_id = partij_identificator["code_soort_object_id"]
225234
self.object_id = partij_identificator["object_id"]
226235

227-
def validate(self) -> None:
236+
def __call__(self) -> None:
228237
"""Run all validations"""
229238
self.validate_code_objecttype()
230239
self.validate_code_soort_object_id()

src/openklant/components/klantinteracties/tests/test_validators.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818

1919
class PartijIdentificatorTypesValidatorTests(TestCase):
2020
def test_valid(self):
21-
validator = PartijIdentificatorTypesValidator(
21+
PartijIdentificatorTypesValidator(
2222
partij_identificator={
2323
"code_objecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon.value,
2424
"code_soort_object_id": PartijIdentificatorCodeSoortObjectId.bsn.value,
2525
"object_id": "296648875",
2626
"code_register": PartijIdentificatorCodeRegister.brp.value,
2727
}
28-
)
29-
validator.validate()
28+
)()
3029

3130
# Start section validate_code_objecttype
3231

@@ -325,15 +324,14 @@ def test_allowed_cases(self):
325324
],
326325
]
327326
for case in valid_cases:
328-
validator = PartijIdentificatorTypesValidator(
327+
PartijIdentificatorTypesValidator(
329328
partij_identificator={
330329
"code_register": case[0],
331330
"code_objecttype": case[1],
332331
"code_soort_object_id": case[2],
333332
"object_id": case[3],
334333
},
335-
)
336-
validator.validate()
334+
)()
337335

338336
def test_not_allowed_cases(self):
339337
invalid_cases = [
@@ -358,15 +356,14 @@ def test_not_allowed_cases(self):
358356
]
359357
for case in invalid_cases:
360358
with self.assertRaises(ValidationError):
361-
validator = PartijIdentificatorTypesValidator(
359+
PartijIdentificatorTypesValidator(
362360
partij_identificator={
363361
"code_register": case[0],
364362
"code_objecttype": case[1],
365363
"code_soort_object_id": case[2],
366364
"object_id": case[3],
367365
}
368-
)
369-
validator.validate()
366+
)()
370367

371368

372369
class PartijIdentificatorUniquenessValidatorTests(TestCase):
@@ -381,7 +378,7 @@ def test_valid_global_uniqueness(self):
381378
},
382379
sub_identificator_van=None,
383380
instance=None,
384-
).validate()
381+
)()
385382

386383
def test_valid_relation_sub_identificator_van(self):
387384
# check self relation and sub_identificator_van allowed cases
@@ -403,7 +400,7 @@ def test_valid_relation_sub_identificator_van(self):
403400
sub_identificator_van=sub_identificator_van,
404401
instance=None,
405402
partij=partij,
406-
).validate()
403+
)()
407404

408405
def test_invalid_self_relation_sub_identificator_van(self):
409406
partij_identificator = PartijIdentificatorFactory.create(
@@ -422,12 +419,12 @@ def test_invalid_self_relation_sub_identificator_van(self):
422419
},
423420
sub_identificator_van=partij_identificator,
424421
instance=partij_identificator,
425-
).validate()
422+
)()
426423

427424
details = error.exception.message_dict
428425
self.assertEqual(
429426
details["sub_identificator_van"][0],
430-
"Kan zichzelf niet selecteren als `sub_identificator_van`.",
427+
"Kan zichzelf niet selecteren als `subIdentificatorVan`.",
431428
)
432429

433430
def test_invalid_sub_identificator_van_type_not_allowed(self):
@@ -448,7 +445,7 @@ def test_invalid_sub_identificator_van_type_not_allowed(self):
448445
},
449446
sub_identificator_van=sub_identificator_van,
450447
instance=None,
451-
).validate()
448+
)()
452449

453450
details = error.exception.message_dict
454451
self.assertEqual(
@@ -469,10 +466,10 @@ def test_invalid_partij_identificator_vestigingsnummer_require_sub_identificator
469466
},
470467
sub_identificator_van=None,
471468
instance=None,
472-
).validate()
469+
)()
473470

474471
details = error.exception.message_dict
475472
self.assertTrue(
476-
"`sub_identifier_van` met CodeSoortObjectId = `kvk_nummer` te kiezen."
473+
"`sub_identifier_van` met codeSoortObjectId = `kvk_nummer` te kiezen."
477474
in details["sub_identificator_van"][0]
478475
)

0 commit comments

Comments
 (0)