ó
­â0_c           @   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 e f d „  ƒ  YZ e d i d	 d
 6ƒ d e e f d „  ƒ  Yƒ Z d S(   iÿÿÿÿ(   t   StaticLiveServerTestCase(   t   modify_settings(   t   SeleniumTestCase(   t   MiddlewareMixin(   t   ugettextt   CSPMiddlewarec           B   s   e  Z d  Z d „  Z RS(   s5   The admin's JavaScript should be compatible with CSP.c         C   s   d | d <| S(   Ns   default-src 'self's   Content-Security-Policy(    (   t   selft   requestt   response(    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   process_response
   s    
(   t   __name__t
   __module__t   __doc__R	   (    (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyR      s   t
   MIDDLEWAREs(   django.contrib.admin.tests.CSPMiddlewaret   appendt   AdminSeleniumTestCasec           B   s¿   e  Z d  d d d d g Z d d „ Z d d d „ Z d d	 „ Z d d
 „ Z d d „ Z d d „ Z d d „ Z	 d „  Z
 d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   django.contrib.admins   django.contrib.auths   django.contrib.contenttypess   django.contrib.sessionss   django.contrib.sitesi
   c         C   s-   d d l  m } | |  j | ƒ j | ƒ d S(   s=  
        Helper function that blocks the execution of the tests until the
        specified callback returns a value that is not falsy. This function 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.
        iÿÿÿÿ(   t   WebDriverWaitN(   t   selenium.webdriver.support.waitR   t   seleniumt   until(   R   t   callbackt   timeoutR   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt
   wait_until   s    i   c            s   |  j  ‡  f d †  | ƒ d S(   s   
        Block until `num_windows` are present (usually 2, but can be
        overridden in the case of pop-ups opening other pop-ups).
        c            s   t  |  j ƒ ˆ  k S(   N(   t   lent   window_handles(   t   d(   t   num_windows(    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   <lambda>)   t    N(   R   (   R   R   R   (    (   R   s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_for_popup$   s    c         C   sF   d d l  m } d d l m } |  j | j | j | f ƒ | ƒ d S(   sX   
        Helper function that blocks until a CSS selector is found on the page.
        iÿÿÿÿ(   t   By(   t   expected_conditionsN(   t   selenium.webdriver.common.byR   t   selenium.webdriver.supportR   R   t   presence_of_element_locatedt   CSS_SELECTOR(   R   t   css_selectorR   R   t   ec(    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_for+   s
    c         C   sI   d d l  m } d d l m } |  j | j | j | f | ƒ | ƒ d S(   sZ   
        Helper function that blocks until the text is found in the CSS selector.
        iÿÿÿÿ(   R   (   R   N(   R    R   R!   R   R   t   text_to_be_present_in_elementR#   (   R   R$   t   textR   R   R%   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_for_text6   s    c         C   sI   d d l  m } d d l m } |  j | j | j | f | ƒ | ƒ d S(   s[   
        Helper function that blocks until the value is found in the CSS selector.
        iÿÿÿÿ(   R   (   R   N(   R    R   R!   R   R   t#   text_to_be_present_in_element_valueR#   (   R   R$   R(   R   R   R%   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_for_valueB   s    c         C   sF   d d l  m } d d l m } |  j | j | j | f ƒ | ƒ d S(   sS   
        Block until the element described by the CSS selector is visible.
        iÿÿÿÿ(   R   (   R   N(   R    R   R!   R   R   t   visibility_of_element_locatedR#   (   R   R$   R   R   R%   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_until_visibleN   s
    c         C   sF   d d l  m } d d l m } |  j | j | j | f ƒ | ƒ d S(   sU   
        Block until the element described by the CSS selector is invisible.
        iÿÿÿÿ(   R   (   R   N(   R    R   R!   R   R   t   invisibility_of_element_locatedR#   (   R   R$   R   R   R%   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_until_invisibleY   s
    c         C   s9   d d l  m } y |  j d ƒ Wn | k
 r4 n Xd S(   s7   
        Block until page has started to load.
        iÿÿÿÿ(   t   TimeoutExceptiont   bodyN(   t   selenium.common.exceptionsR0   R&   (   R   R0   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   wait_page_loadedd   s
    s   /admin/c         C   s   |  j  j d |  j | f ƒ |  j  j d ƒ } | j | ƒ |  j  j d ƒ } | j | ƒ t d ƒ } |  j  j d | ƒ j ƒ  |  j ƒ  d S(   s8   
        Helper function to log into the admin.
        s   %s%st   usernamet   passwords   Log ins   //input[@value="%s"]N(	   R   t   gett   live_server_urlt   find_element_by_namet	   send_keyst   _t   find_element_by_xpatht   clickR3   (   R   R4   R5   t	   login_urlt   username_inputt   password_inputt
   login_text(    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   admin_loginr   s    	c         C   s   |  j  j d | | f ƒ S(   s¹   
        Helper function that returns the value for the CSS attribute of an
        DOM element specified by the given selector. Uses the jQuery that ships
        with Django.
        s$   return django.jQuery("%s").css("%s")(   R   t   execute_script(   R   t   selectort	   attribute(    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   get_css_value€   s    	c         C   sj   d d l  m } |  j j d | ƒ } x' | D] } | j d ƒ | k r- | Sq- W| d | | f ƒ ‚ d S(   s‹   
        Returns the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        iÿÿÿÿ(   t   NoSuchElementExceptions   %s > optiont   values   Option "%s" not found in "%s"N(   R2   RF   R   t   find_elements_by_css_selectort   get_attribute(   R   RC   RG   RF   t   optionst   option(    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   get_select_option‰   s    c            s…   | rX |  j  j ˆ  ƒ } g  } x$ | D] } | j | j d ƒ ƒ q% W|  j | | ƒ n) |  j ƒ   |  j ‡  f d †  ƒ Wd  QXd  S(   NRG   c            s   t  |  j ˆ  ƒ ƒ d k S(   Ni    (   R   RH   (   t   driver(   t   options_selector(    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyR   ¢   R   (   R   RH   R   RI   t   assertEqualt   disable_implicit_waitR   (   R   RN   t   valuesRJ   t   actual_valuesRK   (    (   RN   s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   _assertOptionsValues•   s    c         C   s   |  j  d | | ƒ d S(   s|   
        Asserts that the <SELECT> widget identified by `selector` has the
        options with the given `values`.
        s   %s > optionN(   RS   (   R   RC   RQ   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   assertSelectOptions¥   s    c         C   s   |  j  d | | ƒ d S(   s…   
        Asserts that the <SELECT> widget identified by `selector` has the
        selected options with the given `values`.
        s   %s > option:checkedN(   RS   (   R   RC   RQ   (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   assertSelectedOptions¬   s    c         C   s(   |  j  j | ƒ j d ƒ j | ƒ d k S(   si   
        Returns True if the element identified by `selector` has the CSS class
        `klass`.
        t   classiÿÿÿÿ(   R   t   find_element_by_css_selectorRI   t   find(   R   RC   t   klass(    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   has_css_class³   s    (   R
   R   t   available_appsR   R   R&   R)   R+   R-   R/   R3   RA   RE   RL   RS   RT   RU   RZ   (    (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyR      s(   	
							N(   t"   django.contrib.staticfiles.testingR    t   django.testR   t   django.test.seleniumR   t   django.utils.deprecationR   t   django.utils.translationR   R:   R   R   (    (    (    s<   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/tests.pyt   <module>   s   