From ea138070fda621efd212d373f5ec687f6d5e6ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Fri, 2 Aug 2024 14:32:30 +0200 Subject: [PATCH] Added test to create mailbox without sending an email --- app/mailbox_utils.py | 6 ++++++ tests/test_mailbox_utils.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/mailbox_utils.py b/app/mailbox_utils.py index 43072fdc..54a41932 100644 --- a/app/mailbox_utils.py +++ b/app/mailbox_utils.py @@ -70,8 +70,14 @@ def create_mailbox( if verified: LOG.i(f"User {user} as created a pre-verified mailbox with {email}") return new_mailbox + LOG.i(f"User {user} has created mailbox with {email}") activation = generate_activation_code(new_mailbox, use_digit_code=use_digit_codes) + + if not send_email: + LOG.i(f"Skipping sending validation email for mailbox {new_mailbox}") + return new_mailbox + send_verification_email( user, new_mailbox, diff --git a/tests/test_mailbox_utils.py b/tests/test_mailbox_utils.py index 8e8d97e1..592b626e 100644 --- a/tests/test_mailbox_utils.py +++ b/tests/test_mailbox_utils.py @@ -101,6 +101,21 @@ def test_create_mailbox_with_digits(): assert mail_sent.envelope_to == email +@mail_sender.store_emails_test_decorator +def test_create_mailbox_without_verification_email(): + email = random_email() + mailbox_utils.create_mailbox(user, email, use_digit_codes=True, send_email=False) + mailbox = Mailbox.get_by(email=email) + assert mailbox is not None + assert not mailbox.verified + activation = MailboxActivation.get_by(mailbox_id=mailbox.id) + assert activation is not None + assert activation.tries == 0 + assert len(activation.code) == 6 + + assert 0 == len(mail_sender.get_stored_emails()) + + @mail_sender.store_emails_test_decorator def test_send_verification_email(): email = random_email()