[PATCH v2 08/16] tests/test_user: Add "profile unlink" tests
Stephen Finucane
stephen.finucane at intel.com
Sat Aug 22 00:32:12 AEST 2015
The 'link' view was not being tested. Resolve this with tests for all
paths.
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/tests/test_user.py | 93 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 86 insertions(+), 7 deletions(-)
diff --git a/patchwork/tests/test_user.py b/patchwork/tests/test_user.py
index ef213a7..e791095 100644
--- a/patchwork/tests/test_user.py
+++ b/patchwork/tests/test_user.py
@@ -32,15 +32,16 @@ def _confirmation_url(conf):
return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
class TestUser(object):
- username = 'testuser'
- email = 'test at example.com'
- secondary_email = 'test2 at example.com'
- password = None
- def __init__(self):
+ def __init__(self, username='testuser', email='test at example.com',
+ secondary_email='test2 at example.com'):
+ self.username = username
+ self.email = email
+ self.secondary_email = secondary_email
self.password = User.objects.make_random_password()
- self.user = User.objects.create_user(self.username,
- self.email, self.password)
+ self.user = User.objects.create_user(
+ self.username, self.email, self.password)
+
class UserPersonRequestTest(TestCase):
def setUp(self):
@@ -198,3 +199,81 @@ class UserPasswordChangeTest(TestCase):
response = self.client.get(self.done_url)
self.assertContains(response,
"Your password has been changed sucessfully")
+
+class UserUnlinkTest(TestCase):
+ def setUp(self):
+ self.form_url = '/user/unlink/{pid}/'
+ self.done_url = '/user/'
+ EmailConfirmation.objects.all().delete()
+ Person.objects.all().delete()
+
+ def testUnlinkPrimaryEmail(self):
+ user = TestUser()
+ self.client.login(username=user.username,
+ password=user.password)
+ conf = EmailConfirmation(type='userperson',
+ email=user.email,
+ user=user.user)
+ conf.save()
+ self.client.get(_confirmation_url(conf))
+
+ person = Person.objects.get(email=user.email)
+ response = self.client.post(self.form_url.format(pid=str(person.id)))
+ self.assertRedirects(response, self.done_url)
+
+ person = Person.objects.get(email=user.email)
+ self.assertEquals(person.user, user.user)
+
+ def testUnlinkSecondaryEmail(self):
+ user = TestUser()
+ self.client.login(username=user.username,
+ password=user.password)
+ conf = EmailConfirmation(type='userperson',
+ email=user.secondary_email,
+ user=user.user)
+ conf.save()
+ self.client.get(_confirmation_url(conf))
+
+ person = Person.objects.get(email=user.secondary_email)
+ response = self.client.post(self.form_url.format(pid=str(person.id)))
+ self.assertRedirects(response, self.done_url)
+
+ person = Person.objects.get(email=user.secondary_email)
+ self.assertEquals(person.user, None)
+
+ def testUnlinkAnotherUser(self):
+ user = TestUser()
+ self.client.login(username=user.username,
+ password=user.password)
+
+ other_user = TestUser('testuser_other', 'test_other at example.com',
+ 'test_other2 at example.com')
+ conf = EmailConfirmation(type='userperson',
+ email=other_user.email,
+ user=other_user.user)
+ conf.save()
+ self.client.get(_confirmation_url(conf))
+
+ person = Person.objects.get(email=other_user.email)
+ response = self.client.post(self.form_url.format(pid=str(person.id)))
+ self.assertRedirects(response, self.done_url)
+
+ person = Person.objects.get(email=other_user.email)
+ self.assertEquals(person.user, None)
+
+ def testUnlinkNonPost(self):
+ user = TestUser()
+ self.client.login(username=user.username,
+ password=user.password)
+ conf = EmailConfirmation(type='userperson',
+ email=user.secondary_email,
+ user=user.user)
+ conf.save()
+ self.client.get(_confirmation_url(conf))
+
+ person = Person.objects.get(email=user.secondary_email)
+ response = self.client.get(self.form_url.format(pid=str(person.id)))
+ self.assertRedirects(response, self.done_url)
+
+ person = Person.objects.get(email=user.secondary_email)
+ self.assertEquals(person.user, user.user)
--
2.0.0
More information about the Patchwork
mailing list