ó
P'—^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  d l m Z m Z m Z m Z m Z m Z y d  d l Z Wn e k
 r§ d Z n Xd Z d	 e f d
 „  ƒ  YZ d S(   i    (   t   absolute_import(   t	   couchbase(   t   CouchBaseBackend(   t   ImproperlyConfigured(   t   backends(   t   AppCaset	   MagicMockt   Mockt   SkipTestt   patcht   sentinelNt   celery_buckett   test_CouchBaseBackendc           B@  sn   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 d
 „ Z d „  Z RS(   c         C@  s4   t  d  k r t d ƒ ‚ n  t d |  j ƒ |  _ d  S(   Ns   couchbase is not installed.t   app(   R   t   NoneR   R   R   t   backend(   t   self(    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   setup   s    c         C@  sN   t  j d } t  _ z* |  j t ƒ  t d |  j ƒ Wd QXWd | t  _ Xd S(   s   test init no couchbase raisesR   N(   t   moduleR   R   t   assertRaisesR   R   R   (   R   t   prev(    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_init_no_couchbase   s
    c         C@  s9   g  |  j  j _ |  j t ƒ  t d |  j  ƒ Wd QXd S(   s   test init no settingsR   N(   R   t   conft!   CELERY_COUCHBASE_BACKEND_SETTINGSR   R   R   (   R   (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_init_no_settings#   s    c         C@  s#   d |  j j _ t d |  j ƒ d S(   s   Test init settings is NoneR   N(   R   R   R   R   R   (   R   (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_init_settings_is_None)   s    c         C@  sZ   t  d ƒ H } t j |  j _ |  j j ƒ  } |  j t j | ƒ |  j | j ƒ Wd  QXd  S(   Ns   couchbase.connection.Connection(   R	   R
   t   _connectionR   t   _get_connectiont   assertEqualt   assertFalset   called(   R   t   mock_Connectiont
   connection(    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt%   test_get_connection_connection_exists.   s
    c         C@  s‚   i  |  j  j _ t d |  j  ƒ } t ƒ  | _ t ƒ  } | j _ t j | j	 _
 |  j | j d ƒ t j ƒ | j j j d ƒ d S(   s¦   test_get

        CouchBaseBackend.get should return  and take two params
        db conn to couchbase is mocked.
        TODO Should test on key not exists

        R   t   1f3fabN(   R   R   R   R   R   R   t   getR
   t   retvalt   return_valuet   valueR   t   assert_called_once_with(   R   t   xt
   mocked_get(    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_get7   s    c         C@  s_   d |  j j _ t d |  j ƒ } t ƒ  | _ t ƒ  | j _ |  j | j t	 j
 t	 j ƒ ƒ d S(   s   test_set

        CouchBaseBackend.set should return None and take two params
        db conn to couchbase is mocked.

        R   N(   R   R   R   R   R   R   R   t   sett   assertIsNoneR
   t   keyR&   (   R   R(   (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_setH   s
    c         C@  sv   i  |  j  j _ t d |  j  ƒ } t ƒ  | _ t ƒ  } | j _ d | _ |  j	 | j d ƒ ƒ | j j j
 d ƒ d S(   s«   test_delete

        CouchBaseBackend.delete should return and take two params
        db conn to couchbase is mocked.
        TODO Should test on key not exists

        R   R"   N(   R   R   R   R   R   R   t   deleteR   R%   R,   R'   (   R   R(   t   mocked_delete(    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_deleteV   s    	c         C@  s³   i d d 6d d g d 6d d 6d d	 6d
 d 6|  j  j _ t d |  j  ƒ } |  j | j d ƒ |  j | j d d g ƒ |  j | j d ƒ |  j | j d ƒ |  j | j	 d ƒ d S(   sb   test_config_params

        celery.conf.CELERY_COUCHBASE_BACKEND_SETTINGS is properly set
        t   mycoolbuckett   buckets   here.host.coms   there.host.comt   hostt   johndoet   usernamet   mysecrett   passwordt   1234t   portR   iÒ  N(
   R   R   R   R   R   R3   R4   R6   R8   R:   (   R   R(   (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_config_paramsg   s    s   couchbase://myhost/mycoolbucketc         C@  sR   d d l  m } t j | |  j j ƒ \ } } |  j | | ƒ |  j | | ƒ d  S(   Ni    (   R   (   t   celery.backends.couchbaseR   R   t   get_backend_by_urlR   t   loadert   assertIsR   (   R   t   urlR   R   t   url_(    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_backend_by_urlz   s    c         C@  s   d } |  j  d | ƒ o } | j } |  j | j d ƒ |  j | j d ƒ |  j | j d ƒ |  j | j d ƒ |  j | j d ƒ Wd  QXd  S(   Ns4   couchbase://johndoe:mysecret@myhost:123/mycoolbucketR   R2   t   myhostR5   R7   i{   (   t   CeleryR   R   R3   R4   R6   R8   R:   (   R   R@   R   R(   (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   test_backend_params_by_url€   s    	(   t   __name__t
   __module__R   R   R   R   R!   R*   R.   R1   R;   RB   RE   (    (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyR      s   											(   t
   __future__R    t   celery.backendsR   R   R<   R   t   celery.exceptionsR   t   celeryR   t   celery.tests.caseR   R   R   R   R	   R
   t   ImportErrorR   t   COUCHBASE_BUCKETR   (    (    (    sF   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/backends/test_couchbase.pyt   <module>   s   .
