ó
ãr$Mc           @   s«   d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d d l m Z m	 Z	 m
 Z
 m Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   s'   Tests for the credential store classes.iÿÿÿÿN(   t   fake_keyringt   InMemoryKeyring(   t   AccessTokent   Credentialst   KeyringCredentialStoret   UnencryptedFileCredentialStoret   CredentialStoreTestCasec           B   s   e  Z d  „  Z RS(   c         C   s   t  d d d d t | d ƒ ƒS(   s(   Helper method to make a fake credential.s   app namet   consumer_secrets   consumer_secret:42t   access_tokens   access_secret:168(   R   R   (   t   selft   consumer_key(    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   make_credential&   s    (   t   __name__t
   __module__R   (    (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyR   $   s   t"   TestUnencryptedFileCredentialStorec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s3   Tests for the UnencryptedFileCredentialStore class.c         C   s+   t  j ƒ  \ } |  _ t |  j ƒ |  _ d  S(   N(   t   tempfilet   mkstempt   filenameR   t   store(   R	   t   ignore(    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   setUp0   s    c         C   s,   t  j j |  j ƒ r( t  j |  j ƒ n  d  S(   N(   t   ost   patht   existsR   t   remove(   R	   (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   tearDown4   s    c         C   sT   |  j  d ƒ } |  j j | d ƒ |  j j d ƒ } |  j | j j | j j ƒ d  S(   Ns   consumer keys
   unique key(   R   R   t   savet   loadt   assertEqualst   consumert   key(   R	   t
   credentialt   credential2(    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   test_save_and_load8   s    c         C   sT   |  j  d ƒ } |  j j | d ƒ |  j j d ƒ } |  j | j j | j j ƒ d  S(   Ns   consumer keys   some keys   some other key(   R   R   R   R   R   R   R   (   R	   R   R    (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   test_unique_id_doesnt_matter?   s    c         C   sv   |  j  d ƒ } |  j  d ƒ } |  j j | d ƒ |  j j | d ƒ |  j j d ƒ } |  j | j j | j j ƒ d  S(   Ns   consumer keys   consumer key2s   unique key 1s   unique key 2(   R   R   R   R   R   R   R   (   R	   t   credential1R    t   loaded(    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt&   test_file_only_contains_one_credentialG   s    (   R   R   t   __doc__R   R   R!   R"   R%   (    (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyR   -   s   				t   TestKeyringCredentialStorec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s+   Tests for the KeyringCredentialStore class.c         C   s   t  ƒ  |  _ t ƒ  |  _ d  S(   N(   R   t   keyringR   R   (   R	   (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyR   W   s    c         C   sj   t  |  j ƒ U |  j d ƒ } |  j j | d ƒ |  j j d ƒ } |  j | j j | j j ƒ Wd  QXd  S(   Ns   consumer keys
   unique key(	   R    R(   R   R   R   R   R   R   R   (   R	   R   R    (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyR!   [   s    c         C   sº   t  |  j ƒ ¥ |  j d ƒ } |  j j | d ƒ |  j d ƒ } |  j j | d ƒ |  j j d ƒ } |  j | j j | j j ƒ |  j j d ƒ } |  j | j j | j j ƒ Wd  QXd  S(   Ns   consumer key1s   key 1s   consumer key2s   key 2(	   R    R(   R   R   R   R   R   R   R   (   R	   R#   R    t   loaded1t   loaded2(    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   test_lookup_by_unique_keyd   s    c         C   sŒ   t  |  j ƒ w |  j d ƒ } |  j j | d ƒ |  j d ƒ } |  j j | d ƒ |  j j d ƒ } |  j | j j | j j ƒ Wd  QXd  S(   Ns   consumer key1s   the only keys   consumer key2(	   R    R(   R   R   R   R   R   R   R   (   R	   R#   R    R$   (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt/   test_reused_unique_id_overwrites_old_credentialv   s    c         C   s6   t  |  j ƒ ! |  j d  |  j j d ƒ ƒ Wd  QXd  S(   Ns   no such key(   R    R(   R   t   NoneR   R   (   R	   (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   test_bad_unique_id_returns_none…   s    (   R   R   R&   R   R!   R+   R,   R.   (    (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyR'   T   s   					(   R&   R   R   t   unittestt   launchpadlib.testing.helpersR    R   t   launchpadlib.credentialsR   R   R   R   t   TestCaseR   R   R'   (    (    (    sL   /usr/lib/python2.7/dist-packages/launchpadlib/tests/test_credential_store.pyt   <module>   s   "	'