diff --git a/tests/test_cross_validate.py b/tests/test_cross_validate.py new file mode 100644 index 0000000..9457c6e --- /dev/null +++ b/tests/test_cross_validate.py @@ -0,0 +1,19 @@ +from validation import FromAccount + + +account_data = FromAccount( + account_name="Astrid Janneke Willems", + account_holder_name="Astrid Janneke", + account_holder_surname="Willems", + passport_number="HW8642009", + reference_currency="EUR", + other_currency=None, + building_number="18", + street_name="Lijnbaan", + postal_code="7523 05", + city="Assen", + country="Netherlands", + name="Astrid Janneke Willems", + phone_number="+31 06 34579996", + email="astrid.willems@upcmail.nl" +) \ No newline at end of file diff --git a/validation/cross_validate.py b/validation/cross_validate.py index c07ce14..928c460 100644 --- a/validation/cross_validate.py +++ b/validation/cross_validate.py @@ -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 \ No newline at end of file + failure = validator(data) + if not failure is None: + validation_failures.append(failure) + return validation_failures