def test_on_identity_fraud_check_result_retry(self): user = users_factories.UserFactory() content = fraud_factories.JouveContentFactory( birthLocationCtrl="OK", bodyBirthDateCtrl="OK", bodyBirthDateLevel=100, bodyFirstnameCtrl="OK", bodyFirstnameLevel=100, bodyNameLevel=100, bodyNameCtrl="OK", bodyPieceNumber="wrong-id-piece-number", bodyPieceNumberCtrl= "KO", # ensure we correctly update this field later in the test bodyPieceNumberLevel=100, creatorCtrl="OK", initialSizeCtrl="OK", ) fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_models.FraudCheckType.JOUVE, user=user, resultContent=content) fraud_check = fraud_api.admin_update_identity_fraud_check_result( user, "123123123123") fraud_result = fraud_factories.BeneficiaryFraudResultFactory( user=user, status=fraud_models.FraudStatus.SUSPICIOUS, reason="Suspiscious case") fraud_api.on_identity_fraud_check_result(user, fraud_check) fraud_result = fraud_models.BeneficiaryFraudResult.query.get( fraud_result.id) assert fraud_result.status == fraud_models.FraudStatus.OK
def test_previously_validated_user_with_retry(self, fraud_check_type): # The user is already beneficiary, and has already done all the checks but # for any circumstances, someone is trying to redo the validation user = users_factories.BeneficiaryGrant18Factory() fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_check_type, user=user) fraud_result = fraud_factories.BeneficiaryFraudResultFactory( user=user, status=fraud_models.FraudStatus.OK) fraud_api.on_identity_fraud_check_result(user, fraud_check) assert fraud_result.status == fraud_models.FraudStatus.OK
def test_user_validation_has_email_validated(self, fraud_check_type): user = users_factories.UserFactory(isEmailValidated=False) fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_check_type, user=user) fraud_result = fraud_api.on_identity_fraud_check_result( user, fraud_check) assert "L'email de l'utilisateur n'est pas validé" in fraud_result.reason assert fraud_result.status == fraud_models.FraudStatus.KO
def test_user_validation_is_beneficiary(self, fraud_check_type): user = users_factories.BeneficiaryGrant18Factory() fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_check_type, user=user) fraud_result = fraud_api.on_identity_fraud_check_result( user, fraud_check) assert ( "L’utilisateur est déjà bénéfiaire, avec un portefeuille non expiré. Il ne peut pas prétendre au pass culture 18 ans" in fraud_result.reason) assert fraud_result.status == fraud_models.FraudStatus.KO
def test_underage_user_validation_has_email_validated(self, age): user = users_factories.UserFactory(isEmailValidated=False) fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_models.FraudCheckType.EDUCONNECT, user=user, resultContent=fraud_factories.EduconnectContentFactory(age=age), ) fraud_result = fraud_api.on_identity_fraud_check_result( user, fraud_check) assert "L'email de l'utilisateur n'est pas validé" in fraud_result.reason assert fraud_result.status == fraud_models.FraudStatus.KO
def test_user_validation_has_phone_validated(self, phone_status, fraud_check_type): user = users_factories.UserFactory( isEmailValidated=True, phoneValidationStatus=phone_status, ) fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_check_type, user=user) fraud_result = fraud_api.on_identity_fraud_check_result( user, fraud_check) assert "Le n° de téléphone de l'utilisateur n'est pas validé" in fraud_result.reason assert fraud_result.status == fraud_models.FraudStatus.KO
def test_underage_user_validation_is_beneficiary(self, age): user = users_factories.UnderageBeneficiaryFactory() fraud_check = fraud_factories.BeneficiaryFraudCheckFactory( type=fraud_models.FraudCheckType.EDUCONNECT, user=user, resultContent=fraud_factories.EduconnectContentFactory(age=age), ) fraud_result = fraud_api.on_identity_fraud_check_result( user, fraud_check) assert ( "L’utilisateur est déjà bénéfiaire, avec un portefeuille non expiré. Il ne peut pas prétendre au pass culture 15-17 ans" in fraud_result.reason) assert fraud_result.status == fraud_models.FraudStatus.KO
def update_beneficiary_id_piece_number(self, user_id: int) -> Response: if not self.check_super_admins() and not flask_login.current_user.has_jouve_role: flask.flash("Vous n'avez pas les droits suffisant pour activer ce bénéficiaire", "error") return flask.redirect(flask.url_for(".details_view", id=user_id)) form = IDPieceNumberForm(flask.request.form) if not form.validate(): errors = "<br>".join(f"{field}: {error[0]}" for field, error in form.errors.items()) flask.flash(Markup(f"Erreurs lors de la validation du formulaire: <br> {errors}"), "error") return flask.redirect(flask.url_for(".details_view", id=user_id)) user = users_models.User.query.get(user_id) if not user: flask.flash("Cet utilisateur n'existe pas", "error") return flask.redirect(flask.url_for(".index_view")) # TODO: Handle switch from underage_beneficiary to beneficiary if user.is_beneficiary: flask.flash(f"L'utilisateur {user.id} {user.firstName} {user.lastName} est déjà bénéficiaire") return flask.redirect(flask.url_for(".details_view", id=user_id)) fraud_check = fraud_api.admin_update_identity_fraud_check_result(user, form.data["id_piece_number"]) if not fraud_check: flask.flash("Aucune vérification de fraude disponible", "error") return flask.redirect(flask.url_for(".details_view", id=user_id)) db.session.refresh(user) fraud_result = fraud_api.on_identity_fraud_check_result(user, fraud_check) if fraud_result.status == fraud_models.FraudStatus.OK: # todo : cleanup to use fraud validation journey v2 if fraud_check.type == fraud_models.FraudCheckType.JOUVE: pre_subscription = jouve_backend.get_subscription_from_content(fraud_check.source_data()) elif fraud_check.type == fraud_models.FraudCheckType.DMS: pre_subscription = subscription_models.BeneficiaryPreSubscription.from_dms_source( fraud_check.source_data() ) beneficiary_repository.BeneficiarySQLRepository.save(pre_subscription, user) flask.flash(f"N° de pièce d'identitée modifiée sur le bénéficiaire {user.firstName} {user.lastName}") return flask.redirect(flask.url_for(".details_view", id=user_id))