+
+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@example.com',
+ 'test_other2@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)