测试gitnore

This commit is contained in:
ladeng07
2022-05-06 15:45:57 +08:00
parent 12f390949b
commit 51552904f9
2347 changed files with 120102 additions and 53549 deletions
@@ -9,21 +9,20 @@ from django.utils.translation import gettext as _
class CSPMiddleware(MiddlewareMixin):
"""The admin's JavaScript should be compatible with CSP."""
def process_response(self, request, response):
response.headers["Content-Security-Policy"] = "default-src 'self'"
response.headers['Content-Security-Policy'] = "default-src 'self'"
return response
@modify_settings(MIDDLEWARE={"append": "django.contrib.admin.tests.CSPMiddleware"})
@modify_settings(MIDDLEWARE={'append': 'django.contrib.admin.tests.CSPMiddleware'})
class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
available_apps = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
]
def wait_until(self, callback, timeout=10):
@@ -34,7 +33,6 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
call this function for more details.
"""
from selenium.webdriver.support.wait import WebDriverWait
WebDriverWait(self.selenium, timeout).until(callback)
def wait_for_and_switch_to_popup(self, num_windows=2, timeout=10):
@@ -53,9 +51,9 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.presence_of_element_located((By.CSS_SELECTOR, css_selector)), timeout
ec.presence_of_element_located((By.CSS_SELECTOR, css_selector)),
timeout
)
def wait_for_text(self, css_selector, text, timeout=10):
@@ -64,10 +62,10 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.text_to_be_present_in_element((By.CSS_SELECTOR, css_selector), text),
timeout,
ec.text_to_be_present_in_element(
(By.CSS_SELECTOR, css_selector), text),
timeout
)
def wait_for_value(self, css_selector, text, timeout=10):
@@ -76,12 +74,10 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.text_to_be_present_in_element_value(
(By.CSS_SELECTOR, css_selector), text
),
timeout,
(By.CSS_SELECTOR, css_selector), text),
timeout
)
def wait_until_visible(self, css_selector, timeout=10):
@@ -90,9 +86,9 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.visibility_of_element_located((By.CSS_SELECTOR, css_selector)), timeout
ec.visibility_of_element_located((By.CSS_SELECTOR, css_selector)),
timeout
)
def wait_until_invisible(self, css_selector, timeout=10):
@@ -101,9 +97,9 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.invisibility_of_element_located((By.CSS_SELECTOR, css_selector)), timeout
ec.invisibility_of_element_located((By.CSS_SELECTOR, css_selector)),
timeout
)
def wait_page_ready(self, timeout=10):
@@ -111,8 +107,7 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
Block until the page is ready.
"""
self.wait_until(
lambda driver: driver.execute_script("return document.readyState;")
== "complete",
lambda driver: driver.execute_script('return document.readyState;') == 'complete',
timeout,
)
@@ -122,27 +117,24 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
Block until a new page has loaded and is ready.
"""
from selenium.webdriver.support import expected_conditions as ec
old_page = self.selenium.find_element_by_tag_name("html")
old_page = self.selenium.find_element_by_tag_name('html')
yield
# Wait for the next page to be loaded
self.wait_until(ec.staleness_of(old_page), timeout=timeout)
self.wait_page_ready(timeout=timeout)
def admin_login(self, username, password, login_url="/admin/"):
def admin_login(self, username, password, login_url='/admin/'):
"""
Log in to the admin.
"""
self.selenium.get("%s%s" % (self.live_server_url, login_url))
username_input = self.selenium.find_element_by_name("username")
self.selenium.get('%s%s' % (self.live_server_url, login_url))
username_input = self.selenium.find_element_by_name('username')
username_input.send_keys(username)
password_input = self.selenium.find_element_by_name("password")
password_input = self.selenium.find_element_by_name('password')
password_input.send_keys(password)
login_text = _("Log in")
login_text = _('Log in')
with self.wait_page_loaded():
self.selenium.find_element_by_xpath(
'//input[@value="%s"]' % login_text
).click()
self.selenium.find_element_by_xpath('//input[@value="%s"]' % login_text).click()
def select_option(self, selector, value):
"""
@@ -150,7 +142,6 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
identified by the CSS selector `selector`.
"""
from selenium.webdriver.support.ui import Select
select = Select(self.selenium.find_element_by_css_selector(selector))
select.select_by_value(value)
@@ -160,7 +151,6 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
identified by the CSS selector `selector`.
"""
from selenium.webdriver.support.ui import Select
select = Select(self.selenium.find_element_by_css_selector(selector))
select.deselect_by_value(value)
@@ -169,7 +159,7 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
options = self.selenium.find_elements_by_css_selector(options_selector)
actual_values = []
for option in options:
actual_values.append(option.get_attribute("value"))
actual_values.append(option.get_attribute('value'))
self.assertEqual(values, actual_values)
else:
# Prevent the `find_elements_by_css_selector` call from blocking
@@ -177,9 +167,7 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
# to be the case.
with self.disable_implicit_wait():
self.wait_until(
lambda driver: not driver.find_elements_by_css_selector(
options_selector
)
lambda driver: not driver.find_elements_by_css_selector(options_selector)
)
def assertSelectOptions(self, selector, values):
@@ -201,9 +189,5 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
Return True if the element identified by `selector` has the CSS class
`klass`.
"""
return (
self.selenium.find_element_by_css_selector(selector)
.get_attribute("class")
.find(klass)
!= -1
)
return (self.selenium.find_element_by_css_selector(selector)
.get_attribute('class').find(klass) != -1)