Skip to content

Commit

Permalink
[#233] Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 23, 2024
1 parent 7fe7f77 commit 181409c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def validate_object_id(self) -> None:
try:
getattr(self, f"_validate_{self.code_soort_object_id}")()
except ValidationError as error:
serializers.ValidationError(
raise serializers.ValidationError(
{
"partijIdentificator.objectId": _(
"ObjectId ongeldig, reden: %s" % (error.message)
Expand Down
47 changes: 39 additions & 8 deletions src/openklant/components/klantinteracties/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,34 @@
)
from openklant.components.klantinteracties.models.validators import (
PartijIdentificatorValidator,
ObjectIdValidator,
)


class ObjectIdValidatorTests(TestCase):
def test_valid(self):
validator = ObjectIdValidator("296648875", [8, 9], True)
validator.validate()

def test_invalid_length(self):
validator = ObjectIdValidator("1234", [8, 9], True)
with self.assertRaises(ValidationError) as error:
validator.validate()
self.assertTrue("The length must be in: [8, 9]" in str(error.exception))

def test_invalid_isdigit(self):
validator = ObjectIdValidator("1234TEST", [8, 9], True)
with self.assertRaises(ValidationError) as error:
validator.validate()
self.assertTrue("Expected a numerical value" in str(error.exception))

def test_invalid_11proefnumber(self):
validator = ObjectIdValidator("123456789", [8, 9], True)
with self.assertRaises(ValidationError) as error:
validator.validate()
self.assertTrue("Invalid code" in str(error.exception))


class PartijIdentificatorValidatorTests(TestCase):
def test_valid(self):
data = {
Expand Down Expand Up @@ -212,7 +237,7 @@ def test_object_id_invalid_len_bsn(self):
details = error.exception.get_full_details()
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
"Ongeldig BSN.",
"ObjectId ongeldig, reden: The length must be in: [8, 9]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

Expand All @@ -229,7 +254,7 @@ def test_object_id_invalid_digit_bsn(self):
details = error.exception.get_full_details()
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
"Ongeldig BSN.",
"ObjectId ongeldig, reden: Expected a numerical value",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

Expand All @@ -246,7 +271,7 @@ def test_object_id_invalid_proef11_bsn(self):
details = error.exception.get_full_details()
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
"Ongeldig BSN.",
"ObjectId ongeldig, reden: Invalid code",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

Expand All @@ -261,8 +286,11 @@ def test_object_id_invalid_vestigingsnummer(self):
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
self.assertEqual(details[0]["message"], "Ongeldige veldlengte")
self.assertEqual(details[0]["code"], "invalid")
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
"ObjectId ongeldig, reden: The length must be in: [12]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

def test_object_id_invalid_rsin(self):
data = {
Expand All @@ -277,7 +305,7 @@ def test_object_id_invalid_rsin(self):
details = error.exception.get_full_details()
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
"Ongeldig RSIN.",
"ObjectId ongeldig, reden: The length must be in: [8, 9]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

Expand All @@ -292,5 +320,8 @@ def test_object_id_invalid_kvknummer(self):
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
self.assertEqual(details[0]["message"], "Ongeldige veldlengte")
self.assertEqual(details[0]["code"], "invalid")
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
"ObjectId ongeldig, reden: The length must be in: [8]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

0 comments on commit 181409c

Please sign in to comment.