]> git.ozlabs.org Git - patchwork/commitdiff
tests: Use strings from fields module for error tests
authorJeremy Kerr <jk@ozlabs.org>
Sun, 13 Oct 2013 06:49:06 +0000 (14:49 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 13 Oct 2013 06:49:06 +0000 (14:49 +0800)
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>
apps/patchwork/tests/mail_settings.py
apps/patchwork/tests/user.py
apps/patchwork/tests/utils.py

index 24b95d05170f39e391bb6b9824d8ab20544e6bd7..a193c9711375920d08a27fc131e6816f31b2a0ce 100644 (file)
@@ -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)
index 3df9dc7ddaa170d6569337bd52a5f7d5f30b9bc7..d35eacd18226fca3981fe4f48d124d590a1eeb55 100644 (file)
@@ -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/',
index f340f096e9021c6180d4856e345bec055f0e3eb3..d4708aa590fb22c673d617c12f6c040177669f98 100644 (file)
@@ -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