def test_panel_query_count(self): # fake a request object with bob as the user self.client.user = self.bob with self.assertNumQueries(4): # Instantiating RecentEditsPanel should not generate N+1 queries - # i.e. any number less than 6 would be reasonable here panel = RecentEditsPanel(self.client) # check that the panel is still actually returning results html = panel.render() self.assertIn("Ameristralia Day", html)
def get_context_data(self, **kwargs): request = self.request panels = [ SiteSummaryPanel(request), UpgradeNotificationPanel(request), PagesForModerationPanel(request), RecentEditsPanel(request), RecentActivityPanel(request) ] for fn in hooks.get_hooks('construct_homepage_panels'): fn(request, panels) root_page = get_explorable_root_page(request.user) if root_page: root_site = root_page.get_site() else: root_site = None real_site_name = None if root_site: real_site_name = root_site.site_name if root_site.site_name else root_site.hostname return { 'root_page': root_page, 'root_site': root_site, 'site_name': real_site_name if real_site_name else settings.WAGTAIL_SITE_NAME, 'panels': sorted(panels, key=lambda p: p.order), 'user': request.user }
def test_panel(self): """Test if the panel actually returns expected pages """ self.login(username='******', password='******') # change a page self.change_something("Bob's edit") # set a user to 'mock' a request self.client.user = get_user_model().objects.get( email='*****@*****.**') # get the panel to get the last edits panel = RecentEditsPanel() ctx = panel.get_context_data({'request': self.client}) # check if the revision is the revision of edited Page self.assertEqual(ctx['last_edits'][0][0].page, Page.objects.get(pk=self.child_page.id)) # check if the page in this list is the specific page of this revision self.assertEqual(ctx['last_edits'][0][1], Page.objects.get(pk=self.child_page.id).specific)