From patchwork Fri Aug 21 14:32:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 509505 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CAB3F1402A9 for ; Sat, 22 Aug 2015 00:34:28 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id B14761A1D9D for ; Sat, 22 Aug 2015 00:34:28 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lists.ozlabs.org (Postfix) with ESMTP id 9CF151A0052 for ; Sat, 22 Aug 2015 00:32:35 +1000 (AEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 21 Aug 2015 07:32:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,722,1432623600"; d="scan'208";a="629748512" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 21 Aug 2015 07:32:30 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t7LEWTJd007158; Fri, 21 Aug 2015 15:32:29 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t7LEWTl2010818; Fri, 21 Aug 2015 15:32:29 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t7LEWTDP010814; Fri, 21 Aug 2015 15:32:29 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 08/16] tests/test_user: Add "profile unlink" tests Date: Fri, 21 Aug 2015 15:32:12 +0100 Message-Id: <1440167540-8751-9-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1440167540-8751-1-git-send-email-stephen.finucane@intel.com> References: <1440167540-8751-1-git-send-email-stephen.finucane@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" The 'link' view was not being tested. Resolve this with tests for all paths. Signed-off-by: Stephen Finucane --- 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@example.com' - secondary_email = 'test2@example.com' - password = None - def __init__(self): + def __init__(self, username='testuser', email='test@example.com', + secondary_email='test2@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@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)