def test_edit_page_post(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) request.method = "POST" request.POST = {"title": "Test Page", "slug": "test-page"} page = models.HelpBasePage.objects.filter(parent__isnull=False).get() response = views.edit_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 200) request.POST["app"] = "tickets.urls" response = views.edit_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 302) self.assertEqual(response["Location"], reverse("admin:index", kwargs={"page_pk": page.pk})) page.refresh_from_db() self.assertEqual(page.title, "Test Page") self.assertEqual(page.slug, "test-page")
def test_has_no_preview(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) base_page = models.HelpBasePage.objects.filter( parent__isnull=False).get() ct = ContentType.objects.get(model="helppage", app_label="cms") page = models.HelpPage.objects.create(parent=base_page, title="FAQ", body="", content_type=ct) response = views.edit_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 200) response.render() self.assertInHTML("<div class=\"panel-heading\">Preview</div>", response.content.decode(), count=0)
def test_404(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) with self.assertRaises(Http404): views.edit_page(request, page_pk="123")
def test_edit_page_get(self): request = MockRequest(self.user, has_otp=True, has_sudo=True) page = models.HelpBasePage.objects.filter(parent__isnull=False).get() response = views.edit_page(request, page_pk=page.pk) self.assertEqual(response.status_code, 200)