def test_root_page_retreaval(self): sub_page = BasePageFactory.create(title="Child page", parent=self.root_page) url = reverse("nextjs:page_by_path:listing") response = self.client.get(f"{url}?html_path=") self.assertEqual(response.status_code, 200)
def test_list_generation(self): sub_page = BasePageFactory.create(title="Child page", parent=self.root_page) url = reverse("nextjs:page_relative_urls:listing") response = self.client.get(url) self.assertEqual(response.status_code, 200) data = response.json() self.assertEqual(data["meta"]["total_count"], 2) self.assertEqual(len(data["items"]), 2) self.assertEqual(data["items"][0]["relative_url"], "/")
def test_missing_password_yeilds_401(self): sub_page = BasePageFactory.create(title="Child page", parent=self.root_page) page_view_restriction = PageViewRestrictionFactory.create( page=sub_page) url = reverse( "nextjs:password_protected_page:detail_view", args=(page_view_restriction.pk, sub_page.pk), ) response = self.client.post(url) self.assertEqual(response.status_code, 401)
def test_redirect_page_if_user_is_not_logged_in(self): sub_page = BasePageFactory.create(title="Child page", parent=self.root_page) page_view_restriction = PageViewRestrictionFactory.create( page=sub_page, restriction_type=BaseViewRestriction.LOGIN, ) url = reverse("nextjs:page_by_path:listing") response = self.client.get( f"{url}?html_path=/child-page", content_type="application/json", ) self.assertEqual(response.status_code, 200) data = response.json() self.assertTrue("redirect" in data)
def test_preview_retrieval(self): sub_page = BasePageFactory.create(title="Child page", parent=self.root_page) preview = sub_page.create_page_preview() content_type = ContentType.objects.get_for_model(sub_page.__class__) token = preview.token content_type = f"{content_type.app_label}.{content_type.model}" response = self.client.get( reverse("nextjs:page_preview:listing"), { "content_type": content_type, "token": token, }, ) self.assertEqual(response.status_code, 200)
def test_correct_password_returns_ok(self): sub_page = BasePageFactory.create(title="Child page", parent=self.root_page) page_view_restriction = PageViewRestrictionFactory.create( page=sub_page, password="******", ) url = reverse( "nextjs:password_protected_page:detail_view", args=(page_view_restriction.pk, sub_page.pk), ) response = self.client.post( url, json.dumps({"password": "******"}), content_type="application/json", ) self.assertEqual(response.status_code, 200)
def setUp(self): self.site = Site.objects.first() self.root_page = BasePageFactory.create(title="Start", parent=None) self.site.root_page = self.root_page self.site.save()