-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validators for cdd,ead, and error pipeline (#177)
* feat: add pydantic dataclassed for cdd ^ ead This is for CddRequest and EadRequest feat: add native address fields * feat: add validation for cdd and ead fix: audit model change validation error fix EncodeError(TypeError('Object of type ValidationError is not JSON serializable') Removed some extra not necessary in logs. * feat: rebase compatibility * feat: add validate cdd and ead pipes Also added error_validation_pipeline * feat: add error_validation_task test =) * fix: add validation step to rti backends * fix: pipeline starts with wrong pipeline_index this removes the keys ["pipeline_index", "launch_validation_error_pipeline"] to dont finish the next pipeline error_validation_task. * feat: keep validation_exception in error_pipeline * chore: fix docstring * chore: improve method name * refactor: error handling with pearson exceptions * feat: pr recommend remove unuseful block code * refactor: send exception_data in kwarg * refactor: change the error raised * feat: audit with name action variable * feat: add skip pipe if not exception_data * fix: assertNoLogs is only available py3.10+ * feat: raise same exception based on exception_data * refactor: hidden_kwargs 2 rm sensitive keys audit * refactor: manage exception with dict representation refactor: init exception also from exception_dict chore: pylint changes * chore: update eox_nelp/pearson_vue/pipeline.py Co-authored-by: Andrey Cañon <[email protected]> * chore: remove unnused utils * feat: pr recommendation init exc improvemente * feat: add test for exception file * chore: docstrings improvements
- Loading branch information
Showing
9 changed files
with
860 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
Module to add data_classes related Pearson Vue Integration | ||
""" | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class Phone(BaseModel): | ||
"""Phone data class model""" | ||
phone_number: str = Field(alias="phoneNumber", min_length=1, max_length=20) | ||
phone_country_code: str = Field(alias="phoneCountryCode", min_length=1, max_length=3) | ||
|
||
|
||
class Mobile(BaseModel): | ||
"""Mobile data class model""" | ||
mobile_number: str = Field(alias="mobileNumber", min_length=1, max_length=20) | ||
mobile_country_code: str = Field(alias="mobileCountryCode", min_length=1, max_length=3) | ||
|
||
|
||
class NativeAddress(BaseModel): | ||
"""NativeAddress data class model""" | ||
language: str = Field(alias="language", min_length=3, max_length=3) | ||
potential_mismatch: str = Field(alias="potentialMismatch", min_length=1) | ||
first_name: str = Field(alias="firstName", min_length=1, max_length=30) | ||
last_name: str = Field(alias="lastName", min_length=1, max_length=50) | ||
address1: str = Field(alias="address1", min_length=1, max_length=40) | ||
city: str = Field(alias="city", min_length=1, max_length=32) | ||
|
||
|
||
class Address(BaseModel): | ||
"""Address data class model""" | ||
address1: str = Field(alias="address1", min_length=1, max_length=40) | ||
city: str = Field(alias="city", min_length=1, max_length=32) | ||
country: str = Field(alias="country", min_length=1, max_length=3) | ||
phone: Phone = Field(alias="phone") | ||
mobile: Mobile = Field(alias="mobile") | ||
native_address: NativeAddress = Field(alias="nativeAddress") | ||
|
||
|
||
class PrimaryAddress(Address): | ||
"""PrimaryAddress data class model""" | ||
|
||
|
||
class AlternateAddress(Address): | ||
"""AlternateAddress data class model""" | ||
|
||
|
||
class CandidateName(BaseModel): | ||
"""CandidateName data class model""" | ||
first_name: str = Field(alias="firstName", min_length=1, max_length=30) | ||
last_name: str = Field(alias="lastName", min_length=1, max_length=50) | ||
|
||
|
||
class WebAccountInfo(BaseModel): | ||
"""WebAccountInfo data class model""" | ||
email: str = Field(alias="email", min_length=1, max_length=255) | ||
|
||
|
||
class CddRequest(BaseModel): | ||
"""CddRequest data class model""" | ||
client_candidate_id: str = Field(alias="@clientCandidateID", min_length=1, max_length=50) | ||
client_id: str = Field(alias="@clientID", min_length=1) | ||
candidate_name: CandidateName = Field(alias="candidateName") | ||
last_update: str = Field(alias="lastUpdate", min_length=1) | ||
primary_address: PrimaryAddress = Field(alias="primaryAddress") | ||
web_account_info: WebAccountInfo = Field(alias="webAccountInfo") | ||
|
||
|
||
class EadRequest(BaseModel): | ||
"""EadRequest data class model""" | ||
client_id: str = Field(alias="@clientID", min_length=1) | ||
authorization_transaction_type: str = Field(alias="@authorizationTransactionType", min_length=1) | ||
client_authorization_id: str = Field(alias="@clientAuthorizationID", min_length=1, max_length=25) | ||
client_candidate_id: str = Field(alias="clientCandidateID", min_length=1, max_length=50) | ||
exam_authorization_count: int = Field(alias="examAuthorizationCount") | ||
exam_series_code: str = Field(alias="examSeriesCode", min_length=1, max_length=20) | ||
elegibility_appt_date_first: str = Field(alias="eligibilityApptDateFirst", min_length=1) | ||
elegibility_appt_date_last: str = Field(alias="eligibilityApptDateLast", min_length=1) | ||
last_update: str = Field(alias="lastUpdate", min_length=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" | ||
Module to add managed exceptions related Pearson Vue Integration | ||
""" | ||
import inspect | ||
|
||
|
||
class PearsonBaseError(Exception): | ||
"""Pearson Base error class | ||
Most classes that inherit from this class must have exception_type. | ||
This class could have a dict representation with the following shape: | ||
exception_dict = { | ||
'exception_type': 'validation-error', | ||
'pipe_args_dict': { | ||
"cdd_request": {} | ||
}, | ||
'pipe_function': 'validate_cdd_request', | ||
'exception_reason': "error: ['String to short.']" | ||
} | ||
""" | ||
exception_type = "base-error" | ||
|
||
def __init__( | ||
self, | ||
exception_reason, | ||
*args, | ||
pipe_frame=None, | ||
pipe_args_dict=None, | ||
pipe_function=None, | ||
**kwargs | ||
): # pylint: disable=unused-argument | ||
"""Init pearson exception.Is mandatory the exception_reasons. | ||
You could init using pipe_frame. | ||
Or init using exception_dict representation, | ||
so you could init the class with PearsonBaseError(**exception_dict) | ||
""" | ||
|
||
self.exception_type = self.exception_type | ||
self.exception_reason = exception_reason | ||
|
||
if pipe_frame: | ||
arg_info = inspect.getargvalues(pipe_frame) | ||
self.pipe_args_dict = {arg: arg_info.locals[arg] for arg in arg_info.args} | ||
self.pipe_function = pipe_frame.f_code.co_name | ||
else: | ||
self.pipe_args_dict = pipe_args_dict | ||
self.pipe_function = pipe_function | ||
|
||
super().__init__(self.to_dict(), *args) | ||
|
||
def to_dict(self): | ||
""" | ||
Returns a dictionary representation of the class instance. | ||
Returns: | ||
A dictionary containing the instance's attributes as key-value pairs. | ||
""" | ||
|
||
return {key: value for key, value in self.__dict__.items() if not key.startswith('_')} | ||
|
||
@classmethod | ||
def from_dict(cls, exception_dict: dict): | ||
"""Create an instance of Person or its subclass from a dictionary. | ||
Returns: | ||
Matched instance of pearson exception subclass initialized. | ||
If not matched returns the base class initialized by default. | ||
""" | ||
exception_type = exception_dict.get('exception_type') | ||
for subclass in cls.__subclasses__(): | ||
if subclass.exception_type == exception_type: | ||
return subclass(**exception_dict) | ||
|
||
# Default to Person if no matching subclass is found | ||
return cls(**exception_dict) | ||
|
||
|
||
class PearsonKeyError(PearsonBaseError): | ||
"""Pearson Key error class | ||
""" | ||
exception_type = "key-error" | ||
|
||
|
||
class PearsonAttributeError(PearsonBaseError): | ||
"""Pearson Attribute error class | ||
""" | ||
exception_type = "attribute-error" | ||
|
||
|
||
class PearsonValidationError(PearsonBaseError): | ||
"""Pearson Validation error class | ||
""" | ||
exception_type = "validation-error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.