
    hL!                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr   " S S\	5      r\" S	S
0S9 " S S\\5      5       rg)    )contextmanager)StaticLiveServerTestCase)modify_settings)SeleniumTestCase)MiddlewareMixin)gettextc                       \ rS rSrSrS rSrg)CSPMiddleware
   z5The admin's JavaScript should be compatible with CSP.c                 $    SUR                   S'   U$ )Nzdefault-src 'self'zContent-Security-Policy)headers)selfrequestresponses      L/var/www/html/env/lib/python3.13/site-packages/django/contrib/admin/tests.pyprocess_responseCSPMiddleware.process_response   s    6J23     N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r
   r
   
   s
    ?r   r
   appendz(django.contrib.admin.tests.CSPMiddleware)
MIDDLEWAREc                       \ rS rSr/ SQrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jr\SS j5       rSS jrS rS rSS jrS rS rS rS rSrg)AdminSeleniumTestCase   )zdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.sessionszdjango.contrib.sitesc                 T    SSK Jn  U" U R                  U5      R                  U5        g)z
Block the execution of the tests until the specified callback returns a
value that is not falsy. This method can be called, for example, after
clicking a link or submitting a form. See the other public methods that
call this function for more details.
r   )WebDriverWaitN)selenium.webdriver.support.waitr"   seleniumuntil)r   callbacktimeoutr"   s       r   
wait_until AdminSeleniumTestCase.wait_until   s!     	BdmmW-33H=r   c                    ^ U R                  U4S jU5        U R                  R                  R                  U R                  R                  S   5        U R                  5         g)z
Block until `num_windows` are present and are ready (usually 2, but can
be overridden in the case of pop-ups opening other pop-ups). Switch the
current window to the new pop-up.
c                 4   > [        U R                  5      T:H  $ N)lenwindow_handles)dnum_windowss    r   <lambda>DAdminSeleniumTestCase.wait_for_and_switch_to_popup.<locals>.<lambda>-   s    #a&6&6"7;"Fr   N)r(   r$   	switch_towindowr.   wait_page_ready)r   r0   r'   s    ` r   wait_for_and_switch_to_popup2AdminSeleniumTestCase.wait_for_and_switch_to_popup'   sG     	FP&&t}}'C'CB'GHr   c                 v    SSK Jn  SSKJn  U R	                  UR                  UR                  U45      U5        g)z2
Block until a CSS selector is found on the page.
r   Byexpected_conditionsN)selenium.webdriver.common.byr;   selenium.webdriver.supportr=   r(   presence_of_element_locatedCSS_SELECTORr   css_selectorr'   r;   ecs        r   wait_forAdminSeleniumTestCase.wait_for1   s/     	4H**BOO\+JKW	
r   c                 x    SSK Jn  SSKJn  U R	                  UR                  UR                  U4U5      U5        g)z4
Block until the text is found in the CSS selector.
r   r:   r<   N)r>   r;   r?   r=   r(   text_to_be_present_in_elementrA   r   rC   textr'   r;   rD   s         r   wait_for_text#AdminSeleniumTestCase.wait_for_text<   s2     	4H,,boo|-LdS	
r   c                 x    SSK Jn  SSKJn  U R	                  UR                  UR                  U4U5      U5        g)z5
Block until the value is found in the CSS selector.
r   r:   r<   N)r>   r;   r?   r=   r(   #text_to_be_present_in_element_valuerA   rI   s         r   wait_for_value$AdminSeleniumTestCase.wait_for_valueH   s7     	4H22,/ 		
r   c                 v    SSK Jn  SSKJn  U R	                  UR                  UR                  U45      U5        g)zC
Block until the element described by the CSS selector is visible.
r   r:   r<   N)r>   r;   r?   r=   r(   visibility_of_element_locatedrA   rB   s        r   wait_until_visible(AdminSeleniumTestCase.wait_until_visibleV   s/     	4H,,boo|-LMw	
r   c                 v    SSK Jn  SSKJn  U R	                  UR                  UR                  U45      U5        g)zE
Block until the element described by the CSS selector is invisible.
r   r:   r<   N)r>   r;   r?   r=   r(   invisibility_of_element_locatedrA   rB   s        r   wait_until_invisible*AdminSeleniumTestCase.wait_until_invisiblea   s0     	4H../NOQX	
r   c                 *    U R                  S U5        g)z!
Block until the  page is ready.
c                 *    U R                  S5      S:H  $ )Nzreturn document.readyState;complete)execute_script)drivers    r   r1   7AdminSeleniumTestCase.wait_page_ready.<locals>.<lambda>q   s    6001NOr   N)r(   )r   r'   s     r   r6   %AdminSeleniumTestCase.wait_page_readyl   s     		
r   c              #      #    SSK Jn  SSKJn  U R                  R                  UR                  S5      nSv   U R                  UR                  U5      US9  U R                  US9  g7f)z1
Block until a new page has loaded and is ready.
r   r:   r<   htmlN)r'   )
r>   r;   r?   r=   r$   find_elementTAG_NAMEr(   staleness_ofr6   )r   r'   r;   rD   old_pages        r   wait_page_loaded&AdminSeleniumTestCase.wait_page_loadedv   sT     
 	4H==--bkk6B17CW-s   A&A(c                    SSK Jn  U R                  R                  U R                  < U< 35        U R                  R                  UR                  S5      nUR                  U5        U R                  R                  UR                  S5      nUR                  U5        [        S5      nU R                  5          U R                  R                  UR                  SU-  5      R                  5         SSS5        g! , (       d  f       g= f)z
Log in to the admin.
r   r:   usernamepasswordzLog inz//input[@value="%s"]N)r>   r;   r$   getlive_server_urlrb   NAME	send_keys_rf   XPATHclick)r   ri   rj   	login_urlr;   username_inputpassword_input
login_texts           r   admin_login!AdminSeleniumTestCase.admin_login   s     	4D$8$8)DE33BGGZH  *33BGGZH  *x[
""$MM&&0:=eg %$$s   ;8C<<
D
c                     SSK Jn  SSKJn  U" U R                  R                  UR                  U5      5      nUR                  U5        g)zr
Select the <OPTION> with the value `value` inside the <SELECT> widget
identified by the CSS selector `selector`.
r   r:   SelectN)r>   r;   selenium.webdriver.support.uirz   r$   rb   rA   select_by_valuer   selectorvaluer;   rz   selects         r   select_option#AdminSeleniumTestCase.select_option   s7    
 	48222??HMNu%r   c                     SSK Jn  SSKJn  U" U R                  R                  UR                  U5      5      nUR                  U5        g)zt
Deselect the <OPTION> with the value `value` inside the <SELECT> widget
identified by the CSS selector `selector`.
r   r:   ry   N)r>   r;   r{   rz   r$   rb   rA   deselect_by_valuer}   s         r   deselect_option%AdminSeleniumTestCase.deselect_option   s7    
 	48222??HMN  'r   Nc                     SSK Jn  U=(       d    U R                  nU R                  [	        UR                  UR                  U5      5      U5        g)zh
Assert number of matches for a CSS selector.

`root_element` allow restriction to a pre-selected node.
r   r:   N)r>   r;   r$   assertEqualr-   find_elementsrA   )r   r~   countroot_elementr;   s        r   assertCountSeleniumElements1AdminSeleniumTestCase.assertCountSeleniumElements   s>     	4#4t}}**2??HEF	
r   c                 h  ^^ SSK Jm  U(       ac  U R                  R                  TR                  T5      n/ nU H#  nUR                  UR                  S5      5        M%     U R                  X$5        g U R                  5          U R                  UU4S j5        S S S 5        g ! , (       d  f       g = f)Nr   r:   r   c                 F   > U R                  TR                  T5      (       + $ r,   )r   rA   )r]   r;   options_selectors    r   r1   <AdminSeleniumTestCase._assertOptionsValues.<locals>.<lambda>   s    v';';)9( $r   )
r>   r;   r$   r   rA   r   get_attributer   disable_implicit_waitr(   )r   r   valuesoptionsactual_valuesoptionr;   s    `    @r   _assertOptionsValues*AdminSeleniumTestCase._assertOptionsValues   s    3mm11"//CSTGM!$$V%9%9'%BC "V3
 ++- .--s   B##
B1c                 .    U R                  SU-  U5        g)zc
Assert that the <SELECT> widget identified by `selector` has the
options with the given `values`.
z%s > optionNr   r   r~   r   s      r   assertSelectOptions)AdminSeleniumTestCase.assertSelectOptions   s    
 	!!-(":FCr   c                 .    U R                  SU-  U5        g)zl
Assert that the <SELECT> widget identified by `selector` has the
selected options with the given `values`.
z%s > option:checkedNr   r   s      r   assertSelectedOptions+AdminSeleniumTestCase.assertSelectedOptions   s    
 	!!"7("BFKr   c                     SSK Jn  U R                  R                  UR                  U5      R                  S5      R                  U5      S:g  $ )zP
Return True if the element identified by `selector` has the CSS class
`klass`.
r   r:   classr3   )r>   r;   r$   rb   rA   r   find)r   r~   klassr;   s       r   has_css_class#AdminSeleniumTestCase.has_css_class   sG    
 	4 MM&& ]7#T%[	
r   r   )r   )   r   )z/admin/r,   )r   r   r   r   available_appsr(   r7   rE   rK   rO   rS   rW   r6   r   rf   rv   r   r   r   r   r   r   r   r   r   r   r   r   r      so    N	>	



	
	

 . ."	&	(
(DL
r   r   N)
contextlibr   "django.contrib.staticfiles.testingr   django.testr   django.test.seleniumr   django.utils.deprecationr   django.utils.translationr   ro   r
   r   r   r   r   <module>r      sQ    % G ' 1 4 1O  X'QRSV
,.F V
 TV
r   