ó
O'^c           @   sĄ   d  d l  Z  d  d l Z d  d l m Z m Z d  d l m Z d d l m Z d d l	 m
 Z
 m Z d e f d     YZ d	 e f d
     YZ d e f d     YZ d e f d     YZ d S(   i’’’’N(   t   TestCaset   RequestFactory(   t   override_settingsi   (   t   get_oauthlib_core(   t   OAuthLibCoret   JSONOAuthLibCoret   TestOAuthLibCoreBackendc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   t    |  _ t   |  _ d  S(   N(   R   t   factoryR   t   oauthlib_core(   t   self(    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt   setUp   s    c         C   s?   t  j d  * t   } |  j t | j t  j   Wd  QXd  S(   NsC   oauth2_provider.oauth2_backends.oauth2_settings.OAUTH2_SERVER_CLASS(   t   mockt   patchR   t
   assertTruet
   isinstancet   servert	   MagicMock(   R	   R   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt   test_swappable_serer_class   s    	c         C   ss   d } |  j  j d | d d } |  j j |  \ } } } } |  j d |  |  j d |  |  j d |  d  S(   Ns1   grant_type=password&username=john&password=123456s	   /o/token/t   content_types!   application/x-www-form-urlencodeds   grant_type=passwords   username=johns   password=123456(   R   t   postR   t   _extract_paramst   assertIn(   R	   t   payloadt   requestt   urit   http_methodt   bodyt   headers(    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt#   test_form_urlencoded_extract_params   s    c         C   s   t  j i d d 6d d 6d d 6 } |  j j d | d d } |  j j |  \ } } } } |  j d	 |  |  j d
 |  |  j d |  d  S(   Nt   passwordt
   grant_typet   johnt   usernamet   123456s	   /o/token/R   s   application/jsons   grant_type=passwords   username=johns   password=123456(   t   jsont   dumpsR   R   R   R   t   assertNotIn(   R	   R   R   R   R   R   R   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt$   test_application_json_extract_params   s    	(   t   __name__t
   __module__R
   R   R   R%   (    (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR      s   				t   TestCustomOAuthLibCoreBackendc           B   s6   e  Z d  Z d e f d     YZ d   Z d   Z RS(   sr   
    Tests that the public API behaves as expected when we override
    the OAuthLibCoreBackend core methods.
    t   MyOAuthLibCorec           B   s   e  Z d    Z RS(   c         C   s   d S(   Ni   (    (   R	   R   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt   _get_extra_credentials3   s    (   R&   R'   R*   (    (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR)   2   s   c         C   s   t    |  _ d  S(   N(   R   R   (   R	   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR
   6   s    c         C   s   d } |  j  j d | d d } t j d  \ } t j   } | | | f | _ |  j   } | j |  |  j | j	 d d d k  Wd	 QXd	 S(
   sS   
        Make sures that extra_credentials parameter is passed to oauthlib
        s1   grant_type=password&username=john&password=123456s	   /o/token/R   s!   application/x-www-form-urlencodeds,   oauthlib.oauth2.Server.create_token_responsei    i   i   N(
   R   R   R   R   R   t   return_valueR)   t   create_token_responseR   t	   call_args(   R	   R   R   R,   t   mockedt   core(    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt1   test_create_token_response_gets_extra_credentials9   s    (   R&   R'   t   __doc__R   R)   R
   R0   (    (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR(   -   s   	t   TestJSONOAuthLibCoreBackendc           B   s   e  Z d    Z d   Z RS(   c         C   s   t    |  _ t   |  _ d  S(   N(   R   R   R   R   (   R	   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR
   I   s    c         C   s   t  j i d d 6d d 6d d 6 } |  j j d | d d } |  j j |  \ } } } } |  j d	 |  |  j d
 |  |  j d |  d  S(   NR   R   R   R    R!   s	   /o/token/R   s   application/jsons   grant_type=passwords   username=johns   password=123456(   R"   R#   R   R   R   R   R   (   R	   R   R   R   R   R   R   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR%   M   s    	(   R&   R'   R
   R%   (    (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR2   H   s   	t   TestOAuthLibCorec           B   s   e  Z d    Z d   Z RS(   c         C   s   t    |  _ d  S(   N(   R   R   (   R	   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR
   \   s    c         C   sF   i d d d 6} |  j  j d |  } t   } | j | d g  d  S(   Ns   Bearer t   a_casual_tokent   HTTP_AUTHORIZATIONs   /fake-resource?next=/faket   scopes(   R   t   getR   t   verify_request(   R	   t   auth_headersR   R   (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt0   test_validate_authorization_request_unsafe_query_   s
    	(   R&   R'   R
   R:   (    (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyR3   [   s   	(   R"   R   t   django.testR    R   t   django.test.utilsR   t   backendsR   t   oauth2_backendsR   R   R   R(   R2   R3   (    (    (    sL   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_oauth2_backends.pyt   <module>   s   "