Exemplo n.º 1
0
 def test_purge_with_unroutable_page(self):
     PURGED_URLS[:] = []  # reset PURGED_URLS to the empty list
     root = Page.objects.get(url_path='/')
     page = EventIndex(title='new top-level page')
     root.add_child(instance=page)
     page.save_revision().publish()
     self.assertEqual(PURGED_URLS, [])
Exemplo n.º 2
0
 def test_purge_with_unroutable_page(self):
     PURGED_URLS[:] = []  # reset PURGED_URLS to the empty list
     root = Page.objects.get(url_path='/')
     page = EventIndex(title='new top-level page')
     root.add_child(instance=page)
     page.save_revision().publish()
     self.assertEqual(PURGED_URLS, [])
Exemplo n.º 3
0
    def test_with_page_type(self):
        # Add a page that is not a SimplePage
        event_page = EventPage(
            title="event",
            location='the moon',
            audience='public',
            cost='free',
            date_from='2001-01-01',
        )
        self.root_page.add_child(instance=event_page)

        # Add a page with a child page
        event_index_page = EventIndex(title="events", )
        self.root_page.add_child(instance=event_index_page)
        event_index_page.add_child(instance=EventPage(
            title="other event",
            location='the moon',
            audience='public',
            cost='free',
            date_from='2001-01-01',
        ))

        # Send request
        response = self.get({'page_type': 'tests.simplepage'})
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailadmin/chooser/browse.html')
        self.assertEqual(response.context['page_type_string'],
                         'tests.simplepage')

        pages = {
            page.id: page
            for page in response.context['pages'].object_list
        }

        # Child page is a simple page directly underneath root
        # so should appear in the list
        self.assertIn(self.child_page.id, pages)
        self.assertTrue(pages[self.child_page.id].can_choose)
        self.assertFalse(pages[self.child_page.id].can_descend)

        # Event page is not a simple page and is not descendable either
        # so should not appear in the list
        self.assertNotIn(event_page.id, pages)

        # Event index page is not a simple page but has a child and is therefore descendable
        # so should appear in the list
        self.assertIn(event_index_page.id, pages)
        self.assertFalse(pages[event_index_page.id].can_choose)
        self.assertTrue(pages[event_index_page.id].can_descend)
Exemplo n.º 4
0
    def test_with_page_type(self):
        # Add a page that is not a SimplePage
        event_page = EventPage(
            title="event",
            location='the moon', audience='public',
            cost='free', date_from='2001-01-01',
        )
        self.root_page.add_child(instance=event_page)

        # Add a page with a child page
        event_index_page = EventIndex(
            title="events",
        )
        self.root_page.add_child(instance=event_index_page)
        event_index_page.add_child(instance=EventPage(
            title="other event",
            location='the moon', audience='public',
            cost='free', date_from='2001-01-01',
        ))

        # Send request
        response = self.get({'page_type': 'tests.simplepage'})
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailadmin/chooser/browse.html')
        self.assertEqual(response.context['page_type_string'], 'tests.simplepage')

        pages = {
            page.id: page
            for page in response.context['pages'].object_list
        }

        # Child page is a simple page directly underneath root
        # so should appear in the list
        self.assertIn(self.child_page.id, pages)
        self.assertTrue(pages[self.child_page.id].can_choose)
        self.assertFalse(pages[self.child_page.id].can_descend)

        # Event page is not a simple page and is not descendable either
        # so should not appear in the list
        self.assertNotIn(event_page.id, pages)

        # Event index page is not a simple page but has a child and is therefore descendable
        # so should appear in the list
        self.assertIn(event_index_page.id, pages)
        self.assertFalse(pages[event_index_page.id].can_choose)
        self.assertTrue(pages[event_index_page.id].can_descend)
Exemplo n.º 5
0
 def make_event_section(self, name):
     event_index = self.home_page.add_child(instance=EventIndex(
         title=name))
     event_index.add_child(instance=EventPage(
         title='First Event',
         location='Bar', audience='public',
         cost='free', date_from='2001-01-01'))
     event_index.add_child(instance=EventPage(
         title='Second Event',
         location='Baz', audience='public',
         cost='free', date_from='2001-01-01'))
     return event_index
Exemplo n.º 6
0
    def setUp(self):
        self.root_page = Page.objects.get(id=1)

        # For simple tests
        self.home_page = self.root_page.add_child(instance=SimplePage(title="Homepage", slug="home"))
        self.about_page = self.home_page.add_child(instance=SimplePage(title="About us", slug="about"))
        self.contact_page = self.home_page.add_child(instance=SimplePage(title="Contact", slug="contact"))

        # For custom tests
        self.event_index = self.root_page.add_child(instance=EventIndex(title="Events", slug="events"))
        for i in range(20):
            self.event_index.add_child(instance=EventPage(title="Event " + str(i), slug="event" + str(i)))
Exemplo n.º 7
0
Arquivo: tests.py Projeto: xus/wagtail
    def test_get_urls_uses_specific(self):
        # Add an event page which has an extra url in the sitemap
        self.home_page.add_child(instance=EventIndex(
            title="Events",
            slug='events',
            live=True,
        ))

        sitemap = Sitemap(self.site)
        urls = [url['location'] for url in sitemap.get_urls()]

        self.assertIn('http://localhost/events/', urls)  # Main view
        self.assertIn('http://localhost/events/past/', urls)  # Sub view
Exemplo n.º 8
0
    def test_get_urls_uses_specific(self):
        request, django_site = self.get_request_and_django_site('/sitemap.xml')
        req_protocol = request.scheme

        # Add an event page which has an extra url in the sitemap
        self.home_page.add_child(instance=EventIndex(
            title="Events",
            slug='events',
            live=True,
        ))

        sitemap = Sitemap(request)
        urls = [url['location'] for url in sitemap.get_urls(1, django_site, req_protocol)]

        self.assertIn('http://localhost/events/', urls)  # Main view
        self.assertIn('http://localhost/events/past/', urls)  # Sub view
Exemplo n.º 9
0
 def make_event_section(self, name):
     event_index = self.home_page.add_child(instance=EventIndex(title=name))
     event_index.add_child(instance=EventPage(
         title="First Event",
         location="Bar",
         audience="public",
         cost="free",
         date_from="2001-01-01",
     ))
     event_index.add_child(instance=EventPage(
         title="Second Event",
         location="Baz",
         audience="public",
         cost="free",
         date_from="2001-01-01",
     ))
     return event_index
Exemplo n.º 10
0
    def setUp(self):
        self.root_page = Page.objects.get(id=1)

        # For simple tests
        self.home_page = self.root_page.add_child(
            instance=SimplePage(title="Homepage", slug="home2", content="hello")
        )
        self.about_page = self.home_page.add_child(
            instance=SimplePage(title="About us", slug="about", content="hello")
        )
        self.contact_page = self.home_page.add_child(
            instance=SimplePage(title="Contact", slug="contact", content="hello")
        )

        # For custom tests
        self.event_index = self.root_page.add_child(instance=EventIndex(title="Events", slug="events"))
        for i in range(20):
            self.event_index.add_child(instance=EventPage(
                title="Event " + str(i), slug="event" + str(i),
                location='the moon', audience='public',
                cost='free', date_from='2001-01-01',
            ))
Exemplo n.º 11
0
 def test_purge_with_unroutable_page(self):
     root = Page.objects.get(url_path="/")
     page = EventIndex(title="new top-level page")
     root.add_child(instance=page)
     page.save_revision().publish()
     self.assertEqual(PURGED_URLS, [])