ó
ø¢TQc           @   sZ   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	 d S(   iÿÿÿÿ(   t   LiveServerTestCase(   t   import_module(   t   SkipTest(   t   ugettextt   AdminSeleniumWebDriverTestCasec           B   s}   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d d „ Z d d „ Z d „  Z d d „ Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z RS(   s.   selenium.webdriver.firefox.webdriver.WebDriverc         C   s’   yF |  j  j d d ƒ \ } } t | ƒ } t | | ƒ } | ƒ  |  _ Wn2 t k
 rz } t d |  j  t | ƒ f ƒ ‚ n Xt t	 |  ƒ j
 ƒ  d  S(   Nt   .i   s<   Selenium webdriver "%s" not installed or not operational: %s(   t   webdriver_classt   rsplitR   t   getattrt   seleniumt	   ExceptionR   t   strt   superR   t
   setUpClass(   t   clst   modulet   attrt   modt	   WebDrivert   e(    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyR   	   s    c         C   s6   t  |  d ƒ r |  j j ƒ  n  t t |  ƒ j ƒ  d  S(   NR	   (   t   hasattrR	   t   quitR   R   t   tearDownClass(   R   (    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyR      s    i
   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   R	   t   until(   t   selft   callbackt   timeoutR   (    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt
   wait_until   s    c            s   |  j  ‡  f d †  | ƒ d S(   su   
        Helper function that blocks until the element with the given tag name
        is found on the page.
        c            s   |  j  ˆ  ƒ S(   N(   t   find_element_by_tag_name(   t   driver(   t   tag_name(    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   <lambda>,   s    N(   R   (   R   R    R   (    (   R    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   wait_loaded_tag&   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.exceptionsR#   R"   (   R   R#   (    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   wait_page_loaded0   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   clickR&   (   R   R'   R(   t	   login_urlt   username_inputt   password_inputt
   login_text(    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   admin_login>   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(    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   get_css_valueL   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(   R%   R9   R	   t   find_elements_by_css_selectort   get_attribute(   R   R6   R:   R9   t   optionst   option(    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   get_select_optionU   s    c         C   sW   |  j  j d | ƒ } g  } x$ | D] } | j | j d ƒ ƒ q# W|  j | | ƒ d S(   s|   
        Asserts that the <SELECT> widget identified by `selector` has the
        options with the given `values`.
        s   %s > optionR:   N(   R	   R;   t   appendR<   t   assertEqual(   R   R6   t   valuesR=   t   actual_valuesR>   (    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   assertSelectOptionsa   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_selectorR<   t   find(   R   R6   t   klass(    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   has_css_classl   s    (   t   __name__t
   __module__R   t   classmethodR   R   R   R"   R&   R4   R8   R?   RD   RI   (    (    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyR      s   

					N(
   t   django.testR    t   django.utils.importlibR   t   django.utils.unittestR   t   django.utils.translationR   R-   R   (    (    (    s3   ../Django//lib/python/django/contrib/admin/tests.pyt   <module>   s   