ó
O'—^c           @  s  d  d l  m 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 d d l m Z d d	 l m Z d
 d l m Z e	 ƒ  Z e ƒ  Z d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   TestCaset   RequestFactory(   t   reversei   (   t   get_application_model(   t   oauth2_settings(   t   ProtectedResourceView(   t   get_user_modeli   (   t   TestCaseUtilst   ResourceViewc           B  s   e  Z d  „  Z RS(   c         O  s   d S(   Nu   This is a protected resource(    (   t   selft   requestt   argst   kwargs(    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt   get   s    (   t   __name__t
   __module__R   (    (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyR	      s   t   BaseTestc           B  s   e  Z d  „  Z d „  Z RS(   c      	   C  sž   t  ƒ  |  _ t j j d d d ƒ |  _ t j j d d d ƒ |  _ t d d d |  j d	 t j d
 t j	 ƒ |  _
 |  j
 j ƒ  d d g t _ d d g t _ d  S(   Nu	   test_useru   test@user.comu   123456u   dev_useru   dev@user.comt   nameu   Test Password Applicationt   usert   client_typet   authorization_grant_typeu   readu   write(   R   t   factoryt	   UserModelt   objectst   create_usert	   test_usert   dev_usert   Applicationt   CLIENT_PUBLICt   GRANT_PASSWORDt   applicationt   saveR   t   _SCOPESt   _DEFAULT_SCOPES(   R
   (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt   setUp   s    		c         C  s+   |  j  j ƒ  |  j j ƒ  |  j j ƒ  d  S(   N(   R   t   deleteR   R   (   R
   (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt   tearDown*   s    (   R   R   R#   R%   (    (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyR      s   	t   TestPasswordTokenViewc           B  s   e  Z d  „  Z d „  Z RS(   c         C  sË   i d d 6d d 6d d 6} |  j  |  j j |  j j ƒ } |  j j t d ƒ d | | } |  j | j d ƒ t	 j
 | j j d	 ƒ ƒ } |  j | d
 d ƒ |  j | d d ƒ |  j | d t j ƒ d S(   uL   
        Request an access token using Resource Owner Password Flow
        u   passwordu
   grant_typeu	   test_useru   usernameu   123456u   oauth2_provider:tokent   dataiÈ   u   utf-8u
   token_typeu   Beareru   scopeu
   read writeu
   expires_inN(   t   get_basic_auth_headerR   t	   client_idt   client_secrett   clientt   postR   t   assertEqualt   status_codet   jsont   loadst   contentt   decodeR   t   ACCESS_TOKEN_EXPIRE_SECONDS(   R
   t   token_request_datat   auth_headerst   responseR1   (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt   test_get_token1   s    
!c         C  sq   i d d 6d d 6d d 6} |  j  |  j j |  j j ƒ } |  j j t d ƒ d | | } |  j | j d ƒ d	 S(
   uL   
        Request an access token using Resource Owner Password Flow
        u   passwordu
   grant_typeu	   test_useru   usernameu   NOT_MY_PASSu   oauth2_provider:tokenR'   i‘  N(	   R(   R   R)   R*   R+   R,   R   R-   R.   (   R
   R4   R5   R6   (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt   test_bad_credentialsD   s    
!(   R   R   R7   R8   (    (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyR&   0   s   	t   TestPasswordProtectedResourcec           B  s   e  Z d  „  Z RS(   c         C  sÝ   i d d 6d d 6d d 6} |  j  |  j j |  j j ƒ } |  j j t d ƒ d | | } t j | j	 j
 d ƒ ƒ } | d	 } i d
 | d 6} |  j j d |  } |  j | _ t j ƒ  } | | ƒ } |  j | d ƒ d  S(   Nu   passwordu
   grant_typeu	   test_useru   usernameu   123456u   oauth2_provider:tokenR'   u   utf-8u   access_tokenu   Bearer u   HTTP_AUTHORIZATIONu   /fake-resourceu   This is a protected resource(   R(   R   R)   R*   R+   R,   R   R/   R0   R1   R2   R   R   R   R   R	   t   as_viewR-   (   R
   R4   R5   R6   R1   t   access_tokenR   t   view(    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt%   test_password_resource_access_allowedT   s    
!
(   R   R   R=   (    (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyR9   S   s   (   t
   __future__R    R/   t   django.testR   R   t   django.core.urlresolversR   t   modelsR   t   settingsR   t   viewsR   t   compatR   t
   test_utilsR   R   R   R	   R   R&   R9   (    (    (    sE   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_password.pyt   <module>   s   		#