Impl cross_validate in progress
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
from enum import StrEnum
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Callable, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from validation import FromAccount, FromDescription, FromPassport, FromProfile
|
||||
|
||||
|
||||
|
||||
class ValidatedData(BaseModel):
|
||||
class ExtractedData(BaseModel):
|
||||
account: FromAccount
|
||||
description: FromDescription
|
||||
passport: FromPassport
|
||||
profile: FromProfile
|
||||
|
||||
|
||||
class DocType(StrEnum):
|
||||
account = "account"
|
||||
description = "description"
|
||||
@ -19,7 +19,7 @@ class DocType(StrEnum):
|
||||
profile = "profile"
|
||||
|
||||
|
||||
class ValidationFailure(BaseModel):
|
||||
class XValFailure(BaseModel):
|
||||
doc1_type: DocType
|
||||
doc1_val: str
|
||||
|
||||
@ -27,19 +27,34 @@ class ValidationFailure(BaseModel):
|
||||
doc2_val: str
|
||||
|
||||
|
||||
|
||||
def xref_client_name(data: ValidatedData) -> ValidationFailure:
|
||||
def xval_name_account_description(data: ExtractedData) -> Optional[XValFailure]:
|
||||
if data.account.account_holder_name != data.description.full_name:
|
||||
return ValidationFailure(
|
||||
doc1_type=DocType.account, doc1_val=f"{data.account.account_holder_name=}",
|
||||
doc2_type=DocType.description, doc2_val=f"{data.description.full_name=}"
|
||||
return XValFailure(
|
||||
doc1_type=DocType.account,
|
||||
doc1_val=f"{data.account.account_holder_name=}",
|
||||
doc2_type=DocType.description,
|
||||
doc2_val=f"{data.description.full_name=}",
|
||||
)
|
||||
# TODO CONTINUE
|
||||
|
||||
def xref_all(data: ValidatedData) -> list[ValidationFailure]:
|
||||
xref_validators: list[Callable[[ValidatedData], ValidationFailure]] = [xref_client_name]
|
||||
|
||||
def xval_email_account_profile(data: ExtractedData) -> Optional[XValFailure]:
|
||||
if data.account.email != data.profile.email:
|
||||
return XValFailure(
|
||||
doc1_type=DocType.account,
|
||||
doc1_val=f"{data.account.email=}",
|
||||
doc2_type=DocType.profile,
|
||||
doc2_val=f"{data.profile.email=}"
|
||||
)
|
||||
|
||||
|
||||
def xref_all(data: ExtractedData) -> list[XValFailure]:
|
||||
xref_validators: list[Callable[[ExtractedData], Optional[XValFailure]]] = [
|
||||
xval_name_account_description
|
||||
]
|
||||
|
||||
validation_failures = []
|
||||
for validator in xref_validators:
|
||||
validation_failures.append(validator(data))
|
||||
return validation_failures
|
||||
failure = validator(data)
|
||||
if not failure is None:
|
||||
validation_failures.append(failure)
|
||||
return validation_failures
|
||||
|
Reference in New Issue
Block a user