summaryrefslogtreecommitdiff
path: root/tests/admin_widgets/tests.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2025-05-09 07:17:58 -0400
committerGitHub <noreply@github.com>2025-05-09 13:17:58 +0200
commitf5197be818dfcb0d58d6e5f7cc44ec5343010b58 (patch)
tree14162cab3d522940a22b636ac676c2431fba3125 /tests/admin_widgets/tests.py
parent84e91262d6b94d35b381d0a46ff5402eaac7c996 (diff)
Removed hardcoded pks in admin selenium tests.
Diffstat (limited to 'tests/admin_widgets/tests.py')
-rw-r--r--tests/admin_widgets/tests.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index efff4e47d7..bd2dd10cc4 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -1740,8 +1740,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
def setUp(self):
super().setUp()
- Band.objects.create(id=42, name="Bogey Blues")
- Band.objects.create(id=98, name="Green Potatoes")
+ self.blues = Band.objects.create(name="Bogey Blues")
+ self.potatoes = Band.objects.create(name="Green Potatoes")
@screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
def test_ForeignKey(self):
@@ -1763,23 +1763,23 @@ class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
self.selenium.find_element(By.ID, "lookup_id_main_band").click()
self.wait_for_and_switch_to_popup()
link = self.selenium.find_element(By.LINK_TEXT, "Bogey Blues")
- self.assertIn("/band/42/", link.get_attribute("href"))
+ self.assertIn(f"/band/{self.blues.pk}/", link.get_attribute("href"))
link.click()
# The field now contains the selected band's id
self.selenium.switch_to.window(main_window)
- self.wait_for_value("#id_main_band", "42")
+ self.wait_for_value("#id_main_band", str(self.blues.pk))
# Reopen the popup window and click on another band
self.selenium.find_element(By.ID, "lookup_id_main_band").click()
self.wait_for_and_switch_to_popup()
link = self.selenium.find_element(By.LINK_TEXT, "Green Potatoes")
- self.assertIn("/band/98/", link.get_attribute("href"))
+ self.assertIn(f"/band/{self.potatoes.pk}/", link.get_attribute("href"))
link.click()
# The field now contains the other selected band's id
self.selenium.switch_to.window(main_window)
- self.wait_for_value("#id_main_band", "98")
+ self.wait_for_value("#id_main_band", str(self.potatoes.pk))
def test_many_to_many(self):
from selenium.webdriver.common.by import By
@@ -1810,23 +1810,25 @@ class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
self.selenium.find_element(By.ID, "lookup_id_supporting_bands").click()
self.wait_for_and_switch_to_popup()
link = self.selenium.find_element(By.LINK_TEXT, "Bogey Blues")
- self.assertIn("/band/42/", link.get_attribute("href"))
+ self.assertIn(f"/band/{self.blues.pk}/", link.get_attribute("href"))
link.click()
# The field now contains the selected band's id
self.selenium.switch_to.window(main_window)
- self.wait_for_value("#id_supporting_bands", "42")
+ self.wait_for_value("#id_supporting_bands", str(self.blues.pk))
# Reopen the popup window and click on another band
self.selenium.find_element(By.ID, "lookup_id_supporting_bands").click()
self.wait_for_and_switch_to_popup()
link = self.selenium.find_element(By.LINK_TEXT, "Green Potatoes")
- self.assertIn("/band/98/", link.get_attribute("href"))
+ self.assertIn(f"/band/{self.potatoes.pk}/", link.get_attribute("href"))
link.click()
# The field now contains the two selected bands' ids
self.selenium.switch_to.window(main_window)
- self.wait_for_value("#id_supporting_bands", "42,98")
+ self.wait_for_value(
+ "#id_supporting_bands", f"{self.blues.pk},{self.potatoes.pk}"
+ )
class RelatedFieldWidgetSeleniumTests(AdminWidgetSeleniumTestCase):