î
Þ^Q\œ  ã               @   s	  d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z y d d l	 m
 Z
 Wn" e k
 r† d d l m
 Z
 Yn Xd d l m Z d d l m Z d a Gd	 d
 „  d
 e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d S)z+Test case for autocomplete implementations.é    N)ÚVERSION)ÚContentType)ÚStaticLiveServerTestCase)Úreverse)Úsix)ÚBrowserc                   sj   e  Z d  Z d Z e ‡  f d d †  ƒ Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z	 d d „  Z
 ‡  S)ÚAutocompleteTestCasez<Provide a class-persistent selenium instance and assertions.c                sJ   t  d k r* t t j j d d ƒ ƒ a  n  t  |  _ t t |  ƒ j ƒ  d S)z1Instanciate a browser for the whole test session.NZBROWSERZfirefox)	ÚGLOBAL_BROWSERr   ÚosÚenvironÚgetÚbrowserÚsuperr   Ú
setUpClass)Úcls)Ú	__class__© úB/var/www/dbchiro/venv/lib/python3.4/site-packages/dal/test/case.pyr      s    	zAutocompleteTestCase.setUpClassc             C   sY   |  j  j d |  j | f ƒ d |  j  j k rK |  j  j d ƒ j j ƒ  n  |  j ƒ  d S)zOpen a URL.z%s%sz/admin/login/zLog inN)r   ÚvisitZlive_server_urlÚurlZfind_by_valueÚfirstÚclickZwait_script)Úselfr   r   r   r   r   #   s    zAutocompleteTestCase.getc             C   s   |  j  j | ƒ j j ƒ  d S)z!Click an element by css selector.N)r   Úfind_by_cssr   r   )r   Úselectorr   r   r   r   2   s    zAutocompleteTestCase.clickc             C   s8   d |  j  j | ƒ j _ |  j  j | ƒ j j | ƒ d S)z)Enter text in an element by css selector.Ú N)r   r   r   ÚvalueÚtype)r   r   Útextr   r   r   Ú
enter_text6   s    zAutocompleteTestCase.enter_textc             C   s5   |  j  j | ƒ } | s1 | j j d k s1 t ‚ d S)z1Assert an element is not visible by css selector.FN)r   r   r   ÚvisibleÚAssertionError)r   r   Úer   r   r   Úassert_not_visible;   s    z'AutocompleteTestCase.assert_not_visiblec             C   s.   |  j  j | ƒ j } | j d k s* t ‚ d S)z-Assert an element is visible by css selector.TN)r   r   r   r    r!   )r   r   r"   r   r   r   Úassert_visible@   s    z#AutocompleteTestCase.assert_visible)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   r   r   r   r#   r$   r   r   )r   r   r      s   r   c               @   s.   e  Z d  Z d Z d d „  Z d d „  Z d S)Ú
AdminMixinz1Mixin for tests that should happen in ModelAdmin.c             K   s/   t  d |  j j j |  j j j | f d | ƒS)z/Return a modeladmin url for a model and action.zadmin:%s_%s_%sÚkwargs)r   ÚmodelZ_metaZ	app_labelZ
model_name)r   Úactionr+   r   r   r   Úget_modeladmin_urlI   s
    
zAdminMixin.get_modeladmin_urlc             C   sS   |  j  ƒ  } t t | ƒ ƒ } | | d … | d | … } |  j j d | ƒ d S)zFill in the name input.NÚname)ÚidÚintÚlenr   Úfill)r   ÚiZhalfZnot_idr   r   r   Ú	fill_nameQ   s    zAdminMixin.fill_nameN)r%   r&   r'   r(   r.   r5   r   r   r   r   r*   F   s   r*   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚOptionMixinz'Mixin to make a unique option per test.c             C   sX   t  j t j ƒ  ƒ } t d k  r6 | j d d ƒ } n  |  j j j d | ƒ \ } } | S)z8Create a unique option from self.model into self.option.é   é
   ú-r   r/   )r7   r8   )	r   Z	text_typeÚuuidZuuid1r   Úreplacer,   ÚobjectsZget_or_create)r   Zunique_nameÚoptionÚcreatedr   r   r   Úcreate_option\   s    zOptionMixin.create_optionN)r%   r&   r'   r(   r?   r   r   r   r   r6   Y   s   r6   c                   s(   e  Z d  Z d Z ‡  f d d †  Z ‡  S)ÚContentTypeOptionMixinz(Same as option mixin, with content type.c                s1   t  t |  ƒ j ƒ  } t j j | ƒ } | | f S)zReturn option, content type.)r   r@   r?   r   r<   Zget_for_model)r   r=   Úctype)r   r   r   r?   l   s    z$ContentTypeOptionMixin.create_option)r%   r&   r'   r(   r?   r   r   )r   r   r@   i   s   r@   )r(   r
   r:   Zdjangor   Z"django.contrib.contenttypes.modelsr   Z"django.contrib.staticfiles.testingr   Zdjango.urlsr   ÚImportErrorZdjango.core.urlresolversZdjango.utilsr   Zsplinterr   r	   r   Úobjectr*   r6   r@   r   r   r   r   Ú<module>   s    1