From 977580989b0af3e93a409b837b44ed56e78d92f7 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Thu, 24 Aug 2023 10:55:53 +0100 Subject: [PATCH] Simplify tests for revisions comparison buttons in workflow dashboard panel --- wagtail/admin/tests/test_workflows.py | 39 ++++++++++++--------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/wagtail/admin/tests/test_workflows.py b/wagtail/admin/tests/test_workflows.py index 8f3f0c160217..a78be41faf4c 100644 --- a/wagtail/admin/tests/test_workflows.py +++ b/wagtail/admin/tests/test_workflows.py @@ -996,7 +996,6 @@ def test_admin_url_finder(self): class BasePageWorkflowTests(WagtailTestUtils, TestCase): model_name = "page" - comparison_url_name = "wagtailadmin_pages:revisions_compare" def setUp(self): delete_existing_workflows() @@ -1122,10 +1121,6 @@ def setUp(self): def model_name(self): return self.model._meta.verbose_name - @property - def comparison_url_name(self): - return self.model.snippet_viewset.get_url_name("revisions_compare") - def setup_object(self): self.object = self.model.objects.create( text="Hello world!", @@ -3565,29 +3560,29 @@ def test_dashboard_for_moderator_with_previous_revisions(self): self.assertContains(response, "Awaiting your review") soup = self.get_soup(response.content) - links = soup.find_all("a") - compare_with_live_link = None - compare_with_previous_link = None - for link in links: - if link.string == "Compare with live version": - compare_with_live_link = link - elif link.string == "Compare with previous version": - compare_with_previous_link = link + compare_with_live_url = self.get_url( + "revisions_compare", + args=(self.object.pk, "live", latest_revision.id), + ) + compare_with_previous_url = self.get_url( + "revisions_compare", + args=(self.object.pk, previous_revision.id, latest_revision.id), + ) + compare_with_live_link = soup.select_one(f"a[href='{compare_with_live_url}']") self.assertIsNotNone(compare_with_live_link) - expected_compare_with_live_url = reverse( - self.comparison_url_name, - args=(self.object.id, "live", latest_revision.id), + self.assertEqual( + compare_with_live_link.text.strip(), + "Compare with live version", ) - self.assertEqual(compare_with_live_link["href"], expected_compare_with_live_url) - self.assertIsNotNone(compare_with_previous_link) - expected_compare_with_previous_url = reverse( - self.comparison_url_name, - args=(self.object.id, previous_revision.id, latest_revision.id), + compare_with_previous_link = soup.select_one( + f"a[href='{compare_with_previous_url}']" ) + self.assertIsNotNone(compare_with_previous_link) self.assertEqual( - compare_with_previous_link["href"], expected_compare_with_previous_url + compare_with_previous_link.text.strip(), + "Compare with previous version", )