ó
O'—^c        	   @   sU  d  d l  m Z d  d l m Z m Z m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z y d  d l
 m Z Wn e k
 r d  d l Z n Xd d	 l m Z d
 d l m Z m Z d
 d l m Z d
 d l m Z e ƒ  Z e ƒ  Z y d  d l m Z d  d l m Z d
 d l m Z m Z 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 e# f d „  ƒ  YZ& e d e d e d ƒ ƒ e d e# j' ƒ  ƒ e d e$ j' ƒ  ƒ e d  e% j' ƒ  ƒ e d! e& j' ƒ  ƒ ƒ Z( e) Z* Wn e k
 r!e+ Z* n Xd" e e	 f d# „  ƒ  YZ, d$ e, f d% „  ƒ  YZ- d S(&   iÿÿÿÿ(   t	   timedelta(   t   patternst   urlt   include(   t   HttpResponse(   t   TestCase(   t   timezone(   t   unittestNi   (   t   TestCaseUtilsi   (   t   AccessTokent   get_application_model(   t   oauth2_settings(   t   get_user_model(   t   permissions(   t   APIView(   t   OAuth2Authenticationt   TokenHasScopet   TokenHasReadWriteScopet   TokenHasResourceScopet   MockViewc           B   s&   e  Z e j f Z d  „  Z d „  Z RS(   c         C   s   t  i d d 6d d 6d d 6ƒ S(   Ni   t   ai   t   bi   t   c(   R   (   t   selft   request(    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   get   s    c         C   s   t  i d d 6d d 6d d 6ƒ S(   Ni   R   i   R   i   R   (   R   (   R   R   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   post"   s    (   t   __name__t
   __module__R   t   IsAuthenticatedt   permission_classesR   R   (    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR      s   	t
   OAuth2Viewc           B   s   e  Z e g Z RS(    (   R   R   R   t   authentication_classes(    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR   %   s   t
   ScopedViewc           B   s    e  Z e j e g Z d  g Z RS(   t   scope1(   R   R   R   R   R   R   t   required_scopes(    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR!   (   s   t   ReadWriteScopedViewc           B   s   e  Z e j e g Z RS(    (   R   R   R   R   R   R   (    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR$   ,   s   t   ResourceScopedViewc           B   s    e  Z e j e g Z d  g Z RS(   t	   resource1(   R   R   R   R   R   R   R#   (    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR%   /   s   t    s   ^oauth2/s   oauth2_provider.urlss   ^oauth2-test/$s   ^oauth2-scoped-test/$s   ^oauth2-read-write-test/$s   ^oauth2-resource-scoped-test/$t   BaseTestc           B   s   e  Z d  Z RS(   s   
    TODO: add docs
    (   R   R   t   __doc__(    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR(   A   s   t   TestOAuth2Authenticationc           B   sd  e  Z d  Z d „  Z d „  Z e j e d ƒ d „  ƒ Z e j e d ƒ d „  ƒ Z	 e j e d ƒ d „  ƒ Z
 e j e d ƒ d „  ƒ Z e j e d ƒ d „  ƒ Z e j e d ƒ d	 „  ƒ Z e j e d ƒ d
 „  ƒ Z e j e d ƒ d „  ƒ Z e j e d ƒ d „  ƒ Z e j e d ƒ d „  ƒ Z e j e d ƒ d „  ƒ Z e j e d ƒ d „  ƒ Z RS(   s)   oauth2_provider.tests.test_rest_frameworkc         C   sÔ   d d d d d g t  _ t j j d d d ƒ |  _ t j j d	 d
 d ƒ |  _ t j j d d d d d |  j d t j	 d t j
 ƒ |  _ t j j d |  j d d d t j ƒ  t d d ƒ d d d |  j ƒ |  _ d  S(   Nt   readt   writeR"   t   scope2R&   t	   test_users   test@user.comt   123456t   dev_users   dev@user.comt   names   Test Applicationt   redirect_uriss5   http://localhost http://example.com http://example.itt   usert   client_typet   authorization_grant_typet   scopes
   read writet   expirest   secondsi,  t   tokens   secret-access-token-keyt   application(   R   t   _SCOPESt	   UserModelt   objectst   create_userR.   R0   t   Applicationt   createt   CLIENT_CONFIDENTIALt   GRANT_AUTHORIZATION_CODER:   R	   R   t   nowR    t   access_token(   R   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   setUpK   s    			c         C   s   d j  | ƒ S(   Ns
   Bearer {0}(   t   format(   R   R9   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   _create_authorization_headera   s    s!   djangorestframework not installedc         C   sD   |  j  |  j j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   Ns   /oauth2-test/t   HTTP_AUTHORIZATIONiÈ   (   RG   RD   R9   t   clientR   t   assertEqualt   status_code(   R   t   autht   response(    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   test_authentication_allowd   s    c         C   s>   |  j  d ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   Ns
   fake-tokens   /oauth2-test/RH   i‘  (   RG   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   test_authentication_deniedj   s    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   NR"   s   /oauth2-scoped-test/RH   iÈ   (	   RD   R6   t   saveRG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   test_scoped_permission_allowp   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   NR-   s   /oauth2-scoped-test/RH   i“  (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   test_scoped_permission_denyy   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   NR+   s   /oauth2-read-write-test/RH   iÈ   (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt$   test_read_write_permission_get_allow‚   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   NR,   s   /oauth2-read-write-test/RH   iÈ   (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt%   test_read_write_permission_post_allow‹   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   NR,   s   /oauth2-read-write-test/RH   i“  (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt#   test_read_write_permission_get_deny”   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   NR+   s   /oauth2-read-write-test/RH   i“  (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt$   test_read_write_permission_post_deny   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   Ns   resource1:reads   /oauth2-resource-scoped-test/RH   iÈ   (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt)   test_resource_scoped_permission_get_allow¦   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   Ns   resource1:writes   /oauth2-resource-scoped-test/RH   iÈ   (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt*   test_resource_scoped_permission_post_allow¯   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   Ns   resource1:writes   /oauth2-resource-scoped-test/RH   i“  (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt*   test_resource_scoped_permission_get_denied¸   s
    c         C   s]   d |  j  _ |  j  j ƒ  |  j |  j  j ƒ } |  j j d d | ƒ} |  j | j d ƒ d  S(   Ns   resource1:reads   /oauth2-resource-scoped-test/RH   i“  (	   RD   R6   RP   RG   R9   RI   R   RJ   RK   (   R   RL   RM   (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt+   test_resource_scoped_permission_post_deniedÁ   s
    (   R   R   t   urlsRE   RG   R   t
   skipUnlesst   rest_framework_installedRN   RO   RQ   RR   RS   RT   RU   RV   RW   RX   RY   RZ   (    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyR*   H   s   											(.   t   datetimeR    t   django.conf.urlsR   R   R   t   django.httpR   t   django.testR   t   django.utilsR   R   t   ImportErrort
   test_utilsR   t   modelsR	   R
   t   settingsR   t   compatR   R?   R<   t   rest_frameworkR   t   rest_framework.viewsR   t   ext.rest_frameworkR   R   R   R   R   R   R!   R$   R%   t   as_viewt   urlpatternst   TrueR]   t   FalseR(   R*   (    (    (    sK   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_rest_framework.pyt   <module>   sF   		"	

