From bc027ec9f1911f58cecff34665a5e6eddf5ea2f2 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Tue, 15 Oct 2024 17:21:28 +0200 Subject: [PATCH] (PC-32146)[API] refactor: regroup ubble serialization pydantic models --- .../pcapi/connectors/beneficiaries/ubble.py | 17 +- .../serialization/ubble_serializers.py | 165 ++++++- api/src/pcapi/core/fraud/models.py | 4 +- api/src/pcapi/core/fraud/ubble/api.py | 12 +- api/src/pcapi/core/fraud/ubble/models.py | 153 ------- api/src/pcapi/core/subscription/ubble/api.py | 10 +- api/src/pcapi/core/users/factories.py | 4 +- api/src/pcapi/routes/internal/e2e_ubble.py | 6 +- api/src/pcapi/validation/routes/ubble.py | 5 +- .../beneficiaries/ubble_fixtures.py | 28 +- api/tests/core/fraud/test_api.py | 4 +- api/tests/core/subscription/test_factories.py | 72 +-- .../end_to_end/test_subscription_via_ubble.py | 2 +- api/tests/core/subscription/ubble/test_api.py | 16 +- .../routes/external/user_subscription_test.py | 426 +++++++++--------- api/tests/routes/native/v1/account_test.py | 16 +- .../routes/native/v1/subscription_test.py | 38 +- 17 files changed, 489 insertions(+), 489 deletions(-) delete mode 100644 api/src/pcapi/core/fraud/ubble/models.py diff --git a/api/src/pcapi/connectors/beneficiaries/ubble.py b/api/src/pcapi/connectors/beneficiaries/ubble.py index 695cb6fd842..b38472d80c3 100644 --- a/api/src/pcapi/connectors/beneficiaries/ubble.py +++ b/api/src/pcapi/connectors/beneficiaries/ubble.py @@ -11,7 +11,6 @@ from pcapi.connectors.serialization import ubble_serializers from pcapi.core import logging as core_logging from pcapi.core.fraud import models as fraud_models -from pcapi.core.fraud.ubble import models as ubble_fraud_models from pcapi.core.users import models as users_models from pcapi.models.feature import FeatureToggle from pcapi.utils import requests @@ -21,9 +20,9 @@ INCLUDED_MODELS = { - "documents": ubble_fraud_models.UbbleIdentificationDocuments, - "document-checks": ubble_fraud_models.UbbleIdentificationDocumentChecks, - "reference-data-checks": ubble_fraud_models.UbbleIdentificationReferenceDataChecks, + "documents": ubble_serializers.UbbleIdentificationDocuments, + "document-checks": ubble_serializers.UbbleIdentificationDocumentChecks, + "reference-data-checks": ubble_serializers.UbbleIdentificationReferenceDataChecks, } @@ -173,7 +172,7 @@ def start_identification( # pylint: disable=too-many-positional-arguments ) response.raise_for_status() - ubble_identification = parse_obj_as(ubble_serializers.UbbleIdentificationResponse, response.json()) + ubble_identification = parse_obj_as(ubble_serializers.UbbleV2IdentificationResponse, response.json()) ubble_content = ubble_serializers.convert_identification_to_ubble_content(ubble_identification) logger.info( @@ -374,7 +373,7 @@ def build_url(path: str, id_: int | str | None = None) -> str: return base_url + path -def _get_included_attributes(response: dict, type_: str) -> ubble_fraud_models.UbbleIdentificationObject | None: +def _get_included_attributes(response: dict, type_: str) -> ubble_serializers.UbbleIdentificationObject | None: filtered = [incl for incl in response["included"] if incl["type"] == type_] if not filtered: return None @@ -419,13 +418,13 @@ def _extract_useful_content_from_response( response: dict, ) -> fraud_models.UbbleContent: documents = typing.cast( - ubble_fraud_models.UbbleIdentificationDocuments, _get_included_attributes(response, "documents") + ubble_serializers.UbbleIdentificationDocuments, _get_included_attributes(response, "documents") ) document_checks = typing.cast( - ubble_fraud_models.UbbleIdentificationDocumentChecks, _get_included_attributes(response, "document-checks") + ubble_serializers.UbbleIdentificationDocumentChecks, _get_included_attributes(response, "document-checks") ) reference_data_checks = typing.cast( - ubble_fraud_models.UbbleIdentificationReferenceDataChecks, + ubble_serializers.UbbleIdentificationReferenceDataChecks, _get_included_attributes(response, "reference-data-checks"), ) diff --git a/api/src/pcapi/connectors/serialization/ubble_serializers.py b/api/src/pcapi/connectors/serialization/ubble_serializers.py index d3ee43b0736..0845177c752 100644 --- a/api/src/pcapi/connectors/serialization/ubble_serializers.py +++ b/api/src/pcapi/connectors/serialization/ubble_serializers.py @@ -1,13 +1,31 @@ import contextlib import datetime +import enum import pydantic.v1 as pydantic_v1 from pcapi.core.fraud import models as fraud_models -from pcapi.core.fraud.ubble import models as ubble_models from pcapi.core.users import models as users_models +class UbbleIdentificationStatus(enum.Enum): + # ubble v2 + PENDING = "pending" + CAPTURE_IN_PROGRESS = "capture_in_progress" + CHECKS_IN_PROGRESS = "checks_in_progress" + APPROVED = "approved" + DECLINED = "declined" + RETRY_REQUIRED = "retry_required" + REFUSED = "refused" + # ubble v1 + UNINITIATED = "uninitiated" # Identification has only been created (user has not started the verification flow) + INITIATED = "initiated" # User has started the verification flow + PROCESSING = "processing" # User has ended the verification flow, identification-url is not usable anymore + PROCESSED = "processed" # Identification is completely processed by Ubble + ABORTED = "aborted" # User has left the identification, the identification-url is no longer usable (this status is in beta test) + EXPIRED = "expired" # The identification-url has expired and is no longer usable (only uninitiated and initiated identifications can become expired) + + class UbbleDeclaredData(pydantic_v1.BaseModel): name: str birth_date: datetime.date | None @@ -45,13 +63,12 @@ class UbbleResponseCode(pydantic_v1.BaseModel): response_code: int -class UbbleIdentificationResponse(pydantic_v1.BaseModel): +class UbbleV2IdentificationResponse(pydantic_v1.BaseModel): # https://docs.ubble.ai/#tag/Identity-verifications/operation/create_and_start_identity_verification id: str applicant_id: str user_journey_id: str - # TODO clean up imports - status: ubble_models.UbbleIdentificationStatus + status: UbbleIdentificationStatus declared_data: UbbleDeclaredData links: UbbleLinks = pydantic_v1.Field(alias="_links") documents: list[UbbleDocument] @@ -66,7 +83,7 @@ def document(self) -> UbbleDocument | None: return self.documents[0] if self.documents else None @property - def fraud_reason_codes(self) -> list[fraud_models.FraudReasonCode]: + def fraud_reason_codes(self) -> list["fraud_models.FraudReasonCode"]: return [ fraud_models.UBBLE_REASON_CODE_MAPPING.get( response_code.response_code, fraud_models.FraudReasonCode.ID_CHECK_BLOCKED_OTHER @@ -78,7 +95,9 @@ class Config: use_enum_values = True -def convert_identification_to_ubble_content(identification: UbbleIdentificationResponse) -> fraud_models.UbbleContent: +def convert_identification_to_ubble_content( + identification: UbbleV2IdentificationResponse, +) -> "fraud_models.UbbleContent": document = identification.document if not document: first_name, last_name = None, None @@ -110,3 +129,137 @@ def convert_identification_to_ubble_content(identification: UbbleIdentificationR supported=None, ) return content + + +# DEPRECATED Ubble V1 + + +class UbbleScore(enum.Enum): + VALID = 1.0 + INVALID = 0.0 + UNDECIDABLE = -1.0 + + +class UbbleIdentificationObject(pydantic_v1.BaseModel): + # Parent class for any object defined in https://ubbleai.github.io/developer-documentation/#objects-2 + pass + + +class UbbleIdentificationAttributes(UbbleIdentificationObject): + # https://ubbleai.github.io/developer-documentation/#identifications + comment: str | None + created_at: datetime.datetime = pydantic_v1.Field(alias="created-at") + ended_at: datetime.datetime | None = pydantic_v1.Field(None, alias="ended-at") + identification_id: str = pydantic_v1.Field(alias="identification-id") + identification_url: str = pydantic_v1.Field(alias="identification-url") + number_of_attempts: int = pydantic_v1.Field(alias="number-of-attempts") + redirect_url: str = pydantic_v1.Field(alias="redirect-url") + score: float | None + started_at: datetime.datetime | None = pydantic_v1.Field(None, alias="started-at") + status: UbbleIdentificationStatus + status_updated_at: datetime.datetime = pydantic_v1.Field(alias="status-updated-at") + updated_at: datetime.datetime = pydantic_v1.Field(alias="updated-at") + user_agent: str | None = pydantic_v1.Field(None, alias="user-agent") + user_ip_address: str | None = pydantic_v1.Field(None, alias="user-ip-address") + webhook: str + + +class UbbleReasonCode(UbbleIdentificationObject): + type: str = pydantic_v1.Field(alias="type") + id: int = pydantic_v1.Field(alias="id") + + +class UbbleReasonCodes(UbbleIdentificationObject): + data: list[UbbleReasonCode] + + +class UbbleIdentificationRelationships(UbbleIdentificationObject): + reason_codes: UbbleReasonCodes = pydantic_v1.Field(alias="reason-codes") + + +class UbbleIdentificationData(pydantic_v1.BaseModel): + type: str + id: int + attributes: UbbleIdentificationAttributes + relationships: UbbleIdentificationRelationships + + +class UbbleIdentificationDocuments(UbbleIdentificationObject): + # https://ubbleai.github.io/developer-documentation/#documents + birth_date: str | None = pydantic_v1.Field(None, alias="birth-date") + document_number: str | None = pydantic_v1.Field(None, alias="document-number") + document_type: str | None = pydantic_v1.Field(None, alias="document-type") + first_name: str | None = pydantic_v1.Field(None, alias="first-name") + gender: str | None = pydantic_v1.Field(None) + last_name: str | None = pydantic_v1.Field(None, alias="last-name") + married_name: str | None = pydantic_v1.Field(None, alias="married-name") + signed_image_front_url: str | None = pydantic_v1.Field(None, alias="signed-image-front-url") + signed_image_back_url: str | None = pydantic_v1.Field(None, alias="signed-image-back-url") + + +class UbbleIdentificationDocumentChecks(UbbleIdentificationObject): + # https://ubbleai.github.io/developer-documentation/#document-checks + data_extracted_score: float | None = pydantic_v1.Field(None, alias="data-extracted-score") + expiry_date_score: float | None = pydantic_v1.Field(None, alias="expiry-date-score") + issue_date_score: float | None = pydantic_v1.Field(None, alias="issue-date-score") + live_video_capture_score: float | None = pydantic_v1.Field(None, alias="live-video-capture-score") + mrz_validity_score: float | None = pydantic_v1.Field(None, alias="mrz-validity-score") + mrz_viz_score: float | None = pydantic_v1.Field(None, alias="mrz-viz-score") + ove_back_score: float | None = pydantic_v1.Field(None, alias="ove-back-score") + ove_front_score: float | None = pydantic_v1.Field(None, alias="ove-front-score") + ove_score: float | None = pydantic_v1.Field(None, alias="ove-score") + quality_score: float | None = pydantic_v1.Field(None, alias="quality-score") + score: float | None = pydantic_v1.Field(None, alias="score") + supported: float | None = None + visual_back_score: float | None = pydantic_v1.Field(None, alias="visual-back-score") + visual_front_score: float | None = pydantic_v1.Field(None, alias="visual-front-score") + + +class UbbleIdentificationFaceChecks(UbbleIdentificationObject): + # https://ubbleai.github.io/developer-documentation/#face-checks + active_liveness_score: float | None = pydantic_v1.Field(None, alias="active-liveness-score") + live_video_capture_score: float | None = pydantic_v1.Field(None, alias="live-video-capture-score") + quality_score: float | None = pydantic_v1.Field(None, alias="quality-score") + score: float | None = None + + +class UbbleIdentificationReferenceDataChecks(UbbleIdentificationObject): + # https://ubbleai.github.io/developer-documentation/#reference-data-check + score: float | None = None + + +class UbbleIdentificationDocFaceMatches(UbbleIdentificationObject): + # https://ubbleai.github.io/developer-documentation/#doc-face-matches + score: float | None = None + + +class UbbleIdentificationIncluded(pydantic_v1.BaseModel): + type: str + id: int + attributes: UbbleIdentificationObject + relationships: dict | None + + +class UbbleIdentificationIncludedDocuments(UbbleIdentificationIncluded): + attributes: UbbleIdentificationDocuments + + +class UbbleIdentificationIncludedDocumentChecks(UbbleIdentificationIncluded): + attributes: UbbleIdentificationDocumentChecks + + +class UbbleIdentificationIncludedFaceChecks(UbbleIdentificationIncluded): + attributes: UbbleIdentificationFaceChecks + + +class UbbleIdentificationIncludedReferenceDataChecks(UbbleIdentificationIncluded): + attributes: UbbleIdentificationReferenceDataChecks + + +class UbbleIdentificationIncludedDocFaceMatches(UbbleIdentificationIncluded): + attributes: UbbleIdentificationDocFaceMatches + + +class UbbleIdentificationResponse(pydantic_v1.BaseModel): + data: UbbleIdentificationData + included: list[UbbleIdentificationIncluded] diff --git a/api/src/pcapi/core/fraud/models.py b/api/src/pcapi/core/fraud/models.py index 6de18399726..3531a1aefac 100644 --- a/api/src/pcapi/core/fraud/models.py +++ b/api/src/pcapi/core/fraud/models.py @@ -11,6 +11,7 @@ from sqlalchemy.dialects import postgresql import sqlalchemy.orm as sa_orm +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.users import constants as users_constants from pcapi.core.users import models as users_models from pcapi.models import Base @@ -19,7 +20,6 @@ from pcapi.serialization.utils import to_camel from .common import models as common_models -from .ubble import models as ubble_fraud_models if TYPE_CHECKING: @@ -365,7 +365,7 @@ class UbbleContent(common_models.IdentityCheckContent): registration_datetime: datetime.datetime | None processed_datetime: datetime.datetime | None score: float | None - status: ubble_fraud_models.UbbleIdentificationStatus | None + status: ubble_serializers.UbbleIdentificationStatus | None status_updated_at: datetime.datetime | None supported: float | None signed_image_front_url: pydantic_v1.HttpUrl | None diff --git a/api/src/pcapi/core/fraud/ubble/api.py b/api/src/pcapi/core/fraud/ubble/api.py index 87fd45260a2..852052ea9d6 100644 --- a/api/src/pcapi/core/fraud/ubble/api.py +++ b/api/src/pcapi/core/fraud/ubble/api.py @@ -2,9 +2,9 @@ import re from pcapi import settings +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.fraud import api as fraud_api from pcapi.core.fraud import models as fraud_models -from pcapi.core.fraud.ubble import models as ubble_fraud_models from pcapi.core.subscription import api as subscription_api from pcapi.core.subscription.ubble import models as ubble_subsciption_models from pcapi.core.users import constants as users_constants @@ -22,7 +22,7 @@ def on_ubble_result(fraud_check: fraud_models.BeneficiaryFraudCheck) -> None: def _ubble_readable_score(score: float | None) -> str: - return ubble_fraud_models.UbbleScore(score).name if score is not None else "AUCUN" + return ubble_serializers.UbbleScore(score).name if score is not None else "AUCUN" def _ubble_message_from_code(code: fraud_models.FraudReasonCode) -> str: @@ -42,7 +42,7 @@ def _ubble_result_fraud_item(user: users_models.User, content: fraud_models.Ubbl status = fraud_models.FraudStatus.SUSPICIOUS # Decision from identification/score - if content.score == ubble_fraud_models.UbbleScore.VALID.value: + if content.score == ubble_serializers.UbbleScore.VALID.value: id_provider_detected_eligibility = subscription_api.get_id_provider_detected_eligibility(user, content) if id_provider_detected_eligibility: status = fraud_models.FraudStatus.OK @@ -58,14 +58,14 @@ def _ubble_result_fraud_item(user: users_models.User, content: fraud_models.Ubbl elif age > users_constants.ELIGIBILITY_AGE_18: reason_codes.add(fraud_models.FraudReasonCode.AGE_TOO_OLD) detail = _ubble_message_from_code(fraud_models.FraudReasonCode.AGE_TOO_OLD).format(age=age) - elif content.score == ubble_fraud_models.UbbleScore.INVALID.value: + elif content.score == ubble_serializers.UbbleScore.INVALID.value: for score, reason_code in [ (content.reference_data_check_score, fraud_models.FraudReasonCode.ID_CHECK_DATA_MATCH), (content.supported, fraud_models.FraudReasonCode.ID_CHECK_NOT_SUPPORTED), (content.expiry_date_score, fraud_models.FraudReasonCode.ID_CHECK_EXPIRED), (content.ove_score, fraud_models.FraudReasonCode.ID_CHECK_NOT_AUTHENTIC), ]: - if score == ubble_fraud_models.UbbleScore.INVALID.value: + if score == ubble_serializers.UbbleScore.INVALID.value: status = fraud_models.FraudStatus.SUSPICIOUS reason_codes.add(reason_code) @@ -77,7 +77,7 @@ def _ubble_result_fraud_item(user: users_models.User, content: fraud_models.Ubbl f" | document supported {_ubble_readable_score(content.supported)}" f" | expiry-date-score {_ubble_readable_score(content.expiry_date_score)}" ) - elif content.score == ubble_fraud_models.UbbleScore.UNDECIDABLE.value: + elif content.score == ubble_serializers.UbbleScore.UNDECIDABLE.value: status = fraud_models.FraudStatus.SUSPICIOUS # Add UNPROCESSABLE only if there are no other reason codes that would be more accurate if not reason_codes: diff --git a/api/src/pcapi/core/fraud/ubble/models.py b/api/src/pcapi/core/fraud/ubble/models.py deleted file mode 100644 index 7e9c9a25ce4..00000000000 --- a/api/src/pcapi/core/fraud/ubble/models.py +++ /dev/null @@ -1,153 +0,0 @@ -import datetime -import enum - -import pydantic.v1 as pydantic_v1 - - -class UbbleIdentificationStatus(enum.Enum): - # ubble v2 - PENDING = "pending" - CAPTURE_IN_PROGRESS = "capture_in_progress" - CHECKS_IN_PROGRESS = "checks_in_progress" - APPROVED = "approved" - DECLINED = "declined" - RETRY_REQUIRED = "retry_required" - REFUSED = "refused" - # ubble v1 - UNINITIATED = "uninitiated" # Identification has only been created (user has not started the verification flow) - INITIATED = "initiated" # User has started the verification flow - PROCESSING = "processing" # User has ended the verification flow, identification-url is not usable anymore - PROCESSED = "processed" # Identification is completely processed by Ubble - ABORTED = "aborted" # User has left the identification, the identification-url is no longer usable (this status is in beta test) - EXPIRED = "expired" # The identification-url has expired and is no longer usable (only uninitiated and initiated identifications can become expired) - - -class UbbleScore(enum.Enum): - VALID = 1.0 - INVALID = 0.0 - UNDECIDABLE = -1.0 - - -class UbbleIdentificationObject(pydantic_v1.BaseModel): - # Parent class for any object defined in https://ubbleai.github.io/developer-documentation/#objects-2 - pass - - -class UbbleIdentificationAttributes(UbbleIdentificationObject): - # https://ubbleai.github.io/developer-documentation/#identifications - comment: str | None - created_at: datetime.datetime = pydantic_v1.Field(alias="created-at") - ended_at: datetime.datetime | None = pydantic_v1.Field(None, alias="ended-at") - identification_id: str = pydantic_v1.Field(alias="identification-id") - identification_url: str = pydantic_v1.Field(alias="identification-url") - number_of_attempts: int = pydantic_v1.Field(alias="number-of-attempts") - redirect_url: str = pydantic_v1.Field(alias="redirect-url") - score: float | None - started_at: datetime.datetime | None = pydantic_v1.Field(None, alias="started-at") - status: UbbleIdentificationStatus - status_updated_at: datetime.datetime = pydantic_v1.Field(alias="status-updated-at") - updated_at: datetime.datetime = pydantic_v1.Field(alias="updated-at") - user_agent: str | None = pydantic_v1.Field(None, alias="user-agent") - user_ip_address: str | None = pydantic_v1.Field(None, alias="user-ip-address") - webhook: str - - -class UbbleReasonCode(UbbleIdentificationObject): - type: str = pydantic_v1.Field(alias="type") - id: int = pydantic_v1.Field(alias="id") - - -class UbbleReasonCodes(UbbleIdentificationObject): - data: list[UbbleReasonCode] - - -class UbbleIdentificationRelationships(UbbleIdentificationObject): - reason_codes: UbbleReasonCodes = pydantic_v1.Field(alias="reason-codes") - - -class UbbleIdentificationData(pydantic_v1.BaseModel): - type: str - id: int - attributes: UbbleIdentificationAttributes - relationships: UbbleIdentificationRelationships - - -class UbbleIdentificationDocuments(UbbleIdentificationObject): - # https://ubbleai.github.io/developer-documentation/#documents - birth_date: str | None = pydantic_v1.Field(None, alias="birth-date") - document_number: str | None = pydantic_v1.Field(None, alias="document-number") - document_type: str | None = pydantic_v1.Field(None, alias="document-type") - first_name: str | None = pydantic_v1.Field(None, alias="first-name") - gender: str | None = pydantic_v1.Field(None) - last_name: str | None = pydantic_v1.Field(None, alias="last-name") - married_name: str | None = pydantic_v1.Field(None, alias="married-name") - signed_image_front_url: str | None = pydantic_v1.Field(None, alias="signed-image-front-url") - signed_image_back_url: str | None = pydantic_v1.Field(None, alias="signed-image-back-url") - - -class UbbleIdentificationDocumentChecks(UbbleIdentificationObject): - # https://ubbleai.github.io/developer-documentation/#document-checks - data_extracted_score: float | None = pydantic_v1.Field(None, alias="data-extracted-score") - expiry_date_score: float | None = pydantic_v1.Field(None, alias="expiry-date-score") - issue_date_score: float | None = pydantic_v1.Field(None, alias="issue-date-score") - live_video_capture_score: float | None = pydantic_v1.Field(None, alias="live-video-capture-score") - mrz_validity_score: float | None = pydantic_v1.Field(None, alias="mrz-validity-score") - mrz_viz_score: float | None = pydantic_v1.Field(None, alias="mrz-viz-score") - ove_back_score: float | None = pydantic_v1.Field(None, alias="ove-back-score") - ove_front_score: float | None = pydantic_v1.Field(None, alias="ove-front-score") - ove_score: float | None = pydantic_v1.Field(None, alias="ove-score") - quality_score: float | None = pydantic_v1.Field(None, alias="quality-score") - score: float | None = pydantic_v1.Field(None, alias="score") - supported: float | None = None - visual_back_score: float | None = pydantic_v1.Field(None, alias="visual-back-score") - visual_front_score: float | None = pydantic_v1.Field(None, alias="visual-front-score") - - -class UbbleIdentificationFaceChecks(UbbleIdentificationObject): - # https://ubbleai.github.io/developer-documentation/#face-checks - active_liveness_score: float | None = pydantic_v1.Field(None, alias="active-liveness-score") - live_video_capture_score: float | None = pydantic_v1.Field(None, alias="live-video-capture-score") - quality_score: float | None = pydantic_v1.Field(None, alias="quality-score") - score: float | None = None - - -class UbbleIdentificationReferenceDataChecks(UbbleIdentificationObject): - # https://ubbleai.github.io/developer-documentation/#reference-data-check - score: float | None = None - - -class UbbleIdentificationDocFaceMatches(UbbleIdentificationObject): - # https://ubbleai.github.io/developer-documentation/#doc-face-matches - score: float | None = None - - -class UbbleIdentificationIncluded(pydantic_v1.BaseModel): - type: str - id: int - attributes: UbbleIdentificationObject - relationships: dict | None - - -class UbbleIdentificationIncludedDocuments(UbbleIdentificationIncluded): - attributes: UbbleIdentificationDocuments - - -class UbbleIdentificationIncludedDocumentChecks(UbbleIdentificationIncluded): - attributes: UbbleIdentificationDocumentChecks - - -class UbbleIdentificationIncludedFaceChecks(UbbleIdentificationIncluded): - attributes: UbbleIdentificationFaceChecks - - -class UbbleIdentificationIncludedReferenceDataChecks(UbbleIdentificationIncluded): - attributes: UbbleIdentificationReferenceDataChecks - - -class UbbleIdentificationIncludedDocFaceMatches(UbbleIdentificationIncluded): - attributes: UbbleIdentificationDocFaceMatches - - -class UbbleIdentificationResponse(pydantic_v1.BaseModel): - data: UbbleIdentificationData - included: list[UbbleIdentificationIncluded] diff --git a/api/src/pcapi/core/subscription/ubble/api.py b/api/src/pcapi/core/subscription/ubble/api.py index 91b887cb816..330f8a33f10 100644 --- a/api/src/pcapi/core/subscription/ubble/api.py +++ b/api/src/pcapi/core/subscription/ubble/api.py @@ -11,6 +11,7 @@ from pcapi import settings from pcapi.connectors.beneficiaries import outscale from pcapi.connectors.beneficiaries import ubble +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.external.attributes import api as external_attributes_api import pcapi.core.external.batch as batch_notification from pcapi.core.external.batch import track_ubble_ko_event @@ -18,7 +19,6 @@ import pcapi.core.fraud.models as fraud_models from pcapi.core.fraud.ubble import api as ubble_fraud_api import pcapi.core.fraud.ubble.constants as ubble_fraud_constants -import pcapi.core.fraud.ubble.models as ubble_fraud_models import pcapi.core.mails.transactional as transactional_mails from pcapi.core.subscription import api as subscription_api from pcapi.core.subscription import models as subscription_models @@ -48,11 +48,11 @@ def update_ubble_workflow(fraud_check: fraud_models.BeneficiaryFraudCheck) -> No user: users_models.User = fraud_check.user - if status == ubble_fraud_models.UbbleIdentificationStatus.PROCESSING: + if status == ubble_serializers.UbbleIdentificationStatus.PROCESSING: fraud_check.status = fraud_models.FraudCheckStatus.PENDING pcapi_repository.repository.save(user, fraud_check) - elif status == ubble_fraud_models.UbbleIdentificationStatus.PROCESSED: + elif status == ubble_serializers.UbbleIdentificationStatus.PROCESSED: fraud_check = subscription_api.handle_eligibility_difference_between_declaration_and_identity_provider( user, fraud_check ) @@ -83,8 +83,8 @@ def update_ubble_workflow(fraud_check: fraud_models.BeneficiaryFraudCheck) -> No external_attributes_api.update_external_user(user) elif status in ( - ubble_fraud_models.UbbleIdentificationStatus.ABORTED, - ubble_fraud_models.UbbleIdentificationStatus.EXPIRED, + ubble_serializers.UbbleIdentificationStatus.ABORTED, + ubble_serializers.UbbleIdentificationStatus.EXPIRED, ): fraud_check.status = fraud_models.FraudCheckStatus.CANCELED pcapi_repository.repository.save(fraud_check) diff --git a/api/src/pcapi/core/users/factories.py b/api/src/pcapi/core/users/factories.py index a7e9a166964..0b6c3d65882 100644 --- a/api/src/pcapi/core/users/factories.py +++ b/api/src/pcapi/core/users/factories.py @@ -14,6 +14,7 @@ from pcapi import settings from pcapi.connectors.beneficiaries.educonnect import models as educonnect_models +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.factories import BaseFactory import pcapi.core.finance.api as finance_api import pcapi.core.finance.models as finance_models @@ -745,7 +746,6 @@ def beneficiaryFraudChecks( # pylint: disable=no-self-argument **kwargs: typing.Any, ) -> fraud_models.BeneficiaryFraudCheck | None: import pcapi.core.fraud.factories as fraud_factories - from pcapi.core.fraud.ubble import models as ubble_fraud_models if not create: return None @@ -756,7 +756,7 @@ def beneficiaryFraudChecks( # pylint: disable=no-self-argument status=fraud_models.FraudCheckStatus.OK, type=fraud_models.FraudCheckType.UBBLE, resultContent=fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + status=ubble_serializers.UbbleIdentificationStatus.PROCESSED, first_name=obj.firstName, last_name=obj.lastName, birth_date=obj.dateOfBirth.date().isoformat(), diff --git a/api/src/pcapi/routes/internal/e2e_ubble.py b/api/src/pcapi/routes/internal/e2e_ubble.py index 24d71ff6eb1..52f7cca32c6 100644 --- a/api/src/pcapi/routes/internal/e2e_ubble.py +++ b/api/src/pcapi/routes/internal/e2e_ubble.py @@ -3,10 +3,10 @@ import uuid from pcapi import settings +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.fraud import factories as fraud_factories from pcapi.core.fraud import models as fraud_models from pcapi.core.fraud.ubble import api as ubble_fraud_api -from pcapi.core.fraud.ubble import models as ubble_fraud_models from pcapi.core.subscription import api as subscription_api from pcapi.core.users import models as users_models from pcapi.repository import repository @@ -58,6 +58,6 @@ def make_identification_response(user: users_models.User, errors: list[UbbleErro identification_url=identification_url, id_document_number="123456789012", reason_codes=[fraud_models.UBBLE_REASON_CODE_MAPPING[error.value] for error in errors] if errors else None, - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, - score=ubble_fraud_models.UbbleScore.INVALID.value if errors else ubble_fraud_models.UbbleScore.VALID.value, + status=ubble_serializers.UbbleIdentificationStatus.PROCESSED, + score=ubble_serializers.UbbleScore.INVALID.value if errors else ubble_serializers.UbbleScore.VALID.value, ) diff --git a/api/src/pcapi/validation/routes/ubble.py b/api/src/pcapi/validation/routes/ubble.py index 745050c3e84..ae07d1ec4f9 100644 --- a/api/src/pcapi/validation/routes/ubble.py +++ b/api/src/pcapi/validation/routes/ubble.py @@ -9,13 +9,14 @@ import pydantic.v1 as pydantic_v1 from pcapi import settings -from pcapi.core.fraud.ubble import models as ubble_fraud_models +from pcapi.connectors.serialization import ubble_serializers from pcapi.models.api_errors import ForbiddenError UBBLE_SIGNATURE_RE = re.compile(r"^ts=(?P\d+),v1=(?P\S{64})$") +# TODO move this file to serialization class Configuration(pydantic_v1.BaseModel): id: int name: str @@ -23,7 +24,7 @@ class Configuration(pydantic_v1.BaseModel): class WebhookRequest(pydantic_v1.BaseModel): identification_id: str - status: ubble_fraud_models.UbbleIdentificationStatus + status: ubble_serializers.UbbleIdentificationStatus configuration: Configuration diff --git a/api/tests/connectors/beneficiaries/ubble_fixtures.py b/api/tests/connectors/beneficiaries/ubble_fixtures.py index 87ffeec1ce4..838fcaacd30 100644 --- a/api/tests/connectors/beneficiaries/ubble_fixtures.py +++ b/api/tests/connectors/beneficiaries/ubble_fixtures.py @@ -1,4 +1,4 @@ -from pcapi.core.fraud.ubble import models as ubble_fraud_models +from pcapi.connectors.serialization import ubble_serializers UBBLE_IDENTIFICATION_RESPONSE = { @@ -6,7 +6,7 @@ "type": "identifications", "id": "3191295", "attributes": { - "score": ubble_fraud_models.UbbleScore.INVALID.value, + "score": ubble_serializers.UbbleScore.INVALID.value, "anonymized-at": None, "comment": None, "created-at": "2021-11-18T18:59:59.273402Z", @@ -57,20 +57,20 @@ "type": "document-checks", "id": "4997875", "attributes": { - "data-extracted-score": ubble_fraud_models.UbbleScore.INVALID.value, - "expiry-date-score": ubble_fraud_models.UbbleScore.INVALID.value, + "data-extracted-score": ubble_serializers.UbbleScore.INVALID.value, + "expiry-date-score": ubble_serializers.UbbleScore.INVALID.value, "issue-date-score": None, "live-video-capture-score": None, - "mrz-validity-score": ubble_fraud_models.UbbleScore.INVALID.value, - "mrz-viz-score": ubble_fraud_models.UbbleScore.INVALID.value, - "ove-back-score": ubble_fraud_models.UbbleScore.INVALID.value, - "ove-front-score": ubble_fraud_models.UbbleScore.INVALID.value, - "ove-score": ubble_fraud_models.UbbleScore.INVALID.value, - "quality-score": ubble_fraud_models.UbbleScore.INVALID.value, - "score": ubble_fraud_models.UbbleScore.INVALID.value, - "supported": ubble_fraud_models.UbbleScore.INVALID.value, - "visual-back-score": ubble_fraud_models.UbbleScore.INVALID.value, - "visual-front-score": ubble_fraud_models.UbbleScore.INVALID.value, + "mrz-validity-score": ubble_serializers.UbbleScore.INVALID.value, + "mrz-viz-score": ubble_serializers.UbbleScore.INVALID.value, + "ove-back-score": ubble_serializers.UbbleScore.INVALID.value, + "ove-front-score": ubble_serializers.UbbleScore.INVALID.value, + "ove-score": ubble_serializers.UbbleScore.INVALID.value, + "quality-score": ubble_serializers.UbbleScore.INVALID.value, + "score": ubble_serializers.UbbleScore.INVALID.value, + "supported": ubble_serializers.UbbleScore.INVALID.value, + "visual-back-score": ubble_serializers.UbbleScore.INVALID.value, + "visual-front-score": ubble_serializers.UbbleScore.INVALID.value, }, "relationships": {}, }, diff --git a/api/tests/core/fraud/test_api.py b/api/tests/core/fraud/test_api.py index 7d9a9024726..e2cbdb9b138 100644 --- a/api/tests/core/fraud/test_api.py +++ b/api/tests/core/fraud/test_api.py @@ -6,10 +6,10 @@ import time_machine from pcapi import settings +from pcapi.connectors.serialization import ubble_serializers import pcapi.core.fraud.api as fraud_api import pcapi.core.fraud.factories as fraud_factories import pcapi.core.fraud.models as fraud_models -import pcapi.core.fraud.ubble.models as ubble_fraud_models import pcapi.core.mails.testing as mails_testing from pcapi.core.testing import override_settings import pcapi.core.users.factories as users_factories @@ -580,7 +580,7 @@ def test_has_user_performed_identity_check_without_identity_fraud_check(self): def test_has_user_performed_identity_check_status_initiated(self): user = user = build_user_at_id_check(18) ubble_content = fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.INITIATED + status=ubble_serializers.UbbleIdentificationStatus.INITIATED ) fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_models.FraudCheckType.UBBLE, diff --git a/api/tests/core/subscription/test_factories.py b/api/tests/core/subscription/test_factories.py index de9deb77f34..a690a73a041 100644 --- a/api/tests/core/subscription/test_factories.py +++ b/api/tests/core/subscription/test_factories.py @@ -10,7 +10,7 @@ import pytz from pcapi import settings -from pcapi.core.fraud.ubble import models as ubble_fraud_models +from pcapi.connectors.serialization import ubble_serializers class IdentificationState(Enum): @@ -24,13 +24,13 @@ class IdentificationState(Enum): STATE_STATUS_MAPPING = { - IdentificationState.NEW: ubble_fraud_models.UbbleIdentificationStatus.UNINITIATED, - IdentificationState.INITIATED: ubble_fraud_models.UbbleIdentificationStatus.INITIATED, - IdentificationState.ABORTED: ubble_fraud_models.UbbleIdentificationStatus.ABORTED, - IdentificationState.PROCESSING: ubble_fraud_models.UbbleIdentificationStatus.PROCESSING, - IdentificationState.VALID: ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, - IdentificationState.INVALID: ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, - IdentificationState.UNPROCESSABLE: ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + IdentificationState.NEW: ubble_serializers.UbbleIdentificationStatus.UNINITIATED, + IdentificationState.INITIATED: ubble_serializers.UbbleIdentificationStatus.INITIATED, + IdentificationState.ABORTED: ubble_serializers.UbbleIdentificationStatus.ABORTED, + IdentificationState.PROCESSING: ubble_serializers.UbbleIdentificationStatus.PROCESSING, + IdentificationState.VALID: ubble_serializers.UbbleIdentificationStatus.PROCESSED, + IdentificationState.INVALID: ubble_serializers.UbbleIdentificationStatus.PROCESSED, + IdentificationState.UNPROCESSABLE: ubble_serializers.UbbleIdentificationStatus.PROCESSED, } @@ -44,7 +44,7 @@ class IdentificationIncludedType(Enum): class UbbleReasonCodeFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleReasonCode + model = ubble_serializers.UbbleReasonCode class Params: error_code = 0 @@ -55,7 +55,7 @@ class Params: class UbbleReasonCodesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleReasonCodes + model = ubble_serializers.UbbleReasonCodes class Params: error_codes = [] @@ -67,7 +67,7 @@ def data(self): class UbbleIdentificationRelationshipsFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationRelationships + model = ubble_serializers.UbbleIdentificationRelationships rename = {"reason_codes": "reason-codes"} class Params: @@ -78,7 +78,7 @@ class Params: class UbbleIdentificationDataAttributesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationAttributes + model = ubble_serializers.UbbleIdentificationAttributes rename = { "anonymized_at": "anonymized-at", "created_at": "created-at", @@ -126,9 +126,9 @@ def number_of_attempts(self): @factory.lazy_attribute def score(self): return { - IdentificationState.UNPROCESSABLE: ubble_fraud_models.UbbleScore.UNDECIDABLE.value, - IdentificationState.INVALID: ubble_fraud_models.UbbleScore.INVALID.value, - IdentificationState.VALID: ubble_fraud_models.UbbleScore.VALID.value, + IdentificationState.UNPROCESSABLE: ubble_serializers.UbbleScore.UNDECIDABLE.value, + IdentificationState.INVALID: ubble_serializers.UbbleScore.INVALID.value, + IdentificationState.VALID: ubble_serializers.UbbleScore.VALID.value, }.get(self.identification_state) @factory.lazy_attribute @@ -203,7 +203,7 @@ def user_ip_address(self): class UbbleIdentificationDataFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationData + model = ubble_serializers.UbbleIdentificationData class Params: identification_state = IdentificationState.NEW @@ -222,7 +222,7 @@ class Params: class UbbleIdentificationIncludedDocumentsAttributesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationDocuments + model = ubble_serializers.UbbleIdentificationDocuments rename = { "birth_date": "birth-date", "birth_place": "birth-place", @@ -266,7 +266,7 @@ class Meta: class UbbleIdentificationIncludedDocumentChecksAttributesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationDocumentChecks + model = ubble_serializers.UbbleIdentificationDocumentChecks rename = { "data_extracted_score": "data-extracted-score", "expiry_date_score": "expiry-date-score", @@ -286,7 +286,7 @@ class Params: identification_state = IdentificationState.VALID data_extracted_score = None - expiry_date_score = ubble_fraud_models.UbbleScore.VALID.value + expiry_date_score = ubble_serializers.UbbleScore.VALID.value issue_date_score = None live_video_capture_score = None mrz_validity_score = None @@ -295,32 +295,32 @@ class Params: ove_front_score = None ove_score = None quality_score: None - supported = ubble_fraud_models.UbbleScore.VALID.value + supported = ubble_serializers.UbbleScore.VALID.value visual_back_score = None visual_front_score = None @factory.lazy_attribute def score(self): return { - IdentificationState.UNPROCESSABLE: ubble_fraud_models.UbbleScore.INVALID.value, - IdentificationState.INVALID: ubble_fraud_models.UbbleScore.INVALID.value, - IdentificationState.VALID: ubble_fraud_models.UbbleScore.VALID.value, + IdentificationState.UNPROCESSABLE: ubble_serializers.UbbleScore.INVALID.value, + IdentificationState.INVALID: ubble_serializers.UbbleScore.INVALID.value, + IdentificationState.VALID: ubble_serializers.UbbleScore.VALID.value, }.get(self.identification_state) class UbbleIdentificationIncludedDocFaceMatchesAttributesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationDocFaceMatches + model = ubble_serializers.UbbleIdentificationDocFaceMatches class Params: identification_state = IdentificationState.VALID - score = ubble_fraud_models.UbbleScore.VALID.value + score = ubble_serializers.UbbleScore.VALID.value class UbbleIdentificationIncludedFaceChecksAttributesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationFaceChecks + model = ubble_serializers.UbbleIdentificationFaceChecks rename = { "active_liveness_score": "active-liveness-score", "live_video_capture_score": "live-video-capture-score", @@ -333,19 +333,19 @@ class Params: active_liveness_score = None live_video_capture_score = None quality_score = None - score = ubble_fraud_models.UbbleScore.VALID.value + score = ubble_serializers.UbbleScore.VALID.value class UbbleIdentificationIncludedReferenceDataChecksAttributesFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationReferenceDataChecks + model = ubble_serializers.UbbleIdentificationReferenceDataChecks - score = ubble_fraud_models.UbbleScore.VALID.value + score = ubble_serializers.UbbleScore.VALID.value class UbbleIdentificationIncludedFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationIncluded + model = ubble_serializers.UbbleIdentificationIncluded abstract = True type = None @@ -355,7 +355,7 @@ class Meta: class UbbleIdentificationIncludedDocumentsFactory(UbbleIdentificationIncludedFactory): class Meta: - model = ubble_fraud_models.UbbleIdentificationIncludedDocuments + model = ubble_serializers.UbbleIdentificationIncludedDocuments type = IdentificationIncludedType.DOCUMENTS.value attributes = factory.SubFactory(UbbleIdentificationIncludedDocumentsAttributesFactory) @@ -363,7 +363,7 @@ class Meta: class UbbleIdentificationIncludedDocumentChecksFactory(UbbleIdentificationIncludedFactory): class Meta: - model = ubble_fraud_models.UbbleIdentificationIncludedDocumentChecks + model = ubble_serializers.UbbleIdentificationIncludedDocumentChecks type = IdentificationIncludedType.DOCUMENT_CHECKS.value attributes = factory.SubFactory(UbbleIdentificationIncludedDocumentChecksAttributesFactory) @@ -371,7 +371,7 @@ class Meta: class UbbleIdentificationIncludedFaceChecksFactory(UbbleIdentificationIncludedFactory): class Meta: - model = ubble_fraud_models.UbbleIdentificationIncludedFaceChecks + model = ubble_serializers.UbbleIdentificationIncludedFaceChecks type = IdentificationIncludedType.FACE_CHECKS.value attributes = factory.SubFactory(UbbleIdentificationIncludedFaceChecksAttributesFactory) @@ -379,7 +379,7 @@ class Meta: class UbbleIdentificationIncludedReferenceDataChecksFactory(UbbleIdentificationIncludedFactory): class Meta: - model = ubble_fraud_models.UbbleIdentificationIncludedReferenceDataChecks + model = ubble_serializers.UbbleIdentificationIncludedReferenceDataChecks type = IdentificationIncludedType.REFERENCE_DATA_CHECKS.value attributes = factory.SubFactory(UbbleIdentificationIncludedReferenceDataChecksAttributesFactory) @@ -387,7 +387,7 @@ class Meta: class UbbleIdentificationIncludedDocFaceMatchesFactory(UbbleIdentificationIncludedFactory): class Meta: - model = ubble_fraud_models.UbbleIdentificationIncludedDocFaceMatches + model = ubble_serializers.UbbleIdentificationIncludedDocFaceMatches type = IdentificationIncludedType.DOC_FACE_MATCHES.value attributes = factory.SubFactory(UbbleIdentificationIncludedDocFaceMatchesAttributesFactory) @@ -395,7 +395,7 @@ class Meta: class UbbleIdentificationResponseFactory(factory.Factory): class Meta: - model = ubble_fraud_models.UbbleIdentificationResponse + model = ubble_serializers.UbbleIdentificationResponse class Params: identification_state = IdentificationState.NEW diff --git a/api/tests/core/subscription/ubble/end_to_end/test_subscription_via_ubble.py b/api/tests/core/subscription/ubble/end_to_end/test_subscription_via_ubble.py index 728a6202151..e1b75cb247a 100644 --- a/api/tests/core/subscription/ubble/end_to_end/test_subscription_via_ubble.py +++ b/api/tests/core/subscription/ubble/end_to_end/test_subscription_via_ubble.py @@ -10,9 +10,9 @@ import time_machine from pcapi import settings +from pcapi.connectors.serialization.ubble_serializers import UbbleIdentificationStatus from pcapi.core.fraud import factories as fraud_factories from pcapi.core.fraud import models as fraud_models -from pcapi.core.fraud.ubble.models import UbbleIdentificationStatus from pcapi.core.subscription import api as subscription_api from pcapi.core.subscription import models as subscription_models from pcapi.core.users import factories as users_factories diff --git a/api/tests/core/subscription/ubble/test_api.py b/api/tests/core/subscription/ubble/test_api.py index fd70fe5b81f..30f26bd48db 100644 --- a/api/tests/core/subscription/ubble/test_api.py +++ b/api/tests/core/subscription/ubble/test_api.py @@ -9,6 +9,7 @@ import time_machine from pcapi import settings +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.fraud import factories as fraud_factories from pcapi.core.fraud import models as fraud_models from pcapi.core.fraud.exceptions import IncompatibleFraudCheckStatus @@ -18,13 +19,12 @@ from pcapi.core.fraud.models import FraudCheckType from pcapi.core.fraud.models import UbbleContent from pcapi.core.fraud.ubble import constants as ubble_constants -from pcapi.core.fraud.ubble import models as ubble_fraud_models from pcapi.core.subscription import messages as subscription_messages from pcapi.core.subscription import models as subscription_models from pcapi.core.subscription.exceptions import BeneficiaryFraudCheckMissingException from pcapi.core.subscription.ubble import api as ubble_subscription_api +from pcapi.core.subscription.ubble import errors as ubble_errors from pcapi.core.subscription.ubble import exceptions as ubble_exceptions -from pcapi.core.subscription.ubble import models as ubble_models from pcapi.core.testing import override_features from pcapi.core.users import factories as users_factories from pcapi.core.users import models as users_models @@ -128,32 +128,32 @@ def test_start_ubble_workflow_v1(self, ubble_mock): [ ( IdentificationState.INITIATED, - ubble_fraud_models.UbbleIdentificationStatus.INITIATED, + ubble_serializers.UbbleIdentificationStatus.INITIATED, fraud_models.FraudCheckStatus.PENDING, ), ( IdentificationState.PROCESSING, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSING, + ubble_serializers.UbbleIdentificationStatus.PROCESSING, fraud_models.FraudCheckStatus.PENDING, ), ( IdentificationState.VALID, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, fraud_models.FraudCheckStatus.OK, ), ( IdentificationState.INVALID, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, fraud_models.FraudCheckStatus.KO, ), ( IdentificationState.UNPROCESSABLE, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, fraud_models.FraudCheckStatus.SUSPICIOUS, ), ( IdentificationState.ABORTED, - ubble_fraud_models.UbbleIdentificationStatus.ABORTED, + ubble_serializers.UbbleIdentificationStatus.ABORTED, fraud_models.FraudCheckStatus.CANCELED, ), ], diff --git a/api/tests/routes/external/user_subscription_test.py b/api/tests/routes/external/user_subscription_test.py index 52a6e35569c..06b252eef3e 100644 --- a/api/tests/routes/external/user_subscription_test.py +++ b/api/tests/routes/external/user_subscription_test.py @@ -13,12 +13,12 @@ from pcapi import settings from pcapi.connectors.dms import api as api_dms from pcapi.connectors.dms import models as dms_models +from pcapi.connectors.serialization import ubble_serializers from pcapi.core import testing from pcapi.core.fraud import api as fraud_api from pcapi.core.fraud import factories as fraud_factories from pcapi.core.fraud import models as fraud_models from pcapi.core.fraud.ubble import api as ubble_fraud_api -from pcapi.core.fraud.ubble import models as ubble_fraud_models import pcapi.core.mails.testing as mails_testing from pcapi.core.subscription import api as subscription_api from pcapi.core.subscription import messages as subscription_messages @@ -1207,15 +1207,15 @@ def test_fraud_check_valid(self, client, ubble_mocker): document = list(filter(lambda included: included.type == "documents", ubble_identification_response.included))[ 0 ].attributes - assert content.score == ubble_fraud_models.UbbleScore.VALID.value + assert content.score == ubble_serializers.UbbleScore.VALID.value assert content.status == test_factories.STATE_STATUS_MAPPING[notified_identification_state] assert content.comment == ubble_identification_response.data.attributes.comment assert content.last_name == document.last_name assert content.first_name == document.first_name assert str(content.birth_date) == document.birth_date - assert content.supported == ubble_fraud_models.UbbleScore.VALID.value + assert content.supported == ubble_serializers.UbbleScore.VALID.value assert content.document_type == document.document_type - assert content.expiry_date_score == ubble_fraud_models.UbbleScore.VALID.value + assert content.expiry_date_score == ubble_serializers.UbbleScore.VALID.value assert str(content.identification_id) == ubble_identification_response.data.attributes.identification_id assert content.id_document_number == document.document_number assert ( @@ -1258,7 +1258,7 @@ def test_fraud_check_invalid(self, client, ubble_mocker): document_check = list( filter(lambda included: included.type == "document-checks", ubble_identification_response.included) )[0].attributes - assert content.score == ubble_fraud_models.UbbleScore.INVALID.value + assert content.score == ubble_serializers.UbbleScore.INVALID.value assert content.status == test_factories.STATE_STATUS_MAPPING[notified_identification_state] assert content.comment == ubble_identification_response.data.attributes.comment assert content.last_name == document.last_name @@ -1303,7 +1303,7 @@ def test_fraud_check_unprocessable(self, client, ubble_mocker): document_check = list( filter(lambda included: included.type == "document-checks", ubble_identification_response.included) )[0].attributes - assert content.score == ubble_fraud_models.UbbleScore.UNDECIDABLE.value + assert content.score == ubble_serializers.UbbleScore.UNDECIDABLE.value assert content.status == test_factories.STATE_STATUS_MAPPING[notified_identification_state] assert content.comment == ubble_identification_response.data.attributes.comment assert content.last_name == document.last_name @@ -1368,7 +1368,7 @@ def test_birth_date_overrided_with_ubble_test_emails(self, client, ubble_mocker, reasonCodes=None, eligibilityType=users_models.EligibilityType.AGE18, ) - request_data = self._get_request_body(fraud_check, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED) + request_data = self._get_request_body(fraud_check, ubble_serializers.UbbleIdentificationStatus.PROCESSED) ubble_identification_response = test_factories.UbbleIdentificationResponseFactory( identification_state=test_factories.IdentificationState.VALID, data__attributes__identification_id=str(request_data.identification_id), @@ -1409,7 +1409,7 @@ def test_birth_date_not_overridden_with_non_ubble_test_emails(self, client, ubbl reasonCodes=None, eligibilityType=users_models.EligibilityType.AGE18, ) - request_data = self._get_request_body(fraud_check, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED) + request_data = self._get_request_body(fraud_check, ubble_serializers.UbbleIdentificationStatus.PROCESSED) ubble_identification_response = test_factories.UbbleIdentificationResponseFactory( identification_state=test_factories.IdentificationState.VALID, data__attributes__identification_id=str(request_data.identification_id), @@ -1451,7 +1451,7 @@ def test_ubble_test_emails_not_actives_on_production(self, client, ubble_mocker, reasonCodes=None, eligibilityType=users_models.EligibilityType.AGE18, ) - request_data = self._get_request_body(fraud_check, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED) + request_data = self._get_request_body(fraud_check, ubble_serializers.UbbleIdentificationStatus.PROCESSED) ubble_identification_response = test_factories.UbbleIdentificationResponseFactory( identification_state=test_factories.IdentificationState.VALID, data__attributes__identification_id=str(request_data.identification_id), @@ -1494,7 +1494,7 @@ def _init_decision_test( "last_name": None, "registration_datetime": datetime.datetime.utcnow().isoformat(), "score": None, - "status": ubble_fraud_models.UbbleIdentificationStatus.PROCESSING.value, + "status": ubble_serializers.UbbleIdentificationStatus.PROCESSING.value, "supported": None, }, status=fraud_models.FraudCheckStatus.PENDING, @@ -1514,7 +1514,7 @@ def _init_decision_test( eligibilityType=users_models.EligibilityType.AGE18, ) repository.save(honor_fraud_check) - request_data = self._get_request_body(ubble_fraud_check, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED) + request_data = self._get_request_body(ubble_fraud_check, ubble_serializers.UbbleIdentificationStatus.PROCESSED) return user, ubble_fraud_check, request_data def _post_webhook(self, client, ubble_mocker, request_data, ubble_identification_response): @@ -1579,7 +1579,7 @@ def test_decision_age_cannot_become_beneficiary( ) user, ubble_fraud_check, request_data = self._init_decision_test() - request_data = self._get_request_body(ubble_fraud_check, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED) + request_data = self._get_request_body(ubble_fraud_check, ubble_serializers.UbbleIdentificationStatus.PROCESSED) ubble_identification_response = test_factories.UbbleIdentificationResponseFactory( identification_state=test_factories.IdentificationState.VALID, data__attributes__identification_id=str(request_data.identification_id), @@ -1592,29 +1592,29 @@ def test_decision_age_cannot_become_beneficiary( attributes__last_name=user.lastName, ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), ], ) @@ -1660,29 +1660,29 @@ def test_decision_duplicate_user(self, client, ubble_mocker): attributes__last_name=existing_user.lastName, ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), ], ) @@ -1736,29 +1736,29 @@ def test_decision_duplicate_id_piece_number(self, client, ubble_mocker): attributes__last_name="Doe", ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), ], ) @@ -1805,30 +1805,30 @@ def test_decision_reference_data_check_failed(self, client, ubble_mocker): attributes__last_name="FRAUDSTER", ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__supported=ubble_fraud_models.UbbleScore.VALID.value, - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__supported=ubble_serializers.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.INVALID.value, # 0 + attributes__score=ubble_serializers.UbbleScore.INVALID.value, # 0 ), ], ) @@ -1947,30 +1947,30 @@ def test_blocked_other_and_ko_if_score_invalid_and_the_rest_is_valid(self, clien attributes__last_name="FRAUDSTER", ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__supported=ubble_fraud_models.UbbleScore.VALID.value, - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__supported=ubble_serializers.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), ], ) @@ -1994,7 +1994,7 @@ def test_blocked_other_and_ko_if_score_invalid_and_the_rest_is_valid(self, clien @pytest.mark.parametrize( "ref_data_check_score", - [ubble_fraud_models.UbbleScore.VALID.value, ubble_fraud_models.UbbleScore.UNDECIDABLE.value], + [ubble_serializers.UbbleScore.VALID.value, ubble_serializers.UbbleScore.UNDECIDABLE.value], ) def test_decision_document_not_supported(self, client, ubble_mocker, ref_data_check_score): user, ubble_fraud_check, request_data = self._init_decision_test() @@ -2017,27 +2017,27 @@ def test_decision_document_not_supported(self, client, ubble_mocker, ref_data_ch attributes__last_name=None, ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__supported=ubble_fraud_models.UbbleScore.INVALID.value, # 0 - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.UNDECIDABLE.value, # -1 - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.UNDECIDABLE.value, # -1 - attributes__issue_date_score=ubble_fraud_models.UbbleScore.UNDECIDABLE.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__supported=ubble_serializers.UbbleScore.INVALID.value, # 0 + attributes__data_extracted_score=ubble_serializers.UbbleScore.UNDECIDABLE.value, # -1 + attributes__expiry_date_score=ubble_serializers.UbbleScore.UNDECIDABLE.value, # -1 + attributes__issue_date_score=ubble_serializers.UbbleScore.UNDECIDABLE.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( attributes__score=ref_data_check_score, # 1 or -1 @@ -2066,11 +2066,11 @@ def test_decision_document_not_supported(self, client, ubble_mocker, ref_data_ch self._assert_email_sent(user, 385) @pytest.mark.parametrize( - "doc_supported", [ubble_fraud_models.UbbleScore.VALID.value, ubble_fraud_models.UbbleScore.UNDECIDABLE.value] + "doc_supported", [ubble_serializers.UbbleScore.VALID.value, ubble_serializers.UbbleScore.UNDECIDABLE.value] ) @pytest.mark.parametrize( "ref_data_check_score", - [ubble_fraud_models.UbbleScore.VALID.value, ubble_fraud_models.UbbleScore.UNDECIDABLE.value], + [ubble_serializers.UbbleScore.VALID.value, ubble_serializers.UbbleScore.UNDECIDABLE.value], ) def test_decision_document_expired(self, client, ubble_mocker, ref_data_check_score, doc_supported): user, ubble_fraud_check, request_data = self._init_decision_test() @@ -2095,26 +2095,26 @@ def test_decision_document_expired(self, client, ubble_mocker, ref_data_check_sc ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( attributes__supported=doc_supported, # 1 or -1 - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.INVALID.value, # 0 - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.INVALID.value, # 0 + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( attributes__score=ref_data_check_score, # 1 or -1 @@ -2169,30 +2169,30 @@ def test_decision_document_not_authentic(self, client, ubble_mocker): attributes__last_name="Doe", ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__supported=ubble_fraud_models.UbbleScore.VALID.value, - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.INVALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__supported=ubble_serializers.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.INVALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), ], ) @@ -2273,30 +2273,30 @@ def test_decision_document_not_authentic_no_retry_left(self, client, ubble_mocke attributes__last_name="Doe", ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( - attributes__supported=ubble_fraud_models.UbbleScore.VALID.value, - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__expiry_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.INVALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__supported=ubble_serializers.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, + attributes__expiry_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.INVALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), ], ) @@ -2322,14 +2322,14 @@ def test_decision_document_not_authentic_no_retry_left(self, client, ubble_mocke assert mails_testing.outbox[0]["template"]["id_prod"] == 760 @pytest.mark.parametrize( - "expiry_score", [ubble_fraud_models.UbbleScore.VALID.value, ubble_fraud_models.UbbleScore.UNDECIDABLE.value] + "expiry_score", [ubble_serializers.UbbleScore.VALID.value, ubble_serializers.UbbleScore.UNDECIDABLE.value] ) @pytest.mark.parametrize( - "doc_supported", [ubble_fraud_models.UbbleScore.VALID.value, ubble_fraud_models.UbbleScore.UNDECIDABLE.value] + "doc_supported", [ubble_serializers.UbbleScore.VALID.value, ubble_serializers.UbbleScore.UNDECIDABLE.value] ) @pytest.mark.parametrize( "ref_data_check_score", - [ubble_fraud_models.UbbleScore.VALID.value, ubble_fraud_models.UbbleScore.UNDECIDABLE.value], + [ubble_serializers.UbbleScore.VALID.value, ubble_serializers.UbbleScore.UNDECIDABLE.value], ) def test_decision_invalid_for_another_reason( self, client, ubble_mocker, ref_data_check_score, doc_supported, expiry_score @@ -2349,26 +2349,26 @@ def test_decision_invalid_for_another_reason( ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( attributes__supported=doc_supported, # 1 or -1 - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, attributes__expiry_date_score=expiry_score, # 1 or -1 - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( attributes__score=ref_data_check_score, # 1 or -1 @@ -2397,25 +2397,25 @@ def test_decision_invalid_for_another_reason( @pytest.mark.parametrize( "expiry_score", [ - ubble_fraud_models.UbbleScore.VALID.value, - ubble_fraud_models.UbbleScore.UNDECIDABLE.value, - ubble_fraud_models.UbbleScore.UNDECIDABLE.value, + ubble_serializers.UbbleScore.VALID.value, + ubble_serializers.UbbleScore.UNDECIDABLE.value, + ubble_serializers.UbbleScore.UNDECIDABLE.value, ], ) @pytest.mark.parametrize( "doc_supported", [ - ubble_fraud_models.UbbleScore.VALID.value, - ubble_fraud_models.UbbleScore.UNDECIDABLE.value, - ubble_fraud_models.UbbleScore.UNDECIDABLE.value, + ubble_serializers.UbbleScore.VALID.value, + ubble_serializers.UbbleScore.UNDECIDABLE.value, + ubble_serializers.UbbleScore.UNDECIDABLE.value, ], ) @pytest.mark.parametrize( "ref_data_check_score", [ - ubble_fraud_models.UbbleScore.VALID.value, - ubble_fraud_models.UbbleScore.UNDECIDABLE.value, - ubble_fraud_models.UbbleScore.UNDECIDABLE.value, + ubble_serializers.UbbleScore.VALID.value, + ubble_serializers.UbbleScore.UNDECIDABLE.value, + ubble_serializers.UbbleScore.UNDECIDABLE.value, ], ) def test_decision_unprocessable(self, client, ubble_mocker, ref_data_check_score, doc_supported, expiry_score): @@ -2440,26 +2440,26 @@ def test_decision_unprocessable(self, client, ubble_mocker, ref_data_check_score ), test_factories.UbbleIdentificationIncludedDocumentChecksFactory( attributes__supported=doc_supported, # 1, 0 or -1 - attributes__data_extracted_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__data_extracted_score=ubble_serializers.UbbleScore.VALID.value, attributes__expiry_date_score=expiry_score, # 1, 0 or -1 - attributes__issue_date_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_validity_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__mrz_viz_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_front_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__ove_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_back_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__visual_front_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__issue_date_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_validity_score=ubble_serializers.UbbleScore.VALID.value, + attributes__mrz_viz_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_front_score=ubble_serializers.UbbleScore.VALID.value, + attributes__ove_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_back_score=ubble_serializers.UbbleScore.VALID.value, + attributes__visual_front_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedFaceChecksFactory( - attributes__active_liveness_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__live_video_capture_score=ubble_fraud_models.UbbleScore.VALID.value, - attributes__quality_score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__active_liveness_score=ubble_serializers.UbbleScore.VALID.value, + attributes__live_video_capture_score=ubble_serializers.UbbleScore.VALID.value, + attributes__quality_score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedDocFaceMatchesFactory( - attributes__score=ubble_fraud_models.UbbleScore.VALID.value, + attributes__score=ubble_serializers.UbbleScore.VALID.value, ), test_factories.UbbleIdentificationIncludedReferenceDataChecksFactory( attributes__score=ref_data_check_score, # 1, 0 or -1 diff --git a/api/tests/routes/native/v1/account_test.py b/api/tests/routes/native/v1/account_test.py index 84efc649c64..70ba8e0f1e2 100644 --- a/api/tests/routes/native/v1/account_test.py +++ b/api/tests/routes/native/v1/account_test.py @@ -17,6 +17,7 @@ from pcapi import settings from pcapi.connectors.google_oauth import GoogleUser +from pcapi.connectors.serialization import ubble_serializers from pcapi.core import token as token_utils from pcapi.core.bookings import factories as booking_factories from pcapi.core.bookings.factories import BookingFactory @@ -26,7 +27,6 @@ import pcapi.core.finance.models as finance_models from pcapi.core.fraud import factories as fraud_factories from pcapi.core.fraud import models as fraud_models -from pcapi.core.fraud.ubble import models as ubble_fraud_models from pcapi.core.history import factories as history_factories from pcapi.core.history import models as history_models import pcapi.core.mails.testing as mails_testing @@ -2423,9 +2423,9 @@ def test_request_ubble_http_error_status(self, client, ubble_mock_http_error_sta @pytest.mark.parametrize( "fraud_check_status,ubble_status", [ - (fraud_models.FraudCheckStatus.PENDING, ubble_fraud_models.UbbleIdentificationStatus.PROCESSING), - (fraud_models.FraudCheckStatus.OK, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED), - (fraud_models.FraudCheckStatus.KO, ubble_fraud_models.UbbleIdentificationStatus.PROCESSED), + (fraud_models.FraudCheckStatus.PENDING, ubble_serializers.UbbleIdentificationStatus.PROCESSING), + (fraud_models.FraudCheckStatus.OK, ubble_serializers.UbbleIdentificationStatus.PROCESSED), + (fraud_models.FraudCheckStatus.KO, ubble_serializers.UbbleIdentificationStatus.PROCESSED), ], ) def test_request_ubble_second_check_blocked(self, client, fraud_check_status, ubble_status): @@ -2461,7 +2461,7 @@ def test_request_ubble_second_check_after_first_aborted(self, client, ubble_mock type=fraud_models.FraudCheckType.UBBLE, status=fraud_models.FraudCheckStatus.CANCELED, resultContent=fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.ABORTED + status=ubble_serializers.UbbleIdentificationStatus.ABORTED ), ) @@ -2502,7 +2502,7 @@ def test_request_ubble_retry(self, client, ubble_mock, reason, retry_number, exp status=fraud_models.FraudCheckStatus.SUSPICIOUS, reasonCodes=[reason], resultContent=fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSED + status=ubble_serializers.UbbleIdentificationStatus.PROCESSED ), ) @@ -2536,7 +2536,7 @@ def test_request_ubble_retry_not_allowed(self, client, ubble_mock, reason): status=fraud_models.FraudCheckStatus.SUSPICIOUS, reasonCodes=[reason], resultContent=fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSED + status=ubble_serializers.UbbleIdentificationStatus.PROCESSED ), ) @@ -2552,7 +2552,7 @@ def test_allow_rerun_identification_from_started(self, client, ubble_mock): expected_url = "https://id.ubble.ai/ef055567-3794-4ca5-afad-dce60fe0f227" ubble_content = fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.INITIATED, + status=ubble_serializers.UbbleIdentificationStatus.INITIATED, identification_url=expected_url, ) fraud_factories.BeneficiaryFraudCheckFactory( diff --git a/api/tests/routes/native/v1/subscription_test.py b/api/tests/routes/native/v1/subscription_test.py index 979f82d81f8..bb044546406 100644 --- a/api/tests/routes/native/v1/subscription_test.py +++ b/api/tests/routes/native/v1/subscription_test.py @@ -5,9 +5,9 @@ import time_machine from pcapi import settings +from pcapi.connectors.serialization import ubble_serializers from pcapi.core.fraud import factories as fraud_factories from pcapi.core.fraud import models as fraud_models -from pcapi.core.fraud.ubble import models as ubble_fraud_models from pcapi.core.subscription.models import SubscriptionStepCompletionState import pcapi.core.subscription.ubble.models as ubble_models from pcapi.core.testing import assert_num_queries @@ -109,7 +109,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.STARTED, None, - ubble_fraud_models.UbbleIdentificationStatus.INITIATED, + ubble_serializers.UbbleIdentificationStatus.INITIATED, "identity-check", False, None, @@ -117,7 +117,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.PENDING, None, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSING, + ubble_serializers.UbbleIdentificationStatus.PROCESSING, "honor-statement", True, None, @@ -125,7 +125,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.OK, None, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, "honor-statement", False, None, @@ -133,7 +133,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.KO, fraud_models.FraudReasonCode.AGE_TOO_OLD, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, None, False, { @@ -145,7 +145,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.CANCELED, None, - ubble_fraud_models.UbbleIdentificationStatus.ABORTED, + ubble_serializers.UbbleIdentificationStatus.ABORTED, "identity-check", False, None, @@ -153,7 +153,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.SUSPICIOUS, fraud_models.FraudReasonCode.ID_CHECK_NOT_SUPPORTED, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, "identity-check", # User can retry False, { @@ -322,7 +322,7 @@ def test_underage_not_ok_turned_18(self, client): type=fraud_models.FraudCheckType.UBBLE, status=fraud_models.FraudCheckStatus.PENDING, resultContent=fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSING + status=ubble_serializers.UbbleIdentificationStatus.PROCESSING ), eligibilityType=users_models.EligibilityType.AGE18, ) @@ -361,7 +361,7 @@ def test_underage_not_ok_turned_18(self, client): # ubble now confirms the status ubble_fraud_check.status = fraud_models.FraudCheckStatus.OK ubble_fraud_check.resultContent = fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSED + status=ubble_serializers.UbbleIdentificationStatus.PROCESSED ) pcapi.repository.repository.save(ubble_fraud_check) response = client.get("/native/v1/subscription/next_step") @@ -512,7 +512,7 @@ def test_ubble_restart_workflow(self, client): fraud_factories.ProfileCompletionFraudCheckFactory(user=user) ubble_content = fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.INITIATED + status=ubble_serializers.UbbleIdentificationStatus.INITIATED ) fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_models.FraudCheckType.UBBLE, @@ -890,7 +890,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.STARTED, None, - ubble_fraud_models.UbbleIdentificationStatus.INITIATED, + ubble_serializers.UbbleIdentificationStatus.INITIATED, "identity-check", False, None, @@ -898,7 +898,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.PENDING, None, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSING, + ubble_serializers.UbbleIdentificationStatus.PROCESSING, "honor-statement", True, None, @@ -906,7 +906,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.OK, None, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, "honor-statement", False, None, @@ -914,7 +914,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.KO, fraud_models.FraudReasonCode.AGE_TOO_OLD, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, None, False, { @@ -927,7 +927,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.CANCELED, None, - ubble_fraud_models.UbbleIdentificationStatus.ABORTED, + ubble_serializers.UbbleIdentificationStatus.ABORTED, "identity-check", False, None, @@ -935,7 +935,7 @@ def test_next_subscription_maintenance_page(self, client): ( fraud_models.FraudCheckStatus.SUSPICIOUS, fraud_models.FraudReasonCode.ID_CHECK_NOT_SUPPORTED, - ubble_fraud_models.UbbleIdentificationStatus.PROCESSED, + ubble_serializers.UbbleIdentificationStatus.PROCESSED, "identity-check", # User can retry False, { @@ -1105,7 +1105,7 @@ def test_underage_not_ok_turned_18(self, client): type=fraud_models.FraudCheckType.UBBLE, status=fraud_models.FraudCheckStatus.PENDING, resultContent=fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSING + status=ubble_serializers.UbbleIdentificationStatus.PROCESSING ), eligibilityType=users_models.EligibilityType.AGE18, ) @@ -1144,7 +1144,7 @@ def test_underage_not_ok_turned_18(self, client): # ubble now confirms the status ubble_fraud_check.status = fraud_models.FraudCheckStatus.OK ubble_fraud_check.resultContent = fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.PROCESSED + status=ubble_serializers.UbbleIdentificationStatus.PROCESSED ) pcapi.repository.repository.save(ubble_fraud_check) response = client.get("/native/v2/subscription/stepper") @@ -1297,7 +1297,7 @@ def test_ubble_restart_workflow(self, client): fraud_factories.ProfileCompletionFraudCheckFactory(user=user) ubble_content = fraud_factories.UbbleContentFactory( - status=ubble_fraud_models.UbbleIdentificationStatus.INITIATED + status=ubble_serializers.UbbleIdentificationStatus.INITIATED ) fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_models.FraudCheckType.UBBLE,