Skip to content

Commit

Permalink
[#57] Fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Jan 6, 2025
1 parent 3d35fa4 commit 1e29728
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
18 changes: 13 additions & 5 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from vng_api_common.validators import (
AlphanumericExcludingDiacritic,
BaseValidator,
BaseIdentificationValidator,
validate_bsn,
)

Expand Down Expand Up @@ -42,12 +42,16 @@ def test_equality_validator_instances():


def test_valid():
validator = BaseValidator("296648875", list_size=[8, 9], check_11proefnumber=True)
validator = BaseIdentificationValidator(
"296648875", list_size=[8, 9], check_11proefnumber=True
)
validator.validate()


def test_invalid_length():
validator = BaseValidator("1234", list_size=[8, 9], check_11proefnumber=True)
validator = BaseIdentificationValidator(
"1234", list_size=[8, 9], check_11proefnumber=True
)

with pytest.raises(ValidationError) as error:
validator.validate()
Expand All @@ -58,15 +62,19 @@ def test_invalid_length():


def test_invalid_isdigit():
validator = BaseValidator("1234TEST", list_size=[8, 9], check_11proefnumber=True)
validator = BaseIdentificationValidator(
"1234TEST", list_size=[8, 9], check_11proefnumber=True
)

with pytest.raises(ValidationError) as error:
validator.validate()
assert "Voer een numerieke waarde in" in str(error.value)


def test_invalid_11proefnumber():
validator = BaseValidator("123456789", list_size=[8, 9], check_11proefnumber=True)
validator = BaseIdentificationValidator(
"123456789", list_size=[8, 9], check_11proefnumber=True
)
with pytest.raises(ValidationError) as error:
validator.validate()
assert "Ongeldige code" in str(error.value)
Expand Down
18 changes: 10 additions & 8 deletions vng_api_common/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
WORD_REGEX = re.compile(r"[\w\-]+$", re.ASCII)


class BaseValidator:
class BaseIdentificationValidator:
"""
Validator base class that performs common validation logic.
Digit check, length, and optional 11-proof check.
Expand Down Expand Up @@ -68,9 +68,7 @@ def validate_11proefnumber(self) -> None:
total += multiplier * int(char)

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

def validate(self) -> None:
self.validate_isdigit()
Expand All @@ -79,27 +77,31 @@ def validate(self) -> None:
self.validate_11proefnumber()


def validate_rsin(value):
def validate_rsin(value: str) -> None:
"""
Validates that a string value is a valid RSIN number by applying the
'11-proef' checking.
:param value: String object representing a presumably good RSIN number.
"""

validator = BaseValidator(value, list_size=RSIN_LIST_SIZE, check_11proefnumber=True)
validator = BaseIdentificationValidator(
value, list_size=RSIN_LIST_SIZE, check_11proefnumber=True
)
validator.error_messages["11proefnumber"] = _("Onjuist RSIN nummer")
validator.validate()


def validate_bsn(value):
def validate_bsn(value: str) -> None:
"""
Validates that a string value is a valid BSN number by applying the
'11-proef' checking.
:param value: String object representing a presumably good BSN number.
"""
validator = BaseValidator(value, list_size=BSN_LIST_SIZE, check_11proefnumber=True)
validator = BaseIdentificationValidator(
value, list_size=BSN_LIST_SIZE, check_11proefnumber=True
)
validator.error_messages["11proefnumber"] = _("Onjuist BSN nummer")
validator.validate()

Expand Down

0 comments on commit 1e29728

Please sign in to comment.