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>
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from patchwork.models import EmailOptout, EmailConfirmation, Person
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'
class MailSettingsTest(TestCase):
view = 'patchwork.views.mail.settings'
response = self.client.post(self.url, {'email': 'foo'})
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-form.html')
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'
def testMailSettingsPOSTOptedIn(self):
email = u'foo@example.com'
def testOptoutRequestInvalidPOSTNonEmail(self):
response = self.client.post(self.url, {'email': 'foo'})
self.assertEquals(response.status_code, 200)
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)
self.assertTrue(response.context['error'])
self.assertTrue('email_sent' not in response.context)
self.assertEquals(len(mail.outbox), 0)
def testOptoutRequestInvalidPOSTNonEmail(self):
response = self.client.post(self.url, {'email': 'foo'})
self.assertEquals(response.status_code, 200)
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)
self.assertTrue(response.context['error'])
self.assertTrue('email_sent' not in response.context)
self.assertEquals(len(mail.outbox), 0)
from django.conf import settings
from django.contrib.auth.models import User
from patchwork.models import EmailConfirmation, Person, Bundle
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})
def _confirmation_url(conf):
return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
self.assertEquals(response.status_code, 200)
self.assertTrue(response.context['linkform'])
self.assertFormError(response, 'linkform', 'email',
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/',
def testUserPersonRequestValid(self):
response = self.client.post('/user/link/',
import codecs
from patchwork.models import Project, Person
from django.contrib.auth.models import User
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:
from email import message_from_file
try:
+error_strings = {
+ 'email': EmailField.default_error_messages['invalid'],
+}
+
_user_idx = 1
def create_user():
global _user_idx
_user_idx = 1
def create_user():
global _user_idx