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 15a1ca2 commit d243b90
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ def test_invalid_validation_partij_identificator_object_id(self):
self.assertEqual(response.data["title"], "Invalid input.")
self.assertEqual(
response.data["invalid_params"][0]["name"],
"partijIdentificator.objectId",
"partijIdentificator.ObjectId",
)
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid")
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def validate_code_objecttype(self) -> None:
return

if self.code_objecttype not in self.REGISTERS.get(self.code_register, {}):
raise serializers.ValidationError(
raise ValidationError(
{
"partijIdentificator.codeObjecttype": _(
"codeObjecttype keuzes zijn beperkt op basis van codeRegister."
Expand All @@ -136,7 +136,7 @@ def validate_code_soort_object_id(self) -> None:
self.code_soort_object_id in d.get(self.code_objecttype, [])
for d in self.REGISTERS.values()
):
raise serializers.ValidationError(
raise ValidationError(
{
"partijIdentificator.codeSoortObjectId": _(
"codeSoortObjectId keuzes zijn beperkt op basis van codeObjecttype."
Expand All @@ -158,9 +158,9 @@ def validate_object_id(self) -> None:
try:
getattr(self, f"_validate_{self.code_soort_object_id}")()
except ValidationError as error:
raise serializers.ValidationError(
raise ValidationError(
{
"partijIdentificator.objectId": _(
"partijIdentificator.ObjectId": _(
"ObjectId ongeldig, reden: %s" % (error.message)
)
}
Expand Down
81 changes: 34 additions & 47 deletions src/openklant/components/klantinteracties/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,15 @@ def test_code_objecttype_not_found_in_code_register(self):
"object_id": "296648875",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_code_objecttype()

details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.codeObjecttype"]["message"],
details["partijIdentificator.codeObjecttype"][0],
"codeObjecttype keuzes zijn beperkt op basis van codeRegister.",
)
self.assertEqual(
details["partijIdentificator.codeObjecttype"]["code"], "invalid"
)

# Start section validate_code_soort_object_id

Expand All @@ -123,35 +120,31 @@ def test_empty_code_objecttype_ok_code_soort_object_id(self):
validator = PartijIdentificatorValidator(**data)
validator.validate_code_soort_object_id()

def test_oveirige_code_objecttype_ok_code_soort_object_id(self):
data = {
"code_objecttype": PartijIdentificatorCodeObjectType.overige.value,
"code_soort_object_id": PartijIdentificatorCodeSoortObjectId.bsn.value,
"object_id": "296648875",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
validator = PartijIdentificatorValidator(**data)
validator.validate_code_soort_object_id()

def test_code_soort_object_id_not_found_in_code_objecttype(self):
data = {
"code_objecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon.value,
"code_soort_object_id": PartijIdentificatorCodeSoortObjectId.rsin.value,
"object_id": "296648875",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_code_soort_object_id()

details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.codeSoortObjectId"]["message"],
details["partijIdentificator.codeSoortObjectId"][0],
"codeSoortObjectId keuzes zijn beperkt op basis van codeObjecttype.",
)
self.assertEqual(
details["partijIdentificator.codeSoortObjectId"]["code"], "invalid"
)

def test_oveirige_code_objecttype_ok_code_soort_object_id(self):
data = {
"code_objecttype": PartijIdentificatorCodeObjectType.overige.value,
"code_soort_object_id": PartijIdentificatorCodeSoortObjectId.bsn.value,
"object_id": "296648875",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
validator = PartijIdentificatorValidator(**data)
validator.validate_code_soort_object_id()

# Start section validate_object_id

Expand Down Expand Up @@ -232,15 +225,14 @@ def test_object_id_invalid_len_bsn(self):
"object_id": "123",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
details["partijIdentificator.ObjectId"][0],
"ObjectId ongeldig, reden: The length must be in: [8, 9]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

def test_object_id_invalid_digit_bsn(self):
data = {
Expand All @@ -249,15 +241,14 @@ def test_object_id_invalid_digit_bsn(self):
"object_id": "123TEST123",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
details["partijIdentificator.ObjectId"][0],
"ObjectId ongeldig, reden: Expected a numerical value",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

def test_object_id_invalid_proef11_bsn(self):
data = {
Expand All @@ -266,15 +257,14 @@ def test_object_id_invalid_proef11_bsn(self):
"object_id": "123456789",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
details["partijIdentificator.ObjectId"][0],
"ObjectId ongeldig, reden: Invalid code",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

def test_object_id_invalid_vestigingsnummer(self):
data = {
Expand All @@ -283,15 +273,14 @@ def test_object_id_invalid_vestigingsnummer(self):
"object_id": "1234",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
details["partijIdentificator.ObjectId"][0],
"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 @@ -300,15 +289,14 @@ def test_object_id_invalid_rsin(self):
"object_id": "1234",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
details["partijIdentificator.ObjectId"][0],
"ObjectId ongeldig, reden: The length must be in: [8, 9]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

def test_object_id_invalid_kvknummer(self):
data = {
Expand All @@ -317,12 +305,11 @@ def test_object_id_invalid_kvknummer(self):
"object_id": "1234",
"code_register": PartijIdentificatorCodeRegister.brp.value,
}
with self.assertRaises(serializers.ValidationError) as error:
with self.assertRaises(ValidationError) as error:
validator = PartijIdentificatorValidator(**data)
validator.validate_object_id()
details = error.exception.get_full_details()
details = error.exception.message_dict
self.assertEqual(
details["partijIdentificator.objectId"]["message"],
details["partijIdentificator.ObjectId"][0],
"ObjectId ongeldig, reden: The length must be in: [8]",
)
self.assertEqual(details["partijIdentificator.objectId"]["code"], "invalid")

0 comments on commit d243b90

Please sign in to comment.