Beispiel #1
0
    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])
Beispiel #2
0
    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])
Beispiel #3
0
 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),
         ))
Beispiel #4
0
    def setUp(self):
        self.root_page = Page.objects.get(id=2)

        self.single_event_page = SingleEventPage(
            title="foo",
            location="the moon",
            audience="public",
            cost="free",
            date_from="2001-01-01",
        )
        self.root_page.add_child(instance=self.single_event_page)
Beispiel #5
0
    def test_result_uses_custom_admin_display_title(self):
        single_event_page = SingleEventPage(
            title="Lunar event",
            location="the moon",
            audience="public",
            cost="free",
            date_from="2001-01-01",
        )
        self.root_page.add_child(instance=single_event_page)

        response = self.get({"q": "lunar"})
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response,
                                "wagtailadmin/chooser/_search_results.html")
        self.assertContains(response, "Lunar event (single event)")
Beispiel #6
0
 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)")
Beispiel #7
0
    def setUp(self):
        self.root_page = Page.objects.get(id=1)

        # Add a site so the URLs render correctly
        Site.objects.create(is_default_site=True, root_page=self.root_page)

        # Create 50 blog pages
        for i in range(50):
            self.root_page.add_child(instance=SingleEventPage(
                title="Event {}".format(i + 1),
                slug=str(i + 1),
                date_from=timezone.now(),
                audience="public",
                location="reykjavik",
                cost="cost",
            ))

        self.login()
Beispiel #8
0
    def test_with_url_extended_page_type(self):
        # Add a page that overrides the url path
        single_event_page = SingleEventPage(
            title="foo",
            location="the moon",
            audience="public",
            cost="free",
            date_from="2001-01-01",
        )
        self.root_page.add_child(instance=single_event_page)

        # Send request
        response = self.get()
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "wagtailadmin/chooser/browse.html")

        page_urls = [page.url for page in response.context["pages"]]

        self.assertIn("/foo/pointless-suffix/", page_urls)
Beispiel #9
0
    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/")