From f31553757805f2c5f2b94b70fb893ed2c7ffb37d Mon Sep 17 00:00:00 2001 From: manoj-02 Date: Thu, 3 Aug 2023 15:36:52 +0530 Subject: [PATCH 1/2] G2P-192 Added error handling in ID type. --- g2p_registry_rest_api/models/group.py | 2 +- g2p_registry_rest_api/models/registrant.py | 2 +- .../services/process_individual_mixin.py | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/g2p_registry_rest_api/models/group.py b/g2p_registry_rest_api/models/group.py index 9bd4c58d..5e06e4d8 100644 --- a/g2p_registry_rest_api/models/group.py +++ b/g2p_registry_rest_api/models/group.py @@ -34,7 +34,7 @@ def validate_kind_no_spaces(cls, value): # noqa: B902 value = value.lstrip() if value else value # Checking if the length of the cleaned value is less than 1 - if len(value) < 1: + if value and len(value) < 1: raise G2PApiValidationError( error_message=G2PErrorCodes.G2P_REQ_001.get_error_message(), error_code=G2PErrorCodes.G2P_REQ_001.get_error_code(), diff --git a/g2p_registry_rest_api/models/registrant.py b/g2p_registry_rest_api/models/registrant.py index 93e949e9..09050627 100644 --- a/g2p_registry_rest_api/models/registrant.py +++ b/g2p_registry_rest_api/models/registrant.py @@ -55,7 +55,7 @@ def validate_id_type_no_spaces(cls, value): # noqa: B902 value = value.lstrip() if value else value # Checking if the length of the cleaned value is less than 1 - if len(value) < 1: + if value and len(value) < 1: raise G2PApiValidationError( error_message=G2PErrorCodes.G2P_REQ_005.get_error_message(), error_code=G2PErrorCodes.G2P_REQ_005.get_error_code(), diff --git a/g2p_registry_rest_api/services/process_individual_mixin.py b/g2p_registry_rest_api/services/process_individual_mixin.py index d9fdeb30..964124a1 100644 --- a/g2p_registry_rest_api/services/process_individual_mixin.py +++ b/g2p_registry_rest_api/services/process_individual_mixin.py @@ -1,5 +1,6 @@ from odoo.addons.component.core import AbstractComponent - +from ..exceptions.base_exception import G2PApiValidationError +from ..exceptions.error_codes import G2PErrorCodes class ProcessIndividualMixin(AbstractComponent): _name = "process_individual.rest.mixin" @@ -60,6 +61,14 @@ def _process_ids(self, ids_info): }, ) ) + + elif rec.id_type: + raise G2PApiValidationError( + error_message=G2PErrorCodes.G2P_REQ_005.get_error_message(), + error_code=G2PErrorCodes.G2P_REQ_005.get_error_code(), + error_description="ID type is not present in the database.", + ) + return ids def _process_phones(self, ids_info): From a5a1e3e77235ee4f814d05b192739f247cbd0c65 Mon Sep 17 00:00:00 2001 From: manoj-02 Date: Thu, 3 Aug 2023 16:53:27 +0530 Subject: [PATCH 2/2] Added ID name in error handling. --- g2p_registry_rest_api/models/group.py | 4 ++-- g2p_registry_rest_api/models/registrant.py | 4 ++-- .../services/process_individual_mixin.py | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/g2p_registry_rest_api/models/group.py b/g2p_registry_rest_api/models/group.py index 5e06e4d8..db783d6b 100644 --- a/g2p_registry_rest_api/models/group.py +++ b/g2p_registry_rest_api/models/group.py @@ -31,10 +31,10 @@ class GroupInfoIn(RegistrantInfoIn): @validator("kind") def validate_kind_no_spaces(cls, value): # noqa: B902 # Using lstrip() to remove leading spaces from the value - value = value.lstrip() if value else value + new_val = value.lstrip() if value else value # Checking if the length of the cleaned value is less than 1 - if value and len(value) < 1: + if value and len(new_val) < 1: raise G2PApiValidationError( error_message=G2PErrorCodes.G2P_REQ_001.get_error_message(), error_code=G2PErrorCodes.G2P_REQ_001.get_error_code(), diff --git a/g2p_registry_rest_api/models/registrant.py b/g2p_registry_rest_api/models/registrant.py index 09050627..ec6f1628 100644 --- a/g2p_registry_rest_api/models/registrant.py +++ b/g2p_registry_rest_api/models/registrant.py @@ -52,10 +52,10 @@ class RegistrantIDIn(NaiveOrmModel): @validator("id_type") def validate_id_type_no_spaces(cls, value): # noqa: B902 # Using lstrip() to remove leading spaces from the value - value = value.lstrip() if value else value + new_val = value.lstrip() if value else value # Checking if the length of the cleaned value is less than 1 - if value and len(value) < 1: + if value and len(new_val) < 1: raise G2PApiValidationError( error_message=G2PErrorCodes.G2P_REQ_005.get_error_message(), error_code=G2PErrorCodes.G2P_REQ_005.get_error_code(), diff --git a/g2p_registry_rest_api/services/process_individual_mixin.py b/g2p_registry_rest_api/services/process_individual_mixin.py index 964124a1..75eae455 100644 --- a/g2p_registry_rest_api/services/process_individual_mixin.py +++ b/g2p_registry_rest_api/services/process_individual_mixin.py @@ -1,7 +1,9 @@ from odoo.addons.component.core import AbstractComponent + from ..exceptions.base_exception import G2PApiValidationError from ..exceptions.error_codes import G2PErrorCodes + class ProcessIndividualMixin(AbstractComponent): _name = "process_individual.rest.mixin" _description = """ @@ -61,12 +63,15 @@ def _process_ids(self, ids_info): }, ) ) - + elif rec.id_type: raise G2PApiValidationError( error_message=G2PErrorCodes.G2P_REQ_005.get_error_message(), error_code=G2PErrorCodes.G2P_REQ_005.get_error_code(), - error_description="ID type is not present in the database.", + error_description=( + ("ID type - %s is not present in the database.") + % rec.id_type + ), ) return ids