Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
(PC-9650) use default email data handler
Browse files Browse the repository at this point in the history
Before: if error code is unknwon -> error
After: if error code is unknwon -> use default handler
  • Loading branch information
jeremieb-pass committed Jun 21, 2021
1 parent 6e971bf commit e60ef6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/pcapi/emails/user_document_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ def build_data_for_document_verification_error(code: str) -> dict:
"invalid-age": _build_invalid_age_data,
}

if code not in error_codes_switch:
# cast to avoid an error: in case code turns out not to be a str
raise DocumentValidationUnknownError(str(code))

handler = error_codes_switch[code]
handler = error_codes_switch.get(code, _build_unread_document_data)
return handler()


Expand Down
21 changes: 20 additions & 1 deletion tests/core/users/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,33 @@ def test_email_sent_when_document_is_invalid(
):
# Given
mocked_get_identity_informations.return_value = ("py@test.com", b"")
mocked_ask_for_identity.return_value = (False, "unread-document")
mocked_ask_for_identity.return_value = (False, "invalid-document-date")

users_api.verify_identity_document_informations("some_path")

assert len(mails_testing.outbox) == 1
sent_data = mails_testing.outbox[0].sent_data

assert sent_data["Vars"]["url"] == settings.DMS_USER_URL
assert sent_data["MJ-TemplateID"] == 2958563

@patch("pcapi.core.users.api.delete_object")
@patch("pcapi.core.users.api.ask_for_identity_document_verification")
@patch("pcapi.core.users.api._get_identity_document_informations")
def test_email_sent_with_default_template(
self, mocked_get_identity_informations, mocked_ask_for_identity, mocked_delete_object, app
):
# Given
mocked_get_identity_informations.return_value = ("py@test.com", b"")
mocked_ask_for_identity.return_value = (False, "unknown-error-code")

users_api.verify_identity_document_informations("some_path")

assert len(mails_testing.outbox) == 1
sent_data = mails_testing.outbox[0].sent_data

assert sent_data["Vars"]["url"] == settings.DMS_USER_URL
assert sent_data["MJ-TemplateID"] == 2958557 # default email template used

@patch("pcapi.core.users.api.delete_object")
@patch("pcapi.core.users.api.ask_for_identity_document_verification")
Expand Down

0 comments on commit e60ef6b

Please sign in to comment.