emails/validators: ugettext_lazy uses named arguments, validation error wording (#32426)

This commit is contained in:
Christophe Siraut 2019-04-17 17:16:28 +02:00
parent 6bc71fc1b4
commit 133bd51350
2 changed files with 6 additions and 6 deletions

View File

@ -34,11 +34,11 @@ def validate_email_address(value):
try:
smtp.connect(mx_server)
except socket.error as e:
raise ValidationError(_('Error while connecting to %s: %s') % (mx_server, str(e)))
raise ValidationError(_('Error while connecting to %(server)s: %(msg)s') % {'server': mx_server, 'msg': str(e)})
status, msg = smtp.helo()
if status != 250:
smtp.quit()
raise ValidationError(_('Error while connecting to %s: %s') % (mx_server, msg))
raise ValidationError(_('Error while connecting to %(server)s: %(msg)s') % {'server': mx_server, 'msg': msg})
smtp.mail('')
status, msg = smtp.rcpt(value)
if status == 250:
@ -61,4 +61,4 @@ def validate_email_spf(value, strict=False):
for allowed_record in allowed_records:
if allowed_record in spf_record:
return
raise ValidationError(_('No matching SPF record for %s') % email_domain)
raise ValidationError(_('No suitable SPF record found for %s') % email_domain)

View File

@ -83,7 +83,7 @@ def test_validate_email_address_socket_error(dns_resolver, monkeypatch):
monkeypatch.setattr('smtplib.SMTP.connect', socket_error)
with pytest.raises(ValidationError) as e:
validate_email_address('john.doe@example.com')
assert 'Error' in str(e.value)
assert 'Error while connecting' in str(e.value)
def test_invalid_address(client, admin_user):
@ -119,7 +119,7 @@ def test_invalid_spf(client, admin_user, dns_resolver, smtp_server, settings):
client.post('/login/', {'username': 'admin', 'password': 'password'})
response = client.post('/emails/', {'default_from_email': 'john.doe@example-invalid-spf.com'})
assert response.status_code == 200
assert 'No matching SPF record' in response.content
assert 'No suitable SPF record found' in response.content
def test_strict_nospf(client, admin_user, dns_resolver, smtp_server, monkeypatch):
@ -127,7 +127,7 @@ def test_strict_nospf(client, admin_user, dns_resolver, smtp_server, monkeypatch
client.post('/login/', {'username': 'admin', 'password': 'password'})
response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True)
assert response.status_code == 200
assert 'No matching SPF record' in response.content
assert 'No suitable SPF record found' in response.content
def test_valid_spf(client, admin_user, dns_resolver, smtp_server, settings):