Improve logging for suppressed email confirmation task + fix relative URL in verification email (#21843)
* Improve logging for suppressed email confirmation task * Add site url to verify email template * Use absolutify to generate confirmation code
This commit is contained in:
Родитель
66c2417b10
Коммит
d655f89f4d
|
@ -15,6 +15,7 @@ from requests.exceptions import HTTPError, Timeout
|
|||
import olympia.core.logger
|
||||
from olympia.amo.celery import task
|
||||
from olympia.amo.decorators import set_modified_on, use_primary_db
|
||||
from olympia.amo.templatetags.jinja_helpers import absolutify
|
||||
from olympia.amo.utils import (
|
||||
SafeStorage,
|
||||
backup_storage_enabled,
|
||||
|
@ -189,7 +190,7 @@ def send_suppressed_email_confirmation(suppressed_email_verification_id):
|
|||
|
||||
verification.status = SuppressedEmailVerification.STATUS_CHOICES.Pending
|
||||
|
||||
confirmation_link = (
|
||||
confirmation_link = absolutify(
|
||||
reverse('devhub.email_verification')
|
||||
+ '?code='
|
||||
+ str(verification.confirmation_code)
|
||||
|
@ -280,6 +281,13 @@ def check_suppressed_email_confirmation(suppressed_email_verification_id, page_s
|
|||
|
||||
if is_first_page:
|
||||
total = json['total']
|
||||
|
||||
if total == 0:
|
||||
raise Retry(
|
||||
f'No emails found for email {email}.'
|
||||
'retrying as email could not be queued yet'
|
||||
)
|
||||
|
||||
is_first_page = False
|
||||
|
||||
data = json['data']
|
||||
|
@ -297,12 +305,14 @@ def check_suppressed_email_confirmation(suppressed_email_verification_id, page_s
|
|||
f'expected {", ".join(options)}'
|
||||
)
|
||||
|
||||
task_log.info(f'Found matching email {item}')
|
||||
|
||||
verification.update(
|
||||
status=SuppressedEmailVerification.STATUS_CHOICES[item['status']]
|
||||
)
|
||||
return
|
||||
|
||||
raise Retry(
|
||||
f'failed to find {code_snippet} in {total} emails.'
|
||||
f'failed to find email for code: {code_snippet} in {total} emails.'
|
||||
'retrying as email could not be queued yet'
|
||||
)
|
||||
|
|
|
@ -18,6 +18,7 @@ from freezegun import freeze_time
|
|||
from PIL import Image
|
||||
from requests.exceptions import Timeout
|
||||
|
||||
from olympia.amo.templatetags.jinja_helpers import absolutify
|
||||
from olympia.amo.tests import TestCase, user_factory
|
||||
from olympia.amo.tests.test_helpers import get_image_path
|
||||
from olympia.amo.utils import SafeStorage
|
||||
|
@ -392,7 +393,7 @@ class TestSendSuppressedEmailConfirmation(TestCase):
|
|||
|
||||
assert len(mail.outbox) == 1
|
||||
|
||||
expected_confirmation_link = (
|
||||
expected_confirmation_link = absolutify(
|
||||
reverse('devhub.email_verification')
|
||||
+ '?code='
|
||||
+ str(verification.confirmation_code)
|
||||
|
@ -477,6 +478,36 @@ class TestCheckSuppressedEmailConfirmation(TestCase):
|
|||
with pytest.raises(Retry):
|
||||
check_suppressed_email_confirmation.apply([verification.id])
|
||||
|
||||
def test_socket_labs_returns_empty(self):
|
||||
verification = SuppressedEmailVerification.objects.create(
|
||||
suppressed_email=SuppressedEmail.objects.create(
|
||||
email=self.user_profile.email
|
||||
),
|
||||
)
|
||||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
(
|
||||
f'{settings.SOCKET_LABS_HOST}servers/{settings.SOCKET_LABS_SERVER_ID}/'
|
||||
f'reports/recipient-search/'
|
||||
),
|
||||
status=200,
|
||||
body=json.dumps(
|
||||
{
|
||||
'data': [],
|
||||
'total': 0,
|
||||
}
|
||||
),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
with pytest.raises(Retry) as error_info:
|
||||
check_suppressed_email_confirmation.apply([verification.id])
|
||||
|
||||
assert f'No emails found for email {self.user_profile.email}' in str(
|
||||
error_info.value
|
||||
)
|
||||
|
||||
def test_auth_header_present(self):
|
||||
verification = SuppressedEmailVerification.objects.create(
|
||||
suppressed_email=SuppressedEmail.objects.create(
|
||||
|
@ -730,5 +761,7 @@ class TestCheckSuppressedEmailConfirmation(TestCase):
|
|||
content_type='application/json',
|
||||
)
|
||||
|
||||
with pytest.raises(Retry):
|
||||
with pytest.raises(Retry) as error_info:
|
||||
check_suppressed_email_confirmation.apply([verification.id, response_size])
|
||||
|
||||
assert 'failed to find email for code: ' in str(error_info.value)
|
||||
|
|
Загрузка…
Ссылка в новой задаче