mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-14 20:18:02 +00:00
Fix tests of forms that do no longer redirect, but provide form errors
This commit is contained in:
@@ -160,10 +160,12 @@ class AddOpenIDForm(forms.Form):
|
|||||||
'''
|
'''
|
||||||
if ConfirmedOpenId.objects.filter(
|
if ConfirmedOpenId.objects.filter(
|
||||||
openid=self.cleaned_data['openid']).exists():
|
openid=self.cleaned_data['openid']).exists():
|
||||||
|
self.add_error('openid', _('OpenID already added and confirmed!'))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if UnconfirmedOpenId.objects.filter(
|
if UnconfirmedOpenId.objects.filter(
|
||||||
openid=self.cleaned_data['openid']).exists():
|
openid=self.cleaned_data['openid']).exists():
|
||||||
|
self.add_error('openid', _('OpenID already added, but not confirmed yet!'))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
unconfirmed = UnconfirmedOpenId()
|
unconfirmed = UnconfirmedOpenId()
|
||||||
|
|||||||
@@ -407,20 +407,10 @@ class Tester(TestCase):
|
|||||||
reverse('add_email'), {
|
reverse('add_email'), {
|
||||||
'email': '%i.%s' % (i, self.email),
|
'email': '%i.%s' % (i, self.email),
|
||||||
},
|
},
|
||||||
|
follow=True,
|
||||||
) # Create test addresses + 1 too much
|
) # Create test addresses + 1 too much
|
||||||
response = self.client.get(reverse('profile'))
|
self.assertFormError(response, 'form', None,
|
||||||
self.assertEqual(
|
'Too many unconfirmed mail addresses!')
|
||||||
response.status_code,
|
|
||||||
200,
|
|
||||||
'why does profile page not work!?')
|
|
||||||
# Take care, since we do did not fetch any pages after adding mail
|
|
||||||
# addresses, the messages still sit there waiting to be fetched!!
|
|
||||||
# Therefore the message index we need to use is max_num_unconfirmed!
|
|
||||||
self.assertEqual(
|
|
||||||
str(list(response.context[0]['messages'])[max_num_unconfirmed]),
|
|
||||||
'Address not added',
|
|
||||||
'Too many unconfirmed address, should return a\
|
|
||||||
"not added" messsage!')
|
|
||||||
|
|
||||||
def test_add_mail_address_twice(self):
|
def test_add_mail_address_twice(self):
|
||||||
'''
|
'''
|
||||||
@@ -436,18 +426,10 @@ class Tester(TestCase):
|
|||||||
reverse('add_email'), {
|
reverse('add_email'), {
|
||||||
'email': self.email,
|
'email': self.email,
|
||||||
},
|
},
|
||||||
) # Request adding test address twice
|
follow=True
|
||||||
response = self.client.get(reverse('profile'))
|
)
|
||||||
self.assertEqual(
|
self.assertFormError(response, 'form', 'email',
|
||||||
response.status_code,
|
'Address already added, currently unconfirmed')
|
||||||
200,
|
|
||||||
'why does profile page not work!?')
|
|
||||||
# Take care, since we do did not fetch any pages after adding mail
|
|
||||||
# addresses, the messages still sit there waiting to be fetched!!
|
|
||||||
self.assertEqual(
|
|
||||||
str(list(response.context[0]['messages'])[1]),
|
|
||||||
'Address not added',
|
|
||||||
'Adding address twice must lead to "Address not added" message!')
|
|
||||||
|
|
||||||
def test_add_already_confirmed_email(self):
|
def test_add_already_confirmed_email(self):
|
||||||
'''
|
'''
|
||||||
@@ -461,14 +443,10 @@ class Tester(TestCase):
|
|||||||
reverse('add_email'), {
|
reverse('add_email'), {
|
||||||
'email': self.email,
|
'email': self.email,
|
||||||
},
|
},
|
||||||
) # Request adding test address a second time
|
follow=True,
|
||||||
response = self.client.get(reverse('profile'))
|
)
|
||||||
self.assertEqual(response.status_code, 200, 'why does profile page not\
|
self.assertFormError(response, 'form', 'email',
|
||||||
work!?')
|
'Address already confirmed (by someone else)')
|
||||||
self.assertEqual(
|
|
||||||
str(list(response.context[0]['messages'])[0]),
|
|
||||||
'Address not added', 'Adding already added address must lead to\
|
|
||||||
"Address not added" message!')
|
|
||||||
|
|
||||||
def test_remove_unconfirmed_non_existing_email(self):
|
def test_remove_unconfirmed_non_existing_email(self):
|
||||||
'''
|
'''
|
||||||
@@ -795,12 +773,15 @@ class Tester(TestCase):
|
|||||||
# Whohu, static... :-[
|
# Whohu, static... :-[
|
||||||
'openid': self.openid,
|
'openid': self.openid,
|
||||||
},
|
},
|
||||||
|
follow=True,
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 302, 'OpenID must redirect')
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.user.unconfirmedopenid_set.count(),
|
self.user.unconfirmedopenid_set.count(),
|
||||||
1, 'There must only be one unconfirmed ID!')
|
1, 'There must only be one unconfirmed ID!')
|
||||||
|
|
||||||
|
self.assertFormError(response, 'form', 'openid',
|
||||||
|
'OpenID already added, but not confirmed yet!')
|
||||||
|
|
||||||
# Manual confirm, since testing is _really_ hard!
|
# Manual confirm, since testing is _really_ hard!
|
||||||
unconfirmed = self.user.unconfirmedopenid_set.first()
|
unconfirmed = self.user.unconfirmedopenid_set.first()
|
||||||
confirmed = ConfirmedOpenId()
|
confirmed = ConfirmedOpenId()
|
||||||
@@ -816,12 +797,11 @@ class Tester(TestCase):
|
|||||||
# Whohu, static... :-[
|
# Whohu, static... :-[
|
||||||
'openid': self.openid,
|
'openid': self.openid,
|
||||||
},
|
},
|
||||||
|
follow=True,
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 302, 'OpenID must redirect')
|
self.assertFormError(response, 'form', 'openid',
|
||||||
self.assertEqual(
|
'OpenID already added and confirmed!')
|
||||||
self.user.unconfirmedopenid_set.count(),
|
|
||||||
0, 'There must be no unconfirmed ID, since we tried adding an\
|
|
||||||
already confirmed ID!')
|
|
||||||
|
|
||||||
def test_assign_photo_to_openid(self):
|
def test_assign_photo_to_openid(self):
|
||||||
self.test_add_openid()
|
self.test_add_openid()
|
||||||
|
|||||||
Reference in New Issue
Block a user