
    DvgL!                         d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ  G d de	          Z ed	d
i           G d dee                      ZdS )    )contextmanager)StaticLiveServerTestCase)modify_settings)SeleniumTestCase)MiddlewareMixin)gettextc                       e Zd ZdZd ZdS )CSPMiddlewarez5The admin's JavaScript should be compatible with CSP.c                     d|j         d<   |S )Nzdefault-src 'self'zContent-Security-Policy)headers)selfrequestresponses      W/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/admin/tests.pyprocess_responsezCSPMiddleware.process_response   s    6J23    N)__name__
__module____qualname____doc__r    r   r   r
   r
   
   s)        ??    r   r
   appendz(django.contrib.admin.tests.CSPMiddleware)
MIDDLEWAREc                       e Zd Zg 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dZd Zd ZddZd Zd Zd Zd ZdS )AdminSeleniumTestCase)zdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.sessionszdjango.contrib.sites
   c                 Z    ddl m}  || j        |                              |           dS )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AAAAAdmW--33H=====r      c                     |                      fd|           | j        j                            | j        j        d                    |                                  dS )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>-   s    #a&6"7"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_popup'   s^     	FFFFPPP&&t}'CB'GHHHr   c                 ~    ddl m} ddlm} |                     |                    |j        |f          |           dS )zB
        Block until a CSS selector is found on the page.
        r   Byexpected_conditionsN)selenium.webdriver.common.byr5   selenium.webdriver.supportr7   r$   presence_of_element_locatedCSS_SELECTORr   css_selectorr#   r5   ecs        r   wait_forzAdminSeleniumTestCase.wait_for1   sb     	433333HHHHHH**BO\+JKKW	
 	
 	
 	
 	
r   c                     ddl m} ddlm} |                     |                    |j        |f|          |           dS )zD
        Block until the text is found in the CSS selector.
        r   r4   r6   N)r8   r5   r9   r7   r$   text_to_be_present_in_elementr;   r   r=   textr#   r5   r>   s         r   wait_for_textz#AdminSeleniumTestCase.wait_for_text<   se     	433333HHHHHH,,bo|-LdSS	
 	
 	
 	
 	
r   c                     ddl m} ddlm} |                     |                    |j        |f|          |           dS )zE
        Block until the value is found in the CSS selector.
        r   r4   r6   N)r8   r5   r9   r7   r$   #text_to_be_present_in_element_valuer;   rB   s         r   wait_for_valuez$AdminSeleniumTestCase.wait_for_valueH   sl     	433333HHHHHH22,/  		
 	
 	
 	
 	
r   c                 ~    ddl m} ddlm} |                     |                    |j        |f          |           dS )zS
        Block until the element described by the CSS selector is visible.
        r   r4   r6   N)r8   r5   r9   r7   r$   visibility_of_element_locatedr;   r<   s        r   wait_until_visiblez(AdminSeleniumTestCase.wait_until_visibleV   sb     	433333HHHHHH,,bo|-LMMw	
 	
 	
 	
 	
r   c                 ~    ddl m} ddlm} |                     |                    |j        |f          |           dS )zU
        Block until the element described by the CSS selector is invisible.
        r   r4   r6   N)r8   r5   r9   r7   r$   invisibility_of_element_locatedr;   r<   s        r   wait_until_invisiblez*AdminSeleniumTestCase.wait_until_invisiblea   sc     	433333HHHHHH../NOOQX	
 	
 	
 	
 	
r   c                 4    |                      d |           dS )z1
        Block until the  page is ready.
        c                 4    |                      d          dk    S )Nzreturn document.readyState;complete)execute_script)drivers    r   r-   z7AdminSeleniumTestCase.wait_page_ready.<locals>.<lambda>q   s    6001NOO r   N)r$   )r   r#   s     r   r1   z%AdminSeleniumTestCase.wait_page_readyl   s1     	 	
 	
 	
 	
 	
r   c              #      K   ddl m} ddlm} | j                            |j        d          }dV  |                     |                    |          |           | 	                    |           dS )zA
        Block until a new page has loaded and is ready.
        r   r4   r6   htmlN)r#   )
r8   r5   r9   r7   r    find_elementTAG_NAMEr$   staleness_ofr1   )r   r#   r5   r>   old_pages        r   wait_page_loadedz&AdminSeleniumTestCase.wait_page_loadedv   s      
 	433333HHHHHH=--bk6BB117CCCW-----r   /admin/c                    ddl m} | j                            | j        |           | j                            |j        d          }|                    |           | j                            |j        d          }|                    |           t          d          }| 	                                5  | j                            |j
        d|z                                             ddd           dS # 1 swxY w Y   dS )z&
        Log in to the admin.
        r   r4   usernamepasswordzLog inz//input[@value="%s"]N)r8   r5   r    getlive_server_urlrU   NAME	send_keys_rY   XPATHclick)r   r\   r]   	login_urlr5   username_inputpassword_input
login_texts           r   admin_loginz!AdminSeleniumTestCase.admin_login   sA    	433333D$8$8))DEEE33BGZHH  ***33BGZHH  ***x[[
""$$ 	 	M&&0:= eggg	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   76C::C>C>c                     ddl m} ddlm}  || j                            |j        |                    }|                    |           dS )z
        Select the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   r4   SelectN)r8   r5   selenium.webdriver.support.uirl   r    rU   r;   select_by_valuer   selectorvaluer5   rl   selects         r   select_optionz#AdminSeleniumTestCase.select_option   se    
 	433333888888222?HMMNNu%%%%%r   c                     ddl m} ddlm}  || j                            |j        |                    }|                    |           dS )z
        Deselect the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   r4   rk   N)r8   r5   rm   rl   r    rU   r;   deselect_by_valuero   s         r   deselect_optionz%AdminSeleniumTestCase.deselect_option   se    
 	433333888888222?HMMNN  '''''r   Nc                     ddl m} |p| j        }|                     t	          |                    |j        |                    |           dS )z
        Assert number of matches for a CSS selector.

        `root_element` allow restriction to a pre-selected node.
        r   r4   N)r8   r5   r    assertEqualr)   find_elementsr;   )r   rp   countroot_elementr5   s        r   assertCountSeleniumElementsz1AdminSeleniumTestCase.assertCountSeleniumElements   sc     	433333#4t}**2?HEEFF	
 	
 	
 	
 	
r   c                 t   ddl m |rg| j                            j                  }g }|D ]*}|                    |                    d                     +|                     ||           d S |                                 5  | 	                    fd           d d d            d S # 1 swxY w Y   d S )Nr   r4   rq   c                 <    |                      j                   S r(   )ry   r;   )rR   r5   options_selectors    r   r-   z<AdminSeleniumTestCase._assertOptionsValues.<locals>.<lambda>   s$    v';';)9( ( $ r   )
r8   r5   r    ry   r;   r   get_attributerx   disable_implicit_waitr$   )r   r   valuesoptionsactual_valuesoptionr5   s    `    @r   _assertOptionsValuesz*AdminSeleniumTestCase._assertOptionsValues   s6   333333 	m11"/CSTTGM! D D$$V%9%9'%B%BCCCCV]33333
 ++--                         s   B--B14B1c                 8    |                      d|z  |           dS )z{
        Assert that the <SELECT> widget identified by `selector` has the
        options with the given `values`.
        z%s > optionNr   r   rp   r   s      r   assertSelectOptionsz)AdminSeleniumTestCase.assertSelectOptions   s%    
 	!!-(":FCCCCCr   c                 8    |                      d|z  |           dS )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KKKKKr   c                     ddl m} | j                            |j        |                              d                              |          dk    S )zh
        Return True if the element identified by `selector` has the CSS class
        `klass`.
        r   r4   classr.   )r8   r5   r    rU   r;   r   find)r   rp   klassr5   s       r   has_css_classz#AdminSeleniumTestCase.has_css_class   s\    
 	433333 M&&  ]7##T%[[	
r   )r   )r%   r   )rZ   r(   )r   r   r   available_appsr$   r2   r?   rD   rG   rJ   rM   r1   r   rY   ri   rs   rv   r|   r   r   r   r   r   r   r   r   r      sm         N	> 	> 	> 	>   	
 	
 	
 	


 

 

 


 
 
 
	
 	
 	
 	
	
 	
 	
 	

 
 
 
 . . . ^.   "	& 	& 	&	( 	( 	(
 
 
 
  (D D DL L L
 
 
 
 
r   r   N)
contextlibr   "django.contrib.staticfiles.testingr   django.testr   django.test.seleniumr   django.utils.deprecationr   django.utils.translationr   rb   r
   r   r   r   r   <module>r      s    % % % % % % G G G G G G ' ' ' ' ' ' 1 1 1 1 1 1 4 4 4 4 4 4 1 1 1 1 1 1    O    X'QRSSSV
 V
 V
 V
 V
,.F V
 V
 TSV
 V
 V
r   