From 8de381cfcaa4e416e3b5680ba59220dcd3e5321b Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Mon, 12 Feb 2024 12:23:16 +0000 Subject: [PATCH] Add different page states in TestRecentEditsQueryCount Simulate pages that are in workflow, locked, or scheduled --- wagtail/admin/tests/pages/test_dashboard.py | 37 ++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/wagtail/admin/tests/pages/test_dashboard.py b/wagtail/admin/tests/pages/test_dashboard.py index df75fc1316..a78cdc096a 100644 --- a/wagtail/admin/tests/pages/test_dashboard.py +++ b/wagtail/admin/tests/pages/test_dashboard.py @@ -6,7 +6,7 @@ from freezegun import freeze_time from wagtail.admin.views.home import RecentEditsPanel from wagtail.coreutils import get_dummy_request -from wagtail.models import Page +from wagtail.models import Page, Workflow from wagtail.test.testapp.models import SimplePage from wagtail.test.utils import WagtailTestUtils @@ -151,11 +151,27 @@ class TestRecentEditsQueryCount(WagtailTestUtils, TestCase): self.bob = self.create_superuser(username="bob", password="password") self.dummy_request = get_dummy_request() self.dummy_request.user = self.bob + workflow = Workflow.objects.first() + workflow_pages = {5, 6} + locked_pages = {6, 9} + scheduled_pages = {9, 12} # make a bunch of page edits (all to EventPages, so that calls to specific() don't add # an unpredictable number of queries) - pages_to_edit = Page.objects.filter(id__in=[4, 5, 6, 9, 12, 13]).specific() + pages_to_edit = list( + Page.objects.filter(id__in=[4, 5, 6, 9, 12, 13]).order_by("pk").specific() + ) for page in pages_to_edit: - page.save_revision(user=self.bob, log_action=True) + revision = page.save_revision(user=self.bob, log_action=True) + if page.pk in workflow_pages: + workflow.start(page, self.bob) + if page.pk in locked_pages: + page.locked = True + page.locked_by = self.bob + page.locked_at = timezone.now() + page.save() + if page.pk in scheduled_pages: + revision.approved_go_live_at = timezone.now() + revision.save() def test_panel_query_count(self): panel = RecentEditsPanel() @@ -167,6 +183,19 @@ class TestRecentEditsQueryCount(WagtailTestUtils, TestCase): # Rendering RecentEditsPanel should not generate N+1 queries - # i.e. any number less than 6 would be reasonable here html = panel.render_html(parent_context) - # check that the panel is still actually returning results self.assertIn("Ameristralia Day", html) + soup = self.get_soup(html) + self.assertEqual(len(soup.select('svg use[href="#icon-lock"]')), 2) + expected_statuses = [ + "live + draft", + "live + scheduled", + "live + scheduled", + "in moderation", + "in moderation", + ] + statuses = [ + "".join(e.find_all(string=True, recursive=False)).strip() + for e in soup.select(".w-status") + ] + self.assertEqual(statuses, expected_statuses)