MCPcopy
hub / github.com/django/django / test_populate_existing_object

Method test_populate_existing_object

tests/admin_views/tests.py:6581–6625  ·  view source on GitHub ↗

The prepopulation works for existing objects too, as long as the original field is empty (#19082).

(self)

Source from the content-addressed store, hash-verified

6579 )
6580
6581 def test_populate_existing_object(self):
6582 """
6583 The prepopulation works for existing objects too, as long as
6584 the original field is empty (#19082).
6585 """
6586 from selenium.webdriver.common.by import By
6587
6588 # Slugs are empty to start with.
6589 item = MainPrepopulated.objects.create(
6590 name=" this is the mAin nÀMë",
6591 pubdate="2012-02-18",
6592 status="option two",
6593 slug1="",
6594 slug2="",
6595 )
6596 self.admin_login(
6597 username="super", password="secret", login_url=reverse("admin:index")
6598 )
6599
6600 object_url = self.live_server_url + reverse(
6601 "admin:admin_views_mainprepopulated_change", args=(item.id,)
6602 )
6603
6604 self.selenium.get(object_url)
6605 self.selenium.find_element(By.ID, "id_name").send_keys(" the best")
6606
6607 # The slugs got prepopulated since they were originally empty
6608 slug1 = self.selenium.find_element(By.ID, "id_slug1").get_attribute("value")
6609 slug2 = self.selenium.find_element(By.ID, "id_slug2").get_attribute("value")
6610 self.assertEqual(slug1, "this-is-the-main-name-the-best-2012-02-18")
6611 self.assertEqual(slug2, "option-two-this-is-the-main-name-the-best")
6612
6613 # Save the object
6614 with self.wait_page_loaded():
6615 self.selenium.find_element(By.XPATH, '//input[@value="Save"]').click()
6616
6617 self.selenium.get(object_url)
6618 self.selenium.find_element(By.ID, "id_name").send_keys(" hello")
6619
6620 # The slugs got prepopulated didn't change since they were originally
6621 # not empty
6622 slug1 = self.selenium.find_element(By.ID, "id_slug1").get_attribute("value")
6623 slug2 = self.selenium.find_element(By.ID, "id_slug2").get_attribute("value")
6624 self.assertEqual(slug1, "this-is-the-main-name-the-best-2012-02-18")
6625 self.assertEqual(slug2, "option-two-this-is-the-main-name-the-best")
6626
6627 @screenshot_cases(["desktop_size", "mobile_size", "dark", "high_contrast"])
6628 def test_collapsible_fieldset(self):

Callers

nothing calls this directly

Calls 5

reverseFunction · 0.90
admin_loginMethod · 0.80
wait_page_loadedMethod · 0.80
createMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected