Example #1
0
    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/getting context of RecentEditsPanel should not generate N+1 queries -
            # i.e. any number less than 6 would be reasonable here
            panel = RecentEditsPanel()
            parent_context = {"request": self.client}
            panel.get_context_data(parent_context)

        # check that the panel is still actually returning results
        html = panel.render_html(parent_context)
        self.assertIn("Ameristralia Day", html)
Example #2
0
    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)