ó
žA/Mc        
   @   sX  d  Z  e Z d d d d d d d d d	 d
 g
 Z d d l m Z d d l Z d d l m Z d d l	 m
 Z
 m Z m Z e ƒ  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d „  ƒ Z d d  d „  ƒ  YZ d d! d „  ƒ  YZ d d" d „  ƒ  YZ d d# d „  ƒ  YZ e d d ƒ Z e d d ƒ Z e d d ƒ Z d S($   s   launchpadlib testing helpers.t   BadSaveKeyringt   fake_keyringt   FauxSocketModulet   InMemoryKeyringt   NoNetworkAuthorizationEnginet   NoNetworkLaunchpadt   TestableLaunchpadt   nopriv_read_nonprivatet   salgado_read_nonprivatet   salgado_with_full_permissionsiÿÿÿÿ(   t   contextmanagerN(   t	   Launchpad(   t   AccessTokent   Credentialst   RequestTokenAuthorizationEnginec           C   s(   t  t j d t ƒ t k s$ t d ‚ d  S(   Nt   keyrings>   During tests the real keyring module should never be imported.(   t   getattrt   launchpadlibt   credentialst   missingt   AssertionError(    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   assert_keyring_not_imported2   s    c           B   s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   s  An authorization engine that doesn't open a web browser.

    You can use this to test the creation of Launchpad objects and the
    storing of credentials. You can't use it to interact with the web
    service, since it only pretends to authorize its OAuth request tokens.
    s   access_key:84c         O   s/   t  t |  ƒ j | | Ž  d |  _ d |  _ d  S(   Ni    (   t   superR   t   __init__t   request_tokens_obtainedt   access_tokens_obtained(   t   selft   argst   kwargs(    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   @   s    	c         C   s   |  j  d 7_  d S(   ss   Pretend to get a request token from the server.

        We do this by simply returning a static token ID.
        i   s   request_token:42(   R   (   R   R   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   get_request_tokenF   s    c         C   s(   t  |  j d ƒ | _ |  j d 7_ d S(   s‚   Pretend to exchange a request token for an access token.

        We do this by simply setting the access_token property.
        s   access_secret:168i   N(   R   t   ACCESS_TOKEN_KEYt   access_tokenR   (   R   R   t   request_token(    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   make_end_user_authorize_tokenN   s    (   t   __name__t
   __module__t   __doc__R   R   R   R!   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   7   s
   		c           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   s²   A Launchpad instance for tests with no network access.

    It's only useful for making sure that certain methods were called.
    It can't be used to interact with the API.
    c	   	      C   sI   | |  _  | |  _ | |  _ t d | d | d | d | d | ƒ |  _ d  S(   Nt   service_roott   cachet   timeoutt
   proxy_infot   version(   R   t   authorization_enginet   credential_storet   dictt   passed_in_args(	   R   R   R*   R+   R%   R&   R'   R(   R)   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   _   s    			c         G   s
   t  | Œ  S(   N(   R   (   t   clsR   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   authorization_engine_factoryh   s    (   R"   R#   R$   R   t   classmethodR/   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   X   s   		c           B   s/   e  Z d  Z d d d d d d e j d „ Z RS(   s5   A base class for talking to the testing root service.t   test_devc	   	      C   s>   t  t |  ƒ j | | | d | d | d | d | d | ƒd S(   s\  Provide test-friendly defaults.

        :param authorization_engine: Defaults to None, since a test
            environment can't use an authorization engine.
        :param credential_store: Defaults to None, since tests
            generally pass in fully-formed Credentials objects.
        :param service_root: Defaults to 'test_dev'.
        R%   R&   R'   R(   R)   N(   R   R   R   (	   R   R   R*   R+   R%   R&   R'   R(   R)   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   p   s    N(   R"   R#   R$   t   NoneR   t   DEFAULT_VERSIONR   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   m   s
   	c         c   s-   t  ƒ  |  t j _ z	 d VWd t j ` Xd S(   sA   A context manager which injects a testing keyring implementation.N(   R   R   R   R   (   t   fake(    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   ‚   s
    	c           B   s   e  Z d  Z d „  Z RS(   s:   A socket module replacement that provides a fake hostname.c         C   s   d S(   Nt   HOSTNAME(    (   R   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   gethostname‘   s    (   R"   R#   R$   R6   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   Ž   s   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s6   A keyring that generates errors when saving passwords.c         C   s   d  S(   N(   R2   (   R   t   servicet   username(    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   get_password˜   s    c         C   s
   t  ‚ d  S(   N(   t   RuntimeError(   R   R7   R8   t   password(    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   set_password›   s    (   R"   R#   R$   R9   R<   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR    •   s   	c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s.   A keyring that saves passwords only in memory.c         C   s   i  |  _  d  S(   N(   t   data(   R   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   ¢   s    c         C   s   | |  j  | | f <d  S(   N(   R=   (   R   R7   R8   R;   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR<   ¥   s    c         C   s   |  j  j | | f ƒ S(   N(   R=   t   get(   R   R7   R8   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR9   ¨   s    (   R"   R#   R$   R   R<   R9   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   Ÿ   s   		t   KnownTokensc           B   s/   e  Z d  Z d „  Z d d d e j d „ Z RS(   s'   Known access token/secret combinations.c         C   sC   | |  _  | |  _ t | | ƒ |  _ t d d d |  j ƒ |  _ d  S(   Nt   consumer_names   launchpad-libraryR   (   t   token_stringt   access_secretR   t   tokenR   R   (   R   RA   RB   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR   ¯   s
    		c      
   C   s%   t  |  j d | d | d | d | ƒS(   s2   Create a Launchpad object using these credentials.R&   R'   R(   R)   (   R   R   (   R   R&   R'   R(   R)   (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   login¶   s    N(   R"   R#   R$   R   R2   R   R3   RD   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyR?   ¬   s   		s   salgado-change-anythingt   tests   salgado-read-nonprivatet   secrets   nopriv-read-nonprivatet   mystery(    (    (    (    (   R$   t   typet   __metaclass__t   __all__t
   contextlibR
   R   t   launchpadlib.launchpadR   t   launchpadlib.credentialsR   R   R   t   objectR   R   R   R   R   R   R   R    R   R?   R	   R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/launchpadlib/testing/helpers.pyt   <module>   s8   			!
