From d243b909d314dbd29448cd93fd4b28c4eac5fc06 Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Mon, 23 Dec 2024 13:34:16 +0100 Subject: [PATCH] [#233] Fix tests --- .../api/tests/test_partijen.py | 2 +- .../klantinteracties/models/validators.py | 8 +- .../klantinteracties/tests/test_validators.py | 81 ++++++++----------- 3 files changed, 39 insertions(+), 52 deletions(-) diff --git a/src/openklant/components/klantinteracties/api/tests/test_partijen.py b/src/openklant/components/klantinteracties/api/tests/test_partijen.py index ad187b65..2e71174c 100644 --- a/src/openklant/components/klantinteracties/api/tests/test_partijen.py +++ b/src/openklant/components/klantinteracties/api/tests/test_partijen.py @@ -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( diff --git a/src/openklant/components/klantinteracties/models/validators.py b/src/openklant/components/klantinteracties/models/validators.py index 8467e5dd..dd928974 100644 --- a/src/openklant/components/klantinteracties/models/validators.py +++ b/src/openklant/components/klantinteracties/models/validators.py @@ -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." @@ -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." @@ -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) ) } diff --git a/src/openklant/components/klantinteracties/tests/test_validators.py b/src/openklant/components/klantinteracties/tests/test_validators.py index e3cf397e..050bbbe1 100644 --- a/src/openklant/components/klantinteracties/tests/test_validators.py +++ b/src/openklant/components/klantinteracties/tests/test_validators.py @@ -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 @@ -123,16 +120,6 @@ 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, @@ -140,18 +127,24 @@ def test_code_soort_object_id_not_found_in_code_objecttype(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_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 @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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")