o a@s|ddlmZddlmZddlmZddlmZddlm Z ddl m Z Gddde Z ed d id Gd d d eeZdS))contextmanager)StaticLiveServerTestCase)modify_settings)SeleniumTestCase)MiddlewareMixin)gettextc@seZdZdZddZdS) CSPMiddlewarez5The admin's JavaScript should be compatible with CSP.cCsd|jd<|S)Nzdefault-src 'self'zContent-Security-Policy)headers)selfrequestresponser ,zDAdminSeleniumTestCase.wait_for_and_switch_to_popup..N)rr switch_towindowr"wait_page_ready)r r%rr r$rwait_for_and_switch_to_popup&s z2AdminSeleniumTestCase.wait_for_and_switch_to_popupcC4ddlm}ddlm}|||j|f|dS)zB Block until a CSS selector is found on the page. rByexpected_conditionsN)selenium.webdriver.common.byr/selenium.webdriver.supportr1rpresence_of_element_located CSS_SELECTORr css_selectorrr/ecr r rwait_for0  zAdminSeleniumTestCase.wait_forcC6ddlm}ddlm}|||j|f||dS)zD Block until the text is found in the CSS selector. rr.r0N)r2r/r3r1rtext_to_be_present_in_elementr5r r7textrr/r8r r r wait_for_text;   z#AdminSeleniumTestCase.wait_for_textcCr;)zE Block until the value is found in the CSS selector. rr.r0N)r2r/r3r1r#text_to_be_present_in_element_valuer5r=r r rwait_for_valueGr@z$AdminSeleniumTestCase.wait_for_valuecCr-)zS Block until the element described by the CSS selector is visible. rr.r0N)r2r/r3r1rvisibility_of_element_locatedr5r6r r rwait_until_visibleSr:z(AdminSeleniumTestCase.wait_until_visiblecCr-)zU Block until the element described by the CSS selector is invisible. rr.r0N)r2r/r3r1rinvisibility_of_element_locatedr5r6r r rwait_until_invisible^r:z*AdminSeleniumTestCase.wait_until_invisiblecCs|dd|dS)z1 Block until the page is ready. cSs|ddkS)Nzreturn document.readyState;complete)execute_scriptdriverr r rr&nr'z7AdminSeleniumTestCase.wait_page_ready..N)r)r rr r rr+isz%AdminSeleniumTestCase.wait_page_readyccsDddlm}|jd}dV|j|||d|j|ddS)zA Block until a new page has loaded and is ready. rr0htmlN)r)r3r1rfind_element_by_tag_namer staleness_ofr+)r rr8old_pager r rwait_page_loadedrs   z&AdminSeleniumTestCase.wait_page_loaded/admin/cCs|jd|j|f|jd}|||jd}||td}||jd|WddS1s?wYdS)z& Log in to the admin. z%s%susernamepasswordzLog inz//input[@value="%s"]N) rgetlive_server_urlfind_element_by_name send_keys_rOfind_element_by_xpathclick)r rQrR login_urlusername_inputpassword_input login_textr r r admin_login~s     "z!AdminSeleniumTestCase.admin_logincC*ddlm}||j|}||dS)z Select the