o
    þÞho!  ã                   @   s€   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 dZG dd	„ d	e	ƒZed
did�G dd„ deeƒƒZdS )é    )Úcontextmanager)ÚStaticLiveServerTestCase)Úmodify_settings)ÚSeleniumTestCase)ÚMiddlewareMixin)ÚgettextTc                   @   s   e Zd ZdZdd„ ZdS )ÚCSPMiddlewarez5The admin's JavaScript should be compatible with CSP.c                 C   s   d|j d< |S )Nzdefault-src 'self'zContent-Security-Policy)Úheaders)ÚselfÚrequestÚresponse© r   úZ/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/contrib/admin/tests.pyÚprocess_response   s   
zCSPMiddleware.process_responseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   Úappendz(django.contrib.admin.tests.CSPMiddleware)Ú
MIDDLEWAREc                   @   s¶   e Zd Zg d¢Zd(dd„Zd)dd„Zd(dd	„Zd(d
d„Zd(dd„Zd(dd„Z	d(dd„Z
d(dd„Zed(dd„ƒZd*dd„Zdd„ Zdd„ Zd+dd„Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdS ),ÚAdminSeleniumTestCase)zdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.sessionszdjango.contrib.sitesé
   c                 C   s"   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   r   r   r   Ú
wait_until   s   z AdminSeleniumTestCase.wait_untilé   c                    s6   |   ‡ fd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                    s   t | jƒˆ kS ©N)ÚlenÚwindow_handles)Úd©Únum_windowsr   r   Ú<lambda>0   s    zDAdminSeleniumTestCase.wait_for_and_switch_to_popup.<locals>.<lambda>éÿÿÿÿN)r   r   Ú	switch_toÚwindowr"   Úwait_page_ready)r
   r%   r   r   r$   r   Úwait_for_and_switch_to_popup*   s   z2AdminSeleniumTestCase.wait_for_and_switch_to_popupc                 C   ó4   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.byr.   Úselenium.webdriver.supportr0   r   Úpresence_of_element_locatedÚCSS_SELECTOR©r
   Úcss_selectorr   r.   Úecr   r   r   Úwait_for4   ó
   ÿzAdminSeleniumTestCase.wait_forc                 C   ó6   ddl m} ddlm} |  | |j|f|¡|¡ dS )zD
        Block until the text is found in the CSS selector.
        r   r-   r/   N)r1   r.   r2   r0   r   Útext_to_be_present_in_elementr4   ©r
   r6   Útextr   r.   r7   r   r   r   Úwait_for_text?   s   þz#AdminSeleniumTestCase.wait_for_textc                 C   r:   )zE
        Block until the value is found in the CSS selector.
        r   r-   r/   N)r1   r.   r2   r0   r   Ú#text_to_be_present_in_element_valuer4   r<   r   r   r   Úwait_for_valueK   s   
ÿüz$AdminSeleniumTestCase.wait_for_valuec                 C   r,   )zS
        Block until the element described by the CSS selector is visible.
        r   r-   r/   N)r1   r.   r2   r0   r   Úvisibility_of_element_locatedr4   r5   r   r   r   Úwait_until_visibleY   r9   z(AdminSeleniumTestCase.wait_until_visiblec                 C   r,   )zU
        Block until the element described by the CSS selector is invisible.
        r   r-   r/   N)r1   r.   r2   r0   r   Úinvisibility_of_element_locatedr4   r5   r   r   r   Úwait_until_invisibled   r9   z*AdminSeleniumTestCase.wait_until_invisiblec                 C   s   |   dd„ |¡ dS )z1
        Block until the  page is ready.
        c                 S   s   |   d¡dkS )Nzreturn document.readyState;Úcomplete)Úexecute_script©Údriverr   r   r   r&   t   s    ÿz7AdminSeleniumTestCase.wait_page_ready.<locals>.<lambda>N)r   )r
   r   r   r   r   r*   o   s   ýz%AdminSeleniumTestCase.wait_page_readyc                 c   sT   � ddl m} ddlm} | j |jd¡}dV  | j| |¡|d� | j	|d� dS )zA
        Block until a new page has loaded and is ready.
        r   r-   r/   ÚhtmlN)r   )
r1   r.   r2   r0   r   Úfind_elementÚTAG_NAMEr   Ústaleness_ofr*   )r
   r   r.   r7   Úold_pager   r   r   Úwait_page_loadedy   s   €z&AdminSeleniumTestCase.wait_page_loadedú/admin/c                 C   s¤   ddl m} | j d| j|f ¡ | j |jd¡}| |¡ | j |jd¡}| |¡ tdƒ}|  	¡ � | j |j
d| ¡ ¡  W d  ƒ dS 1 sKw   Y  dS )	z&
        Log in to the admin.
        r   r-   z%s%sÚusernameÚpasswordzLog inz//input[@value="%s"]N)r1   r.   r   ÚgetÚlive_server_urlrJ   ÚNAMEÚ	send_keysÚ_rN   ÚXPATHÚclick)r
   rP   rQ   Ú	login_urlr.   Úusername_inputÚpassword_inputÚ
login_textr   r   r   Úadmin_login‡   s   



ÿ"ýz!AdminSeleniumTestCase.admin_loginc                 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   r-   ©ÚSelectN)r1   r.   Úselenium.webdriver.support.uir`   r   rJ   r4   Úselect_by_value©r
   ÚselectorÚvaluer.   r`   Úselectr   r   r   Úselect_option˜   ó   z#AdminSeleniumTestCase.select_optionc                 C   r^   )zŒ
        Deselect the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   r-   r_   N)r1   r.   ra   r`   r   rJ   r4   Údeselect_by_valuerc   r   r   r   Údeselect_option£   rh   z%AdminSeleniumTestCase.deselect_optionNc                 C   s4   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   r-   N)r1   r.   r   ÚassertEqualr!   Úfind_elementsr4   )r
   rd   ÚcountÚroot_elementr.   r   r   r   ÚassertCountSeleniumElements®   s
   
ÿz1AdminSeleniumTestCase.assertCountSeleniumElementsc                    s�   ddl m‰  |r'| j ˆ jˆ¡}g }|D ]
}| | d¡¡ q|  ||¡ d S |  ¡ � |  	‡ ‡fdd„¡ W d   ƒ d S 1 sAw   Y  d S )Nr   r-   re   c                    s   |   ˆ jˆ¡ S r    )rl   r4   rG   ©r.   Úoptions_selectorr   r   r&   Ê   s    ÿz<AdminSeleniumTestCase._assertOptionsValues.<locals>.<lambda>)
r1   r.   r   rl   r4   r   Úget_attributerk   Údisable_implicit_waitr   )r
   rq   ÚvaluesÚoptionsÚactual_valuesÚoptionr   rp   r   Ú_assertOptionsValues»   s   
ÿ"ÿz*AdminSeleniumTestCase._assertOptionsValuesc                 C   ó   |   d| |¡ dS )z{
        Assert that the <SELECT> widget identified by `selector` has the
        options with the given `values`.
        z%s > optionN©rx   ©r
   rd   rt   r   r   r   ÚassertSelectOptionsÏ   ó   z)AdminSeleniumTestCase.assertSelectOptionsc                 C   ry   )z„
        Assert that the <SELECT> widget identified by `selector` has the
        selected options with the given `values`.
        z%s > option:checkedNrz   r{   r   r   r   ÚassertSelectedOptionsÖ   r}   z+AdminSeleniumTestCase.assertSelectedOptionsc                 C   s&   ddl m} | j |j|¡ d¡dkS )zk
        Return True if the element identified by `selector` has the `disabled`
        attribute.
        r   r-   ÚdisabledÚtrue)r1   r.   r   rJ   r4   rr   )r
   rd   r.   r   r   r   Úis_disabledÝ   s   ÿýÿz!AdminSeleniumTestCase.is_disabled)r   )r   r   )rO   r    )r   r   r   Úavailable_appsr   r+   r8   r>   r@   rB   rD   r*   r   rN   r]   rg   rj   ro   rx   r|   r~   r�   r   r   r   r   r      s(    











r   N)Ú
contextlibr   Ú"django.contrib.staticfiles.testingr   Údjango.testr   Údjango.test.seleniumr   Údjango.utils.deprecationr   Údjango.utils.translationr   rV   Ú
__unittestr   r   r   r   r   r   Ú<module>   s    