From 133bd51350523255c3e66c6c966d99c671ec2830 Mon Sep 17 00:00:00 2001 From: Christophe Siraut Date: Wed, 17 Apr 2019 17:16:28 +0200 Subject: [PATCH] emails/validators: ugettext_lazy uses named arguments, validation error wording (#32426) --- hobo/emails/validators.py | 6 +++--- tests/test_emails.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hobo/emails/validators.py b/hobo/emails/validators.py index c2513f8..d6b4bd0 100644 --- a/hobo/emails/validators.py +++ b/hobo/emails/validators.py @@ -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) diff --git a/tests/test_emails.py b/tests/test_emails.py index 782d6e7..c713d8d 100644 --- a/tests/test_emails.py +++ b/tests/test_emails.py @@ -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):