def test_404(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) page = models.HelpBasePage.objects.filter(parent__isnull=False).get() # page parent can't be deleted yet with self.assertRaises(Http404): views.delete_page(request, page_pk=page.parent_id) # not a page with self.assertRaises(Http404): views.delete_page(request, page_pk="123")
def test_delete_page_post(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) request.method = "POST" request.POST = {} page = models.HelpBasePage.objects.filter(parent__isnull=False).get() response = views.delete_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 200) # page still exists page.refresh_from_db() request.POST["yes_delete"] = True response = views.delete_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 302) self.assertEqual(response["Location"], reverse("admin:index", kwargs={"page_pk": page.parent_id})) # page was deleted with self.assertRaises(models.HelpBasePage.DoesNotExist): page.refresh_from_db()
def test_delete_page_post(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) request.method = "POST" request.POST = {} page = models.HelpBasePage.objects.filter(parent__isnull=False).get() response = views.delete_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 200) # page still exists page.refresh_from_db() request.POST["yes_delete"] = True response = views.delete_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 302) self.assertEqual( response["Location"], reverse("admin:index", kwargs={"page_pk": page.parent_id})) # page was deleted with self.assertRaises(models.HelpBasePage.DoesNotExist): page.refresh_from_db()
def test_delete_page_get(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) page = models.HelpBasePage.objects.filter(parent__isnull=False).get() response = views.delete_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 200)