ó
O'—^c           @  sq  d  d l  m Z y d  d l m Z Wn! e k
 rG d  d l m Z n Xd  d l 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 m Z m Z m Z d d
 l m Z e ƒ  Z e ƒ  Z d e f d „  ƒ  YZ e e j d k  d ƒ e
 d d ƒ d e f d „  ƒ  Yƒ ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literals(   t   skipIfN(   t   TestCase(   t   override_settings(   t   ValidationError(   t   timezonei   (   t   get_application_modelt   Grantt   AccessTokent   RefreshToken(   t   get_user_modelt
   TestModelsc           B  s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C  s   t  j j d d d ƒ |  _ d  S(   Nu	   test_useru   test@user.comu   123456(   t	   UserModelt   objectst   create_usert   user(   t   self(    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   setUp   s    c         C  s  |  j  j d d d d ƒ t j j d d d d d	 |  j d
 t j d t j ƒ } t d	 |  j d d d d d d d | ƒ } |  j	 | j
 d d g ƒ ƒ |  j	 | j
 d d g ƒ ƒ |  j	 | j
 d d d g ƒ ƒ |  j	 | j
 g  ƒ ƒ |  j | j
 d d g ƒ ƒ d  S(   Nt   usernameu	   test_usert   passwordu   123456t   nameu   test_appt   redirect_urisu5   http://localhost http://example.com http://example.itR   t   client_typet   authorization_grant_typet   scopeu
   read writet   expiresi    t   tokenu    t   applicationu   readu   writeu   destroy(   t   clientt   logint   ApplicationR   t   createR   t   CLIENT_CONFIDENTIALt   GRANT_AUTHORIZATION_CODER   t
   assertTruet   allow_scopest   assertFalse(   R   t   appt   access_token(    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   test_allow_scopes   s$    				c         C  sG   t  d d d d d |  j d t  j d t  j ƒ } |  j t | j ƒ d  S(   NR   u   test_appR   u    R   R   R   (   R   R   R    R!   t   assertRaisesR   t
   full_clean(   R   R%   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt+   test_grant_authorization_code_redirect_uris2   s    		c         C  sG   t  d d d d d |  j d t  j d t  j ƒ } |  j t | j ƒ d  S(   NR   u   test_appR   u    R   R   R   (   R   R   R    t   GRANT_IMPLICITR(   R   R)   (   R   R%   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt!   test_grant_implicit_redirect_uris=   s    		c      	   C  sb   t  d d d |  j d t  j d t  j ƒ } |  j d | | j ƒ d | _ |  j d | d ƒ d  S(   NR   u    R   R   R   u   %su   test_app(   R   R   R    R+   t   assertEqualt	   client_idR   (   R   R%   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   test_strH   s    			c         C  sâ   |  j  j d d d d ƒ t j j d d d d d	 |  j d
 t j d t j ƒ } t d	 |  j d d d d d d d | ƒ } t d	 |  j d d d d d d d | ƒ } |  j	 | j
 i d d 6d d 6ƒ |  j	 | j
 i d d 6ƒ d  S(   NR   u	   test_userR   u   123456R   u   test_appR   u5   http://localhost http://example.com http://example.itR   R   R   R   u
   read writeR   i    R   u    R   u   writeu   Reading scopeu   readu   Writing scope(   R   R   R   R   R   R   R    R!   R   R-   t   scopes(   R   R%   R&   t   access_token2(    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   test_scopes_propertyT   s*    						!(   t   __name__t
   __module__R   R'   R*   R,   R/   R2   (    (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR      s   					i   i   u2   Behavior is broken on 1.4 and there is no solutiont!   OAUTH2_PROVIDER_APPLICATION_MODELu   tests.TestApplicationt   TestCustomApplicationModelc           B  s   e  Z d  „  Z d „  Z RS(   c         C  s   t  j j d d d ƒ |  _ d  S(   Nu	   test_useru   test@user.comu   123456(   R   R   R   R   (   R   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR   v   s    c         C  s}   t  j d k  r t j ` n  g  t j j ƒ  D] } | j ^ q+ } |  j d | ƒ |  j d t  j d	 k  rn d n d | ƒ d S(
   uá   
        If a custom application model is installed, it should be present in
        the related objects and not the swapped out one.

        See issue #90 (https://github.com/evonove/django-oauth-toolkit/issues/90)
        i   i   u   oauth2_provider:applicationu   tests%stestapplicationu   :u   _N(   i   i   (   i   i   (	   t   djangot   VERSIONR   t   _metat   _related_objects_cachet   get_all_related_objectsR   t   assertNotInt   assertIn(   R   t   rot   related_object_names(    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   test_related_objectsy   s    %"(   R3   R4   R   R@   (    (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR6   s   s   	t   TestGrantModelc           B  s   e  Z d  „  Z d „  Z RS(   c         C  s*   t  d d ƒ } |  j d | | j ƒ d  S(   Nt   codeu	   test_codeu   %s(   R   R-   RB   (   R   t   grant(    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR/   ‹   s    c         C  s6   t  d d ƒ } |  j | j ƒ |  j | j ƒ  ƒ d  S(   NRB   u	   test_code(   R   t   assertIsNoneR   R"   t
   is_expired(   R   RC   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   test_expires_can_be_none   s    (   R3   R4   R/   RF   (    (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyRA   ‰   s   	t   TestAccessTokenModelc           B  s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C  s   t  j j d d d ƒ |  _ d  S(   Nu	   test_useru   test@user.comu   123456(   R   R   R   R   (   R   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR   –   s    c         C  s*   t  d d ƒ } |  j d | | j ƒ d  S(   NR   u
   test_tokenu   %s(   R   R-   R   (   R   R&   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR/   ™   s    c         C  sq   t  j j d d d d d |  j d t  j d t  j ƒ } t j j d d	 d
 | d t j ƒ  ƒ } |  j	 | j ƒ d  S(   NR   u   test_appR   u5   http://localhost http://example.com http://example.itR   R   R   R   u
   test_tokenR   R   (
   R   R   R   R   R    R!   R   R   t   nowRD   (   R   R%   R&   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   test_user_can_be_none   s    		'c         C  s6   t  d d ƒ } |  j | j ƒ |  j | j ƒ  ƒ d  S(   NR   u
   test_token(   R   RD   R   R"   RE   (   R   R&   (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyRF   ¨   s    (   R3   R4   R   R/   RI   RF   (    (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyRG   •   s   			t   TestRefreshTokenModelc           B  s   e  Z d  „  Z RS(   c         C  s*   t  d d ƒ } |  j d | | j ƒ d  S(   NR   u
   test_tokenu   %s(   R	   R-   R   (   R   t   refresh_token(    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyR/   °   s    (   R3   R4   R/   (    (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyRJ   ®   s   (   i   i   (   t
   __future__R    t   unittestR   t   ImportErrort   django.utils.unittest.caseR7   t   django.testR   t   django.test.utilsR   t   django.core.exceptionsR   t   django.utilsR   t   modelsR   R   R   R	   t   compatR
   R   R   R   R8   R6   RA   RG   RJ   (    (    (    sC   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_models.pyt   <module>   s(   "		]