def test_UsermaxPOSTDeleteAccountOK(self): with self.settings(INDEX_PAGE="HOME"): username = "******" self.login(username) data = { 'validation': "DROP MY ACCOUNT", 'delete_account_form_submitted': "yes", } f = DeleteAccountForm(data) self.assertEqual(f.is_valid(), True) response = self.client.post(reverse("account_settings"), data, follow=True) self.assertRedirects(response, reverse("index")) self.assertTemplateUsed(response, "layouts/base.html") self.logout() try: self.login(username) response2 = self.client.get(reverse("user_dashboard")) self.assertRedirects( response2, reverse("login") + "?next=" + reverse("user_dashboard")) self.assertEqual(0, 1) # Should never be reached except: pass # I expected that! pu = PytitionUser.objects.filter(user__username=username).count() self.assertEqual(pu, 0) User = get_user_model() u = User.objects.filter(username=username).count() self.assertEqual(u, 0)
def test_UserjohnPOSTDeleteAccountOK(self): # to avoid 404 error when index page redirects to deleted Organization profile page with self.settings(INDEX_PAGE="ALL_PETITIONS"): self.login("john") data = { 'validation': "DROP MY ACCOUNT", 'delete_account_form_submitted': "yes", } f = DeleteAccountForm(data) self.assertEqual(f.is_valid(), True) response = self.client.post(reverse("account_settings"), data, follow=True) self.assertRedirects(response, reverse("all_petitions")) self.assertTemplateUsed(response, "layouts/base.html") self.logout() try: self.login("john") response2 = self.client.get(reverse("user_dashboard")) self.assertRedirects(response2, reverse("login")+"?next="+reverse("user_dashboard")) self.assertEqual(0, 1) # Should never be reached except: pass # I expected that! pu = PytitionUser.objects.filter(user__username="******").count() self.assertEqual(pu, 0) User = get_user_model() u = User.objects.filter(username="******").count() self.assertEqual(u, 0)
def test_UserUnauthenticatedPOST(self): self.logout() data = { 'validation': "DROP MY ACCOUNT", 'delete_account_form_submitted': "yes", } f = DeleteAccountForm(data) self.assertEqual(f.is_valid(), True) response = self.client.post(reverse("account_settings"), data, follow=True) self.assertRedirects(response, reverse("login")+"?next="+reverse("account_settings")) self.assertTemplateUsed(response, "layouts/base.html")
def test_UsersarahPOSTDeleteAccountValidNOK(self): username = "******" self.login(username) data = { 'validation': "DO *NOT* DROP MY ACCOUNT", 'delete_account_form_submitted': "yes", } f = DeleteAccountForm(data) self.assertEqual(f.is_valid(), False) response = self.client.post(reverse("account_settings"), data) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "layouts/base.html") self.assertTemplateUsed(response, "petition/account_settings.html") self.logout() self.login(username) response2 = self.client.get(reverse("user_dashboard")) self.assertEqual(response2.status_code, 200) pu = PytitionUser.objects.filter(user__username=username).count() self.assertEqual(pu, 1) User = get_user_model() u = User.objects.filter(username=username).count() self.assertEqual(u, 1)