Skip to content

Commit

Permalink
Simplify tests for revisions comparison buttons in workflow dashboard…
Browse files Browse the repository at this point in the history
… panel
  • Loading branch information
laymonage committed Aug 24, 2023
1 parent 29fb69b commit 9775809
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions wagtail/admin/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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!",
Expand Down Expand Up @@ -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",
)


Expand Down

0 comments on commit 9775809

Please sign in to comment.