diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-10-13 14:49:06 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-10-13 14:49:06 +0800 |
commit | 6ea54166123c6f839af02bd8efb16b33e78acd3c (patch) | |
tree | 921f2a935e48670bb6602202ecbf935cba151f2e | |
parent | a37842591183a2302f580ee4973a19e35661baf0 (diff) | |
download | patchwork-6ea54166123c6f839af02bd8efb16b33e78acd3c.tar patchwork-6ea54166123c6f839af02bd8efb16b33e78acd3c.tar.gz |
tests: Use strings from fields module for error tests
Rather than hard-coding expected error messages, grab the values from
the fields module, and expose through the test utils.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r-- | apps/patchwork/tests/mail_settings.py | 11 | ||||
-rw-r--r-- | apps/patchwork/tests/user.py | 4 | ||||
-rw-r--r-- | apps/patchwork/tests/utils.py | 5 |
3 files changed, 11 insertions, 9 deletions
diff --git a/apps/patchwork/tests/mail_settings.py b/apps/patchwork/tests/mail_settings.py index 24b95d0..a193c97 100644 --- a/apps/patchwork/tests/mail_settings.py +++ b/apps/patchwork/tests/mail_settings.py @@ -25,7 +25,7 @@ from django.core import mail from django.core.urlresolvers import reverse from django.contrib.auth.models import User from patchwork.models import EmailOptout, EmailConfirmation, Person -from patchwork.tests.utils import create_user +from patchwork.tests.utils import create_user, error_strings class MailSettingsTest(TestCase): view = 'patchwork.views.mail.settings' @@ -54,8 +54,7 @@ class MailSettingsTest(TestCase): response = self.client.post(self.url, {'email': 'foo'}) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, 'patchwork/mail-form.html') - self.assertFormError(response, 'form', 'email', - 'Enter a valid e-mail address.') + self.assertFormError(response, 'form', 'email', error_strings['email']) def testMailSettingsPOSTOptedIn(self): email = u'foo@example.com' @@ -119,8 +118,7 @@ class OptoutRequestTest(TestCase): def testOptoutRequestInvalidPOSTNonEmail(self): response = self.client.post(self.url, {'email': 'foo'}) self.assertEquals(response.status_code, 200) - self.assertFormError(response, 'form', 'email', - 'Enter a valid e-mail address.') + self.assertFormError(response, 'form', 'email', error_strings['email']) self.assertTrue(response.context['error']) self.assertTrue('email_sent' not in response.context) self.assertEquals(len(mail.outbox), 0) @@ -202,8 +200,7 @@ class OptinRequestTest(TestCase): def testOptoutRequestInvalidPOSTNonEmail(self): response = self.client.post(self.url, {'email': 'foo'}) self.assertEquals(response.status_code, 200) - self.assertFormError(response, 'form', 'email', - 'Enter a valid e-mail address.') + self.assertFormError(response, 'form', 'email', error_strings['email']) self.assertTrue(response.context['error']) self.assertTrue('email_sent' not in response.context) self.assertEquals(len(mail.outbox), 0) diff --git a/apps/patchwork/tests/user.py b/apps/patchwork/tests/user.py index 3df9dc7..d35eacd 100644 --- a/apps/patchwork/tests/user.py +++ b/apps/patchwork/tests/user.py @@ -25,7 +25,7 @@ from django.core.urlresolvers import reverse from django.conf import settings from django.contrib.auth.models import User from patchwork.models import EmailConfirmation, Person, Bundle -from patchwork.tests.utils import defaults +from patchwork.tests.utils import defaults, error_strings def _confirmation_url(conf): return reverse('patchwork.views.confirm', kwargs = {'key': conf.key}) @@ -65,7 +65,7 @@ class UserPersonRequestTest(TestCase): self.assertEquals(response.status_code, 200) self.assertTrue(response.context['linkform']) self.assertFormError(response, 'linkform', 'email', - 'Enter a valid e-mail address.') + error_strings['email']) def testUserPersonRequestValid(self): response = self.client.post('/user/link/', diff --git a/apps/patchwork/tests/utils.py b/apps/patchwork/tests/utils.py index f340f09..d4708aa 100644 --- a/apps/patchwork/tests/utils.py +++ b/apps/patchwork/tests/utils.py @@ -21,6 +21,7 @@ import os import codecs from patchwork.models import Project, Person from django.contrib.auth.models import User +from django.forms.fields import EmailField from email import message_from_file try: @@ -56,6 +57,10 @@ class defaults(object): +a """ +error_strings = { + 'email': EmailField.default_error_messages['invalid'], +} + _user_idx = 1 def create_user(): global _user_idx |