mirror of
https://github.com/django/django.git
synced 2025-06-03 02:29:13 +00:00
Removed hardcoded pks in admin selenium tests.
This commit is contained in:
parent
84e91262d6
commit
f5197be818
@ -69,6 +69,7 @@ from .models import (
|
|||||||
Collector,
|
Collector,
|
||||||
Color,
|
Color,
|
||||||
ComplexSortedPerson,
|
ComplexSortedPerson,
|
||||||
|
Country,
|
||||||
CoverLetter,
|
CoverLetter,
|
||||||
CustomArticle,
|
CustomArticle,
|
||||||
CyclicOne,
|
CyclicOne,
|
||||||
@ -6698,11 +6699,12 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
||||||
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
||||||
|
|
||||||
|
argentina = Country.objects.get(name="Argentina")
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
_get_HTML_inside_element_by_id(born_country_select_id),
|
_get_HTML_inside_element_by_id(born_country_select_id),
|
||||||
"""
|
f"""
|
||||||
<option value="" selected="">---------</option>
|
<option value="" selected="">---------</option>
|
||||||
<option value="1" selected="">Argentina</option>
|
<option value="{argentina.pk}" selected="">Argentina</option>
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
# Argentina isn't added to the living_country select nor selected by
|
# Argentina isn't added to the living_country select nor selected by
|
||||||
@ -6736,12 +6738,13 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
||||||
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
||||||
|
|
||||||
|
spain = Country.objects.get(name="Spain")
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
_get_HTML_inside_element_by_id(born_country_select_id),
|
_get_HTML_inside_element_by_id(born_country_select_id),
|
||||||
"""
|
f"""
|
||||||
<option value="" selected="">---------</option>
|
<option value="" selected="">---------</option>
|
||||||
<option value="1" selected="">Argentina</option>
|
<option value="{argentina.pk}" selected="">Argentina</option>
|
||||||
<option value="2">Spain</option>
|
<option value="{spain.pk}">Spain</option>
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -6778,12 +6781,13 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
||||||
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
||||||
|
|
||||||
|
italy = spain
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
_get_HTML_inside_element_by_id(born_country_select_id),
|
_get_HTML_inside_element_by_id(born_country_select_id),
|
||||||
"""
|
f"""
|
||||||
<option value="" selected="">---------</option>
|
<option value="" selected="">---------</option>
|
||||||
<option value="1" selected="">Argentina</option>
|
<option value="{argentina.pk}" selected="">Argentina</option>
|
||||||
<option value="2">Italy</option>
|
<option value="{italy.pk}">Italy</option>
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
# Italy is added to the living_country select and it's also selected by
|
# Italy is added to the living_country select and it's also selected by
|
||||||
|
@ -1740,8 +1740,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
|||||||
class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
|
class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
Band.objects.create(id=42, name="Bogey Blues")
|
self.blues = Band.objects.create(name="Bogey Blues")
|
||||||
Band.objects.create(id=98, name="Green Potatoes")
|
self.potatoes = Band.objects.create(name="Green Potatoes")
|
||||||
|
|
||||||
@screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
|
@screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
|
||||||
def test_ForeignKey(self):
|
def test_ForeignKey(self):
|
||||||
@ -1763,23 +1763,23 @@ class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
|
|||||||
self.selenium.find_element(By.ID, "lookup_id_main_band").click()
|
self.selenium.find_element(By.ID, "lookup_id_main_band").click()
|
||||||
self.wait_for_and_switch_to_popup()
|
self.wait_for_and_switch_to_popup()
|
||||||
link = self.selenium.find_element(By.LINK_TEXT, "Bogey Blues")
|
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()
|
link.click()
|
||||||
|
|
||||||
# The field now contains the selected band's id
|
# The field now contains the selected band's id
|
||||||
self.selenium.switch_to.window(main_window)
|
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
|
# Reopen the popup window and click on another band
|
||||||
self.selenium.find_element(By.ID, "lookup_id_main_band").click()
|
self.selenium.find_element(By.ID, "lookup_id_main_band").click()
|
||||||
self.wait_for_and_switch_to_popup()
|
self.wait_for_and_switch_to_popup()
|
||||||
link = self.selenium.find_element(By.LINK_TEXT, "Green Potatoes")
|
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()
|
link.click()
|
||||||
|
|
||||||
# The field now contains the other selected band's id
|
# The field now contains the other selected band's id
|
||||||
self.selenium.switch_to.window(main_window)
|
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):
|
def test_many_to_many(self):
|
||||||
from selenium.webdriver.common.by import By
|
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.selenium.find_element(By.ID, "lookup_id_supporting_bands").click()
|
||||||
self.wait_for_and_switch_to_popup()
|
self.wait_for_and_switch_to_popup()
|
||||||
link = self.selenium.find_element(By.LINK_TEXT, "Bogey Blues")
|
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()
|
link.click()
|
||||||
|
|
||||||
# The field now contains the selected band's id
|
# The field now contains the selected band's id
|
||||||
self.selenium.switch_to.window(main_window)
|
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
|
# Reopen the popup window and click on another band
|
||||||
self.selenium.find_element(By.ID, "lookup_id_supporting_bands").click()
|
self.selenium.find_element(By.ID, "lookup_id_supporting_bands").click()
|
||||||
self.wait_for_and_switch_to_popup()
|
self.wait_for_and_switch_to_popup()
|
||||||
link = self.selenium.find_element(By.LINK_TEXT, "Green Potatoes")
|
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()
|
link.click()
|
||||||
|
|
||||||
# The field now contains the two selected bands' ids
|
# The field now contains the two selected bands' ids
|
||||||
self.selenium.switch_to.window(main_window)
|
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):
|
class RelatedFieldWidgetSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user