Skip to content

Commit

Permalink
[#233] Check validations
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 19, 2024
1 parent 703ea4e commit faa988d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ def test_invalid_validation_partij_identificator_code_objecttype(self):
}

# ValidationError, "ObjectType keuzes zijn beperkt op basis van CodeRegister."
with self.assertRaises(ValidationError):
with self.assertRaises(ValidationError) as error:
self.client.post(url, data)

def test_invalid_validation_partij_identificator_code_soort_object_id(self):
Expand All @@ -2135,7 +2135,7 @@ def test_invalid_validation_partij_identificator_code_soort_object_id(self):
},
}
# "CodeSoortObjectId keuzes zijn beperkt op basis van CodeObjectType.",
with self.assertRaises(ValidationError):
with self.assertRaises(ValidationError) as error:
self.client.post(url, data)

def test_invalid_validation_partij_identificator_object_id(self):
Expand All @@ -2152,7 +2152,7 @@ def test_invalid_validation_partij_identificator_object_id(self):
},
}
# "De lengte van de ObjectId moet tussen 8 en 9 liggen."
with self.assertRaises(ValidationError):
with self.assertRaises(ValidationError) as error:
self.client.post(url, data)

def test_valid_validation_partij_identificator(self):
Expand Down
29 changes: 22 additions & 7 deletions src/openklant/components/klantinteracties/models/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def validate_code_object_type(self) -> None:
return

if self.code_object_type not in self.REGISTERS.get(self.code_register, {}):
raise ValidationError("ERRORE")
raise ValidationError(
_("ObjectType keuzes zijn beperkt op basis van CodeRegister.")
)

def validate_code_soort_object_id(self) -> None:
"""Validates the CodeSoortObjectId based on register and CodeObjectType"""
Expand All @@ -73,7 +75,9 @@ def validate_code_soort_object_id(self) -> None:
self.code_soort_object_id in d.get(self.code_object_type, [])
for d in self.REGISTERS.values()
):
raise ValidationError("ERRORE")
raise ValidationError(
_("CodeSoortObjectId keuzes zijn beperkt op basis van CodeObjectType.")
)

def validate_object_id(self) -> None:
"""Validates the object ID based on the SoortObjectId"""
Expand All @@ -91,24 +95,35 @@ def validate_object_id(self) -> None:
if validator:
validator()
else:
raise ValidationError("ERRORE")
raise ValidationError(
code="object_id",
message=(_("Ongeldige Partij Identificator CodeSoortObjectId.")),
)

def _validate_bsn(self) -> None:
"""Validates the BSN Object ID length"""
if len(self.object_id) not in [8, 9]:
raise ValidationError("ERRORE")
raise ValidationError(
{"object_id": "De lengte van de ObjectId moet tussen 8 en 9 liggen."}
)

def _validate_vestigingsnummer(self) -> None:
"""Validates the VestigingsNummer Object ID length"""
if len(self.object_id) not in [12]:
raise ValidationError("ERRORE")
raise ValidationError(
{"object_id": _("De lengte van de ObjectId moet 12 tekens zijn.")}
)

def _validate_rsin(self) -> None:
"""Validates the Rsin Object ID length"""
if len(self.object_id) not in [8, 9]:
raise ValidationError("ERRORE")
raise ValidationError(
{"object_id": _("De lengte van de ObjectId moet tussen 8 en 9 liggen.")}
)

def _validate_kvknummer(self) -> None:
"""Validates the KvkNummer Object ID length"""
if len(self.object_id) not in [8]:
raise ValidationError("ERRORE")
raise ValidationError(
{"object_id": _("De lengte van de ObjectId moet 8 tekens zijn.")}
)

0 comments on commit faa988d

Please sign in to comment.