def setUp(self): # Find root page self.root_page = Page.objects.get(id=2) # Add child page of class with base_form_class override # non model field is 'code' self.test_page = FormClassAdditionalFieldPage( title='A Statement', slug='a-statement', location='Early Morning Cafe, Mainland, NZ', body="<p>hello</p>" ) self.root_page.add_child(instance=self.test_page) # add new revision self.test_page.title = 'Statement' self.test_page.location = 'Victory Monument, Bangkok' self.test_page.body = ( "<p>I would like very much to go into the forrest.</p>" ) self.test_page_revision = self.test_page.save_revision() self.test_page_revision.created_at = local_datetime(2017, 10, 15) self.test_page_revision.save() # add another new revision self.test_page.title = 'True Statement' self.test_page.location = 'Victory Monument, Bangkok' self.test_page.body = ( "<p>I would like very much to go into the forest.</p>" ) self.test_page_revision_new = self.test_page.save_revision() self.test_page_revision_new.created_at = local_datetime(2017, 10, 16) self.test_page_revision_new.save() self.login()
def setUp(self): # Find root page self.root_page = Page.objects.get(id=2) # Add child page self.child_page = SimplePage( title="Hello world!", slug="hello-world", content="hello", ) self.root_page.add_child(instance=self.child_page) # more child pages to test ordering self.old_page = StandardIndex( title="Old page", slug="old-page", latest_revision_created_at=local_datetime(2010, 1, 1)) self.root_page.add_child(instance=self.old_page) self.new_page = SimplePage(title="New page", slug="new-page", content="hello", latest_revision_created_at=local_datetime( 2016, 1, 1)) self.root_page.add_child(instance=self.new_page) # Login self.user = self.login()
def setUp(self): self.christmas_event = EventPage.objects.get(url_path='/home/events/christmas/') self.christmas_event.title = "Last Christmas" self.christmas_event.date_from = '2013-12-25' self.christmas_event.body = ( "<p>Last Christmas I gave you my heart, " "but the very next day you gave it away</p>" ) self.last_christmas_revision = self.christmas_event.save_revision() self.last_christmas_revision.created_at = local_datetime(2013, 12, 25) self.last_christmas_revision.save() self.last_christmas_revision.publish() self.christmas_event.title = "This Christmas" self.christmas_event.date_from = '2014-12-25' self.christmas_event.body = ( "<p>This year, to save me from tears, " "I'll give it to someone special</p>" ) self.this_christmas_revision = self.christmas_event.save_revision() self.this_christmas_revision.created_at = local_datetime(2014, 12, 24) self.this_christmas_revision.save() self.this_christmas_revision.approved_go_live_at = local_datetime(2014, 12, 25) self.this_christmas_revision.save() self.user = self.login()
def test_search_order_by_status(self): root_page = Page.objects.get(id=2) live_event = SingleEventPage( title="Lunar event", location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1), live=True ) root_page.add_child(instance=live_event) draft_event = SingleEventPage( title="Lunar event", location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1), live=False ) root_page.add_child(instance=draft_event) response = self.get({'q': 'Lunar', 'ordering': 'live'}) page_ids = [page.id for page in response.context['pages']] self.assertEqual(page_ids, [draft_event.id, live_event.id]) response = self.get({'q': 'Lunar', 'ordering': '-live'}) page_ids = [page.id for page in response.context['pages']] self.assertEqual(page_ids, [live_event.id, draft_event.id])
def test_search_order_by_title(self): root_page = Page.objects.get(id=2) new_event = SingleEventPage( title="Lunar event", location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1) ) root_page.add_child(instance=new_event) new_event_2 = SingleEventPage( title="A Lunar event", location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1) ) root_page.add_child(instance=new_event_2) response = self.get({'q': 'Lunar', 'ordering': 'title'}) page_ids = [page.id for page in response.context['pages']] self.assertEqual(page_ids, [new_event_2.id, new_event.id]) response = self.get({'q': 'Lunar', 'ordering': '-title'}) page_ids = [page.id for page in response.context['pages']] self.assertEqual(page_ids, [new_event.id, new_event_2.id])
def test_search_order_by_status(self): root_page = Page.objects.get(id=2) live_event = SingleEventPage( title="Lunar event", location="the moon", audience="public", cost="free", date_from="2001-01-01", latest_revision_created_at=local_datetime(2016, 1, 1), live=True, ) root_page.add_child(instance=live_event) draft_event = SingleEventPage( title="Lunar event", location="the moon", audience="public", cost="free", date_from="2001-01-01", latest_revision_created_at=local_datetime(2016, 1, 1), live=False, ) root_page.add_child(instance=draft_event) response = self.get({"q": "Lunar", "ordering": "live"}) page_ids = [page.id for page in response.context["pages"]] self.assertEqual(page_ids, [draft_event.id, live_event.id]) response = self.get({"q": "Lunar", "ordering": "-live"}) page_ids = [page.id for page in response.context["pages"]] self.assertEqual(page_ids, [live_event.id, draft_event.id])
def test_search_order_by_updated(self): root_page = Page.objects.get(id=2) new_event = SingleEventPage( title="Lunar event", location="the moon", audience="public", cost="free", date_from="2001-01-01", latest_revision_created_at=local_datetime(2016, 1, 1), ) root_page.add_child(instance=new_event) new_event_2 = SingleEventPage( title="Lunar event 2", location="the moon", audience="public", cost="free", date_from="2001-01-01", latest_revision_created_at=local_datetime(2015, 1, 1), ) root_page.add_child(instance=new_event_2) response = self.get({ "q": "Lunar", "ordering": "latest_revision_created_at" }) page_ids = [page.id for page in response.context["pages"]] self.assertEqual(page_ids, [new_event_2.id, new_event.id]) response = self.get({ "q": "Lunar", "ordering": "-latest_revision_created_at" }) page_ids = [page.id for page in response.context["pages"]] self.assertEqual(page_ids, [new_event.id, new_event_2.id])
def test_get_revisions_index(self): response = self.client.get( reverse('wagtailadmin_pages:revisions_index', args=(self.christmas_event.id, )) ) self.assertEqual(response.status_code, 200) self.assertContains(response, formats.localize(parse_date('2013-12-25'))) last_christmas_preview_url = reverse( 'wagtailadmin_pages:revisions_view', args=(self.christmas_event.id, self.last_christmas_revision.id) ) last_christmas_revert_url = reverse( 'wagtailadmin_pages:revisions_revert', args=(self.christmas_event.id, self.last_christmas_revision.id) ) self.assertContains(response, last_christmas_preview_url) self.assertContains(response, last_christmas_revert_url) self.assertContains(response, formats.localize(local_datetime(2014, 12, 25))) this_christmas_preview_url = reverse( 'wagtailadmin_pages:revisions_view', args=(self.christmas_event.id, self.this_christmas_revision.id) ) this_christmas_revert_url = reverse( 'wagtailadmin_pages:revisions_revert', args=(self.christmas_event.id, self.this_christmas_revision.id) ) self.assertContains(response, this_christmas_preview_url) self.assertContains(response, this_christmas_revert_url)
def make_event_pages(self, count): for i in range(count): self.root_page.add_child(instance=SingleEventPage( title="New event " + str(i), location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1) ))
def make_event_pages(self, count): for i in range(count): self.root_page.add_child(instance=SingleEventPage( title="New event " + str(i), location="the moon", audience="public", cost="free", date_from="2001-01-01", latest_revision_created_at=local_datetime(2016, 1, 1), ))
def setUp(self): self.unpublished_event = EventPage.objects.get( url_path='/home/events/tentative-unpublished-event/') self.unpublished_event.title = "Unpublished Page" self.unpublished_event.date_from = '2014-12-25' self.unpublished_event.body = ("<p>Some Content</p>") self.unpublished_revision = self.unpublished_event.save_revision() self.unpublished_revision.created_at = local_datetime(2014, 12, 25) self.unpublished_revision.save() self.user = self.login()
def test_search_uses_admin_display_title_from_specific_class(self): # SingleEventPage has a custom get_admin_display_title method; explorer should # show the custom title rather than the basic database one root_page = Page.objects.get(id=2) new_event = SingleEventPage( title="Lunar event", location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1) ) root_page.add_child(instance=new_event) response = self.get({'q': "lunar"}) self.assertContains(response, "Lunar event (single event)")
def test_scheduled_revision(self): self.last_christmas_revision.publish() self.this_christmas_revision.approved_go_live_at = local_datetime(2014, 12, 26) self.this_christmas_revision.save() this_christmas_unschedule_url = reverse( 'wagtailadmin_pages:revisions_unschedule', args=(self.christmas_event.id, self.this_christmas_revision.id) ) response = self.client.get( reverse('wagtailadmin_pages:revisions_index', args=(self.christmas_event.id, )) ) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Scheduled for') self.assertContains(response, formats.localize(parse_date('2014-12-26'))) self.assertContains(response, this_christmas_unschedule_url)
def setUp(self): self.root_page = Page.objects.get(id=2) self.test_page = DefaultStreamPage( title="A DefaultStreamPage", slug="a-defaultstreampage", ) self.root_page.add_child(instance=self.test_page) self.test_page.title = "An Updated DefaultStreamPage" self.first_revision = self.test_page.save_revision() self.first_revision.created_at = local_datetime(2022, 5, 10) self.first_revision.save() self.login()
def test_listing_uses_specific_models(self): # SingleEventPage has custom URL routing; the 'live' link in the listing # should show the custom URL, which requires us to use the specific version # of the class self.new_event = SingleEventPage( title="New event", location='the moon', audience='public', cost='free', date_from='2001-01-01', latest_revision_created_at=local_datetime(2016, 1, 1) ) self.root_page.add_child(instance=self.new_event) response = self.client.get(reverse('wagtailadmin_explore', args=(self.root_page.id, ))) self.assertEqual(response.status_code, 200) self.assertContains(response, '/new-event/pointless-suffix/')