Skip to content

Commit

Permalink
(PC-32146)[API] refactor: rename ubble error file
Browse files Browse the repository at this point in the history
models.py files are reserved for database models
  • Loading branch information
dnguyen1-pass committed Oct 16, 2024
1 parent 7ea6f5f commit 9a2abdd
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions api/src/pcapi/core/fraud/ubble/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pcapi.core.fraud import api as fraud_api
from pcapi.core.fraud import models as 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.subscription.ubble import errors as ubble_errors
from pcapi.core.users import constants as users_constants
from pcapi.core.users import models as users_models
from pcapi.core.users import utils as users_utils
Expand All @@ -26,15 +26,15 @@ def _ubble_readable_score(score: float | None) -> str:


def _ubble_message_from_code(code: fraud_models.FraudReasonCode) -> str:
return ubble_subsciption_models.UBBLE_CODE_ERROR_MAPPING[code].detail_message
return ubble_errors.UBBLE_CODE_ERROR_MAPPING[code].detail_message


def _ubble_result_fraud_item(user: users_models.User, content: fraud_models.UbbleContent) -> fraud_models.FraudItem:
status = None
reason_codes = set(content.reason_codes or [])
detail = f"Ubble score {_ubble_readable_score(content.score)}: {content.comment}"
for reason_code in reason_codes:
ubble_error = ubble_subsciption_models.UBBLE_CODE_ERROR_MAPPING.get(reason_code)
ubble_error = ubble_errors.UBBLE_CODE_ERROR_MAPPING.get(reason_code)
if ubble_error:
detail += " | " + ubble_error.detail_message

Expand Down
6 changes: 3 additions & 3 deletions api/src/pcapi/core/subscription/ubble/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from pcapi.tasks import ubble_tasks
from pcapi.utils import requests as requests_utils

from . import errors
from . import exceptions
from . import messages
from . import models


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -118,8 +118,8 @@ def get_most_relevant_ubble_error(
sorted(
reason_codes,
key=lambda reason_code: (
models.UBBLE_CODE_ERROR_MAPPING[reason_code].priority
if reason_code in models.UBBLE_CODE_ERROR_MAPPING
errors.UBBLE_CODE_ERROR_MAPPING[reason_code].priority
if reason_code in errors.UBBLE_CODE_ERROR_MAPPING
else 0
),
reverse=True,
Expand Down
14 changes: 7 additions & 7 deletions api/src/pcapi/core/subscription/ubble/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pcapi.core.subscription import models as subscription_models

from . import api
from . import models
from . import errors


REDIRECT_TO_IDENTIFICATION = subscription_models.CallToActionMessage(
Expand All @@ -30,10 +30,10 @@ def get_ubble_retryable_message(
reason_codes: list[fraud_models.FraudReasonCode], updated_at: datetime.datetime | None
) -> subscription_models.SubscriptionMessage:
relevant_reason_code = api.get_most_relevant_ubble_error(reason_codes)
if relevant_reason_code in models.UBBLE_CODE_ERROR_MAPPING:
relevant_error = models.UBBLE_CODE_ERROR_MAPPING[relevant_reason_code]
if relevant_reason_code in errors.UBBLE_CODE_ERROR_MAPPING:
relevant_error = errors.UBBLE_CODE_ERROR_MAPPING[relevant_reason_code]
else:
relevant_error = models.UBBLE_DEFAULT
relevant_error = errors.UBBLE_DEFAULT

return subscription_models.SubscriptionMessage(
user_message=relevant_error.retryable_user_message,
Expand All @@ -49,10 +49,10 @@ def get_ubble_not_retryable_message(
fraud_check: fraud_models.BeneficiaryFraudCheck,
) -> subscription_models.SubscriptionMessage:
relevant_reason_code = api.get_most_relevant_ubble_error(fraud_check.reasonCodes or [])
if relevant_reason_code in models.UBBLE_CODE_ERROR_MAPPING:
relevant_error = models.UBBLE_CODE_ERROR_MAPPING[relevant_reason_code]
if relevant_reason_code in errors.UBBLE_CODE_ERROR_MAPPING:
relevant_error = errors.UBBLE_CODE_ERROR_MAPPING[relevant_reason_code]
else:
relevant_error = models.UBBLE_DEFAULT
relevant_error = errors.UBBLE_DEFAULT

user_message = relevant_error.not_retryable_user_message

Expand Down
4 changes: 2 additions & 2 deletions api/tests/core/fraud/ubble/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pcapi.core.fraud import models as fraud_models
from pcapi.core.fraud.ubble.api import _ubble_readable_score
from pcapi.core.fraud.ubble.api import _ubble_result_fraud_item
from pcapi.core.subscription.ubble import models as ubble_models
from pcapi.core.subscription.ubble import errors as ubble_errors
from pcapi.core.users import factories as user_factories

from tests.core.subscription.test_factories import UbbleIdentificationResponseFactory
Expand All @@ -28,7 +28,7 @@ def test_ubble_reason_code_details(self, ubble_mocker):
details = set(fraud_item.detail.split(" | "))

expected_details = {
ubble_models.UBBLE_CODE_ERROR_MAPPING.get(reason_code).detail_message for reason_code in reason_codes
ubble_errors.UBBLE_CODE_ERROR_MAPPING.get(reason_code).detail_message for reason_code in reason_codes
}
expected_details.add(f"Ubble score {_ubble_readable_score(content.score)}: {content.comment}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pcapi.core.mails.transactional.sendinblue_template_ids as sendinblue_template
from pcapi.core.mails.transactional.users.ubble.reminder_emails import _find_users_to_remind
from pcapi.core.mails.transactional.users.ubble.reminder_emails import send_reminders
from pcapi.core.subscription.ubble import models as ubble_models
from pcapi.core.subscription.ubble import errors as ubble_errors
from pcapi.core.testing import override_settings
import pcapi.core.users.factories as users_factories
import pcapi.core.users.models as users_models
Expand Down Expand Up @@ -334,8 +334,8 @@ def should_send_reminder_for_most_relevant_error_to_user_for_long_action(self, r
[
reason_code
for reason_code in ubble_constants.REASON_CODES_FOR_QUICK_ACTION_REMINDERS
if ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].priority
< ubble_models.UBBLE_CODE_ERROR_MAPPING[fraud_models.FraudReasonCode.DUPLICATE_USER].priority
if ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].priority
< ubble_errors.UBBLE_CODE_ERROR_MAPPING[fraud_models.FraudReasonCode.DUPLICATE_USER].priority
],
)
def should_not_send_email_if_most_relevant_is_not_retryable(self, reason_code):
Expand Down
10 changes: 5 additions & 5 deletions api/tests/core/subscription/ubble/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@ def test_retryable(self, reason_code):
assert ubble_subscription_api.get_ubble_subscription_message(
fraud_check
) == subscription_models.SubscriptionMessage(
user_message=ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message,
message_summary=ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_message_summary,
action_hint=ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_action_hint,
user_message=ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message,
message_summary=ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_message_summary,
action_hint=ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_action_hint,
call_to_action=subscription_models.CallToActionMessage(
title="Réessayer la vérification de mon identité",
link="passculture://verification-identite",
Expand Down Expand Up @@ -927,7 +927,7 @@ def test_not_retryable_go_dms(self):
assert ubble_subscription_api.get_ubble_subscription_message(
fraud_check
) == subscription_models.SubscriptionMessage(
user_message=ubble_models.UBBLE_DEFAULT.not_retryable_user_message,
user_message=ubble_errors.UBBLE_DEFAULT.not_retryable_user_message,
call_to_action=subscription_models.CallToActionMessage(
title="Accéder au site Démarches-Simplifiées",
link="passculture://verification-identite/demarches-simplifiees",
Expand Down Expand Up @@ -977,7 +977,7 @@ def test_not_retryable_third_time_go_dms(self, reason_code):
assert ubble_subscription_api.get_ubble_subscription_message(
fraud_check
) == subscription_models.SubscriptionMessage(
user_message=ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].not_retryable_user_message,
user_message=ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].not_retryable_user_message,
call_to_action=subscription_models.CallToActionMessage(
title="Accéder au site Démarches-Simplifiées",
link="passculture://verification-identite/demarches-simplifiees",
Expand Down
22 changes: 11 additions & 11 deletions api/tests/routes/external/user_subscription_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pcapi.core.subscription.dms import api as dms_subscription_api
from pcapi.core.subscription.dms import dms_internal_mailing
from pcapi.core.subscription.ubble import api as ubble_subscription_api
from pcapi.core.subscription.ubble import models as ubble_models
from pcapi.core.subscription.ubble import errors as ubble_errors
from pcapi.core.users import factories as users_factories
from pcapi.core.users import models as users_models
from pcapi.core.users.api import get_domains_credit
Expand Down Expand Up @@ -1894,7 +1894,7 @@ def test_unknown_reason_code_is_retryable(self, client, ubble_mocker):
db.session.refresh(ubble_fraud_check)

reason_code = fraud_models.FraudReasonCode.ID_CHECK_BLOCKED_OTHER
ubble_error = ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code]
ubble_error = ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code]

assert ubble_fraud_check.status == fraud_models.FraudCheckStatus.SUSPICIOUS
assert reason_code in ubble_fraud_check.reasonCodes
Expand All @@ -1920,7 +1920,7 @@ def test_id_is_unprocessable_only_if_no_clue(self, client, ubble_mocker):
db.session.refresh(ubble_fraud_check)

reason_code = fraud_models.FraudReasonCode.ID_CHECK_UNPROCESSABLE
ubble_error = ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code]
ubble_error = ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code]

assert ubble_fraud_check.status == fraud_models.FraudCheckStatus.SUSPICIOUS
assert reason_code in ubble_fraud_check.reasonCodes
Expand Down Expand Up @@ -1981,7 +1981,7 @@ def test_blocked_other_and_ko_if_score_invalid_and_the_rest_is_valid(self, clien
db.session.refresh(ubble_fraud_check)

reason_code = fraud_models.FraudReasonCode.ID_CHECK_BLOCKED_OTHER
ubble_error = ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code]
ubble_error = ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code]

assert ubble_fraud_check.status == fraud_models.FraudCheckStatus.KO
assert reason_code in ubble_fraud_check.reasonCodes
Expand Down Expand Up @@ -2058,7 +2058,7 @@ def test_decision_document_not_supported(self, client, ubble_mocker, ref_data_ch
assert reason_code in ubble_fraud_check.reasonCodes

message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert message.user_message == ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.user_message == ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.call_to_action.link == "passculture://verification-identite"
assert message.call_to_action.icon == subscription_models.CallToActionIcon.RETRY
assert message.call_to_action.title == "Réessayer la vérification de mon identité"
Expand Down Expand Up @@ -2136,7 +2136,7 @@ def test_decision_document_expired(self, client, ubble_mocker, ref_data_check_sc
message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert (
message.user_message
== ubble_models.UBBLE_CODE_ERROR_MAPPING[
== ubble_errors.UBBLE_CODE_ERROR_MAPPING[
fraud_models.FraudReasonCode.ID_CHECK_EXPIRED
].retryable_user_message
)
Expand Down Expand Up @@ -2209,7 +2209,7 @@ def test_decision_document_not_authentic(self, client, ubble_mocker):
assert reason_code in ubble_fraud_check.reasonCodes

message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert message.user_message == ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.user_message == ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.call_to_action.link == "passculture://verification-identite"
assert message.call_to_action.icon == subscription_models.CallToActionIcon.RETRY
assert message.call_to_action.title == "Réessayer la vérification de mon identité"
Expand Down Expand Up @@ -2244,7 +2244,7 @@ def test_decision_suspicious_codes(self, client, ubble_mocker, code_number):
assert reason_code in ubble_fraud_check.reasonCodes

message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert message.user_message == ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.user_message == ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.call_to_action.link == "passculture://verification-identite"
assert message.call_to_action.icon == subscription_models.CallToActionIcon.RETRY
assert message.call_to_action.title == "Réessayer la vérification de mon identité"
Expand Down Expand Up @@ -2313,7 +2313,7 @@ def test_decision_document_not_authentic_no_retry_left(self, client, ubble_mocke
assert reason_code in ubble_fraud_check.reasonCodes

message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert message.user_message == ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].not_retryable_user_message
assert message.user_message == ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].not_retryable_user_message
assert message.call_to_action.link == "passculture://verification-identite/demarches-simplifiees"
assert message.call_to_action.icon == subscription_models.CallToActionIcon.EXTERNAL
assert message.call_to_action.title == "Accéder au site Démarches-Simplifiées"
Expand Down Expand Up @@ -2389,7 +2389,7 @@ def test_decision_invalid_for_another_reason(
assert reason_code in ubble_fraud_check.reasonCodes

message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert message.user_message == ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.user_message == ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.call_to_action.link == "passculture://verification-identite"

assert len(mails_testing.outbox) == 1
Expand Down Expand Up @@ -2480,7 +2480,7 @@ def test_decision_unprocessable(self, client, ubble_mocker, ref_data_check_score
assert reason_code in ubble_fraud_check.reasonCodes

message = ubble_subscription_api.get_ubble_subscription_message(ubble_fraud_check)
assert message.user_message == ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.user_message == ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_user_message
assert message.call_to_action.link == "passculture://verification-identite"
assert message.call_to_action.icon == subscription_models.CallToActionIcon.RETRY
assert message.call_to_action.title == "Réessayer la vérification de mon identité"
Expand Down
4 changes: 2 additions & 2 deletions api/tests/routes/native/v1/subscription_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pcapi.core.fraud import factories as fraud_factories
from pcapi.core.fraud import models as fraud_models
from pcapi.core.subscription.models import SubscriptionStepCompletionState
import pcapi.core.subscription.ubble.models as ubble_models
from pcapi.core.subscription.ubble import errors as ubble_errors
from pcapi.core.testing import assert_num_queries
from pcapi.core.testing import override_features
from pcapi.core.users import factories as users_factories
Expand Down Expand Up @@ -744,7 +744,7 @@ def should_have_subtitle_for_id_check_when_ubble_retryable(self, client, reason_
{
"name": "identity-check",
"title": "Identification",
"subtitle": ubble_models.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_action_hint,
"subtitle": ubble_errors.UBBLE_CODE_ERROR_MAPPING[reason_code].retryable_action_hint,
"completionState": SubscriptionStepCompletionState.RETRY.value,
},
self.get_step("honor_statement_step", SubscriptionStepCompletionState.DISABLED.value),
Expand Down

0 comments on commit 9a2abdd

Please sign in to comment.