def test_issue_2599(self): homepage = Page.objects.get(id=2) child1 = Page(title="child1") homepage.add_child(instance=child1) child2 = Page(title="child2") homepage.add_child(instance=child2) child1.delete() self.login() post_data = { "title": "New page!", "content": "Some content", "slug": "hello-world", "action-submit": "Submit", } preview_url = reverse( "wagtailadmin_pages:preview_on_add", args=("tests", "simplepage", homepage.id), ) response = self.client.post(preview_url, post_data) # Check the JSON response self.assertEqual(response.status_code, 200) self.assertJSONEqual(response.content.decode(), {"is_valid": True}) response = self.client.get(preview_url) # Check the HTML response self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tests/simple_page.html") self.assertContains(response, "New page!") # Check that the treebeard attributes were set correctly on the page object self.assertEqual(response.context["self"].depth, homepage.depth + 1) self.assertTrue(response.context["self"].path.startswith( homepage.path)) self.assertEqual(response.context["self"].get_parent(), homepage)
def test_issue_2599(self): homepage = Page.objects.get(id=2) child1 = Page(title='child1') homepage.add_child(instance=child1) child2 = Page(title='child2') homepage.add_child(instance=child2) child1.delete() self.login() post_data = { 'title': "New page!", 'content': "Some content", 'slug': 'hello-world', 'action-submit': "Submit", } preview_url = reverse('wagtailadmin_pages:preview_on_add', args=('tests', 'simplepage', homepage.id)) response = self.client.post(preview_url, post_data) # Check the JSON response self.assertEqual(response.status_code, 200) self.assertJSONEqual(response.content.decode(), {'is_valid': True}) response = self.client.get(preview_url) # Check the HTML response self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'tests/simple_page.html') self.assertContains(response, "New page!") # Check that the treebeard attributes were set correctly on the page object self.assertEqual(response.context['self'].depth, homepage.depth + 1) self.assertTrue(response.context['self'].path.startswith( homepage.path)) self.assertEqual(response.context['self'].get_parent(), homepage)