Skip to content

Commit

Permalink
[#233] Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 23, 2024
1 parent a7288d5 commit 3e15771
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ def test_invalid_validation_partij_identificator_object_id(self):
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid")
self.assertEqual(
response.data["invalid_params"][0]["reason"],
"Ongeldig BSN.",
"ObjectId ongeldig, reden: The length must be in: [8, 9]",
)

def test_valid_validation_partij_identificator(self):
Expand Down
34 changes: 10 additions & 24 deletions src/openklant/components/klantinteracties/models/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ class ObjectIdValidator:
Validates an ObjectId based on digit check, length, and optional 11-proof check.
"""

list_size: List[int] = []
error_messages = {
"isdigit": "Expected a numerical value",
"length": "The length must be in: {list_size}",
"11proefnumber": "Invalid code",
}

def __init__(
self,
value: str,
Expand All @@ -37,17 +30,13 @@ def __init__(
def validate_isdigit(self) -> None:
"""Validates that the value contains only digits."""
if not self.value.isdigit():
raise ValidationError(
self.error_messages["isdigit"],
code="invalid",
)
raise ValidationError("Expected a numerical value", code="invalid")

def validate_length(self) -> None:
"""Validates that the length of the value is within the allowed sizes."""
if len(self.value) not in self.list_size:
raise ValidationError(
self.error_messages["length"].format(list_size=self.list_size),
code="invalid",
"The length must be in: %s" % self.list_size, code="invalid"
)

def validate_11proefnumber(self) -> None:
Expand All @@ -60,10 +49,7 @@ def validate_11proefnumber(self) -> None:
total += multiplier * int(char)

if total % 11 != 0:
raise ValidationError(
self.error_messages["11proefnumber"],
code="invalid",
)
raise ValidationError("Invalid code", code="invalid")

def validate(self) -> None:
self.validate_isdigit()
Expand Down Expand Up @@ -102,15 +88,15 @@ def __init__(
code_objecttype: str,
code_soort_object_id: str,
object_id: str,
):
"""Init fields"""
) -> None:
"""Initialize validator"""
self.code_register = code_register
self.code_objecttype = code_objecttype
self.code_soort_object_id = code_soort_object_id
self.object_id = object_id

def validate(self) -> None:
"""Validate all fields"""
"""Run all validations"""
self.validate_code_objecttype()
self.validate_code_soort_object_id()
self.validate_object_id()
Expand Down Expand Up @@ -181,17 +167,17 @@ def validate_object_id(self) -> None:
)

def _validate_bsn(self) -> None:
"""Validates the bsn object_id"""
"""Validate BSN"""
ObjectIdValidator(self.object_id, [8, 9], True).validate()

def _validate_vestigingsnummer(self) -> None:
"""Validates the vestigingsNummer object_id"""
"""Validate Vestigingsnummer"""
ObjectIdValidator(self.object_id, [12], False).validate()

def _validate_rsin(self) -> None:
"""Validates the rsin object_id"""
"""Validate RSIN"""
ObjectIdValidator(self.object_id, [8, 9], True).validate()

def _validate_kvknummer(self) -> None:
"""Validates the kvkNummer object_id"""
"""Validate Kvk_nummer"""
ObjectIdValidator(self.object_id, [8], False).validate()

0 comments on commit 3e15771

Please sign in to comment.