
    N}bg                         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      m/home/e360mart.nyusoft.in/public_html/e360mart_env/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 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_for0   sc     	433333HHHHHH**BO\+JKK	
 	
 	
 	
 	
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;   sj     	433333HHHHHH,,,/7 7	
 	
 	
 	
 	
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_valueG   sj     	433333HHHHHH22,/7 7	
 	
 	
 	
 	
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_visibleS   sc     	433333HHHHHH,,bo|-LMM	
 	
 	
 	
 	
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_invisible^   sc     	433333HHHHHH../NOO	
 	
 	
 	
 	
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>n   s    6001NOOS]] r   N)r$   )r   r#   s     r   r1   z%AdminSeleniumTestCase.wait_page_readyi   s-     	]]	
 	
 	
 	
 	
r   c              #      K   ddl m} | j                            d          }dV  |                     |                    |          |           |                     |           dS )zA
        Block until a new page has loaded and is ready.
        r   r6   htmlN)r#   )r9   r7   r    find_element_by_tag_namer$   staleness_ofr1   )r   r#   r>   old_pages       r   wait_page_loadedz&AdminSeleniumTestCase.wait_page_loadedr   sx      
 	IHHHHH=99&AA117CCCW-----r   /admin/c                    | j                             | j        |           | j                             d          }|                    |           | j                             d          }|                    |           t          d          }|                                 5  | j                             d|z                                             ddd           dS # 1 swxY w Y   dS )z&
        Log in to the admin.
        usernamepasswordzLog inz//input[@value="%s"]N)	r    getlive_server_urlfind_element_by_name	send_keys_rX   find_element_by_xpathclick)r   r[   r\   	login_urlusername_inputpassword_input
login_texts          r   admin_loginz!AdminSeleniumTestCase.admin_login~   s6    	D$8$8))DEEE;;JGG  ***;;JGG  ***x[[
""$$ 	] 	]M//0F0STTZZ\\\	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	]s   %0C""C&)C&c                     ddl m}  || j                            |                    }|                    |           dS )z
        Select the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   SelectN)selenium.webdriver.support.uirk   r    find_element_by_css_selectorselect_by_valuer   selectorvaluerk   selects        r   select_optionz#AdminSeleniumTestCase.select_option   sO    
 	988888BB8LLMMu%%%%%r   c                     ddl m}  || j                            |                    }|                    |           dS )z
        Deselect the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   rj   N)rl   rk   r    rm   deselect_by_valuero   s        r   deselect_optionz%AdminSeleniumTestCase.deselect_option   sO    
 	988888BB8LLMM  '''''r   c                 X   |ra| j                                       }g }|D ]*}|                    |                    d                     +|                     ||           d S |                                 5  |                     fd           d d d            d S # 1 swxY w Y   d S )Nrq   c                 0    |                                 S r(   )find_elements_by_css_selector)rR   options_selectors    r   r-   z<AdminSeleniumTestCase._assertOptionsValues.<locals>.<lambda>   s    v'K'KL\']']#] r   )r    ry   r   get_attributeassertEqualdisable_implicit_waitr$   )r   rz   valuesoptionsactual_valuesoptions    `    r   _assertOptionsValuesz*AdminSeleniumTestCase._assertOptionsValues   s    	mAABRSSGM! D D$$V%9%9'%B%BCCCCV]33333
 ++--  ]]]]                   s   9BB#&B#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                     | j                             |                              d                              |          dk    S )zh
        Return True if the element identified by `selector` has the CSS class
        `klass`.
        classr.   )r    rm   r{   find)r   rp   klasss      r   has_css_classz#AdminSeleniumTestCase.has_css_class   s:    
 ::8DDw''Ur: 	;r   N)r   )r%   r   )rY   )r   r   r   available_appsr$   r2   r?   rD   rG   rJ   rM   r1   r   rX   rh   rs   rv   r   r   r   r   r   r   r   r   r      s]         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   ra   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o; o; o; o; o;,.F o; o; TSo; o; o;r   