
    (\i$              	          d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ dZ edd	i
       ee
j                  ge
j                   ge
j                   ge
j                   ge
j                   gd       G d dee                    Zy)    )contextmanager)StaticLiveServerTestCase)modify_settingsoverride_settings)SeleniumTestCase)CSP)gettextTappendz5django.middleware.csp.ContentSecurityPolicyMiddleware)
MIDDLEWARE)zdefault-srczconnect-srczimg-srcz
script-srcz	style-src)
SECURE_CSPc                        e Zd Zg dZ fdZddZddZddZddZddZ	ddZ
dd	Zdd
Zedd       Zd ZddZd Zd ZddZd Zd Zd Zd Z xZS )AdminSeleniumTestCase)zdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.sessionszdjango.contrib.sitesc                 f    | j                  | j                  d      g        t        |           y )Nsecurity)source)assertEqualget_browser_logssupertearDown)self	__class__s    j/home/devuser/fomin/mqttuser/mqtt_project/myenv/lib/python3.12/site-packages/django/contrib/admin/tests.pyr   zAdminSeleniumTestCase.tearDown"   s,    ..j.A2F    c                 T    ddl m}  || j                  |      j                  |       y)a%  
        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_untilz AdminSeleniumTestCase.wait_until'   s!     	BdmmW-33H=r   c                     | j                  fd|       | j                  j                  j                  | j                  j                  d          | j                          y)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    t        | j                        k(  S N)lenwindow_handles)dnum_windowss    r   <lambda>zDAdminSeleniumTestCase.wait_for_and_switch_to_popup.<locals>.<lambda>8   s    #a&6&6"7;"F r   N)r!   r   	switch_towindowr&   wait_page_ready)r   r(   r    s    ` r   wait_for_and_switch_to_popupz2AdminSeleniumTestCase.wait_for_and_switch_to_popup2   sG     	FP&&t}}'C'CB'GHr   c                 v    ddl m} ddlm} | j	                  |j                  |j                  |f      |       y)zB
        Block until a CSS selector is found on the page.
        r   Byexpected_conditionsN)selenium.webdriver.common.byr1   selenium.webdriver.supportr3   r!   presence_of_element_locatedCSS_SELECTORr   css_selectorr    r1   ecs        r   wait_forzAdminSeleniumTestCase.wait_for<   s/     	4H**BOO\+JKW	
r   c                 x    ddl m} ddlm} | j	                  |j                  |j                  |f|      |       y)zD
        Block until the text is found in the CSS selector.
        r   r0   r2   N)r4   r1   r5   r3   r!   text_to_be_present_in_elementr7   r   r9   textr    r1   r:   s         r   wait_for_textz#AdminSeleniumTestCase.wait_for_textG   s2     	4H,,boo|-LdS	
r   c                 x    ddl m} ddlm} | j	                  |j                  |j                  |f|      |       y)zE
        Block until the value is found in the CSS selector.
        r   r0   r2   N)r4   r1   r5   r3   r!   #text_to_be_present_in_element_valuer7   r>   s         r   wait_for_valuez$AdminSeleniumTestCase.wait_for_valueS   s7     	4H22,/ 		
r   c                 v    ddl m} ddlm} | j	                  |j                  |j                  |f      |       y)zS
        Block until the element described by the CSS selector is visible.
        r   r0   r2   N)r4   r1   r5   r3   r!   visibility_of_element_locatedr7   r8   s        r   wait_until_visiblez(AdminSeleniumTestCase.wait_until_visiblea   s/     	4H,,boo|-LMw	
r   c                 v    ddl m} ddlm} | j	                  |j                  |j                  |f      |       y)zU
        Block until the element described by the CSS selector is invisible.
        r   r0   r2   N)r4   r1   r5   r3   r!   invisibility_of_element_locatedr7   r8   s        r   wait_until_invisiblez*AdminSeleniumTestCase.wait_until_invisiblel   s0     	4H../NOQX	
r   c                 *    | j                  d |       y)z0
        Block until the page is ready.
        c                 *    | j                  d      dk(  S )Nzreturn document.readyState;complete)execute_script)drivers    r   r)   z7AdminSeleniumTestCase.wait_page_ready.<locals>.<lambda>|   s    6001NO r   N)r!   )r   r    s     r   r-   z%AdminSeleniumTestCase.wait_page_readyw   s     		
r   c              #     K   ddl m} ddlm} ddlm} | j                  j                  |j                  d      }d 	 | j                  |j                  |      |       | j                  |       y# |$ r Y w xY ww)zA
        Block until a new page has loaded and is ready.
        r   )WebDriverExceptionr0   r2   htmlN)r    )selenium.common.exceptionsrP   r4   r1   r5   r3   r   find_elementTAG_NAMEr!   staleness_ofr-   )r   r    rP   r1   r:   old_pages         r   wait_page_loadedz&AdminSeleniumTestCase.wait_page_loaded   su     
 	B3H==--bkk6B	OOBOOH5wOG 	W- " 	 		s)   =B  "A5 "B 5A=:B <A==B c                 .   | j                   j                         d   }| j                   j                         d   }| j                   j                  |dz   |       | j                          | j                   j                  ||       | j                          y )Nwidthheight   )r   get_window_sizeset_window_sizer-   )r   rY   rZ   s      r   trigger_resizez$AdminSeleniumTestCase.trigger_resize   st    --/8..0:%%eai8%%eV4r   c                    ddl m} | j                  j                  | j                  |       | j                  j                  |j                  d      }|j                  |       | j                  j                  |j                  d      }|j                  |       t        d      }| j                         5  | j                  j                  |j                  d|z        j                          ddd       y# 1 sw Y   yxY w)z&
        Log in to the admin.
        r   r0   usernamepasswordzLog inz//input[@value="%s"]N)r4   r1   r   getlive_server_urlrS   NAME	send_keys_rW   XPATHclick)r   r`   ra   	login_urlr1   username_inputpassword_input
login_texts           r   admin_loginz!AdminSeleniumTestCase.admin_login   s     	4D$8$8)DE33BGGZH  *33BGGZH  *x[
""$ 	MM&&0:=eg	 	 	s   98C::Dc                     ddl m} ddlm}  || j                  j                  |j                  |            }|j                  |       y)z
        Select the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   r0   SelectN)r4   r1   selenium.webdriver.support.uirp   r   rS   r7   select_by_valuer   selectorvaluer1   rp   selects         r   select_optionz#AdminSeleniumTestCase.select_option   s7    
 	48222??HMNu%r   c                     ddl m} ddlm}  || j                  j                  |j                  |            }|j                  |       y)z
        Deselect the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   r0   ro   N)r4   r1   rq   rp   r   rS   r7   deselect_by_valuers   s         r   deselect_optionz%AdminSeleniumTestCase.deselect_option   s7    
 	48222??HMN  'r   c                     ddl m} |xs | j                  }| j                  t	        |j                  |j                  |            |       y)z
        Assert number of matches for a CSS selector.

        `root_element` allow restriction to a pre-selected node.
        r   r0   N)r4   r1   r   r   r%   find_elementsr7   )r   rt   countroot_elementr1   s        r   assertCountSeleniumElementsz1AdminSeleniumTestCase.assertCountSeleniumElements   s>     	4#4t}}**2??HEF	
r   c                 P   ddl m |rb| j                  j                  j                        }g }|D ]"  }|j                  |j                  d             $ | j                  ||       y | j                         5  | j                  fd       d d d        y # 1 sw Y   y xY w)Nr   r0   ru   c                 >    | j                  j                         S r$   )r|   r7   )rN   r1   options_selectors    r   r)   z<AdminSeleniumTestCase._assertOptionsValues.<locals>.<lambda>   s!    v';';)9( $ r   )
r4   r1   r   r|   r7   r
   get_attributer   disable_implicit_waitr!   )r   r   valuesoptionsactual_valuesoptionr1   s    `    @r   _assertOptionsValuesz*AdminSeleniumTestCase._assertOptionsValues   s    3mm11"//CSTGM! D$$V%9%9'%BCDV]3
 ++-   s   =BB%c                 .    | j                  d|z  |       y)z{
        Assert that the <SELECT> widget identified by `selector` has the
        options with the given `values`.
        z%s > optionNr   r   rt   r   s      r   assertSelectOptionsz)AdminSeleniumTestCase.assertSelectOptions   s    
 	!!-(":FCr   c                 .    | j                  d|z  |       y)z
        Assert that the <SELECT> widget identified by `selector` has the
        selected options with the given `values`.
        z%s > option:checkedNr   r   s      r   assertSelectedOptionsz+AdminSeleniumTestCase.assertSelectedOptions   s    
 	!!"7("BFKr   c                 ~    ddl m} | j                  j                  |j                  |      j                  d      dk(  S )zk
        Return True if the element identified by `selector` has the `disabled`
        attribute.
        r   r0   disabledtrue)r4   r1   r   rS   r7   r   )r   rt   r1   s      r   is_disabledz!AdminSeleniumTestCase.is_disabled   s>    
 	4 MM&&rAOO 	
r   )
   )   r   )z/admin/r$   )__name__
__module____qualname__available_appsr   r!   r.   r;   r@   rC   rF   rI   r-   r   rW   r^   rm   rw   rz   r   r   r   r   r   __classcell__)r   s   @r   r   r      sz    N
	>	



	
	

 . .*"	&	(
(DL
r   r   N)
contextlibr   "django.contrib.staticfiles.testingr   django.testr   r   django.test.seleniumr   django.utils.cspr   django.utils.translationr	   rf   
__unittestNONESELFr    r   r   <module>r      s    % G : 1   1 
 QR zzHH:xxjhhZh
,.F h
h
r   