8
8
from django .utils .html import escape
9
9
from django .test import TestCase
10
10
from django .contrib .auth .models import User
11
- import mock
12
11
13
12
from .. import constants , scope
13
+
14
14
from ..compat import skipIfCustomUser
15
- from provider .constants import CONFIDENTIAL , READ
16
15
from ..templatetags .scope import scopes
17
16
from ..utils import now as date_now
18
17
from .forms import ClientForm
@@ -627,7 +626,7 @@ class AccessTokenDetailViewTests(TestCase):
627
626
def setUp (self ):
628
627
super (AccessTokenDetailViewTests , self )
629
628
self .
user = User .
objects .
create_user (
'TEST-USER' ,
'[email protected] ' )
630
- self .oauth_client = Client .objects .create (client_type = CONFIDENTIAL )
629
+ self .oauth_client = Client .objects .create (client_type = constants . CONFIDENTIAL )
631
630
632
631
def assert_invalid_token_response (self , token ):
633
632
""" Verifies that the view returns an invalid token response for the specified token. """
@@ -653,22 +652,18 @@ def test_invalid_token(self):
653
652
def test_valid_token (self ):
654
653
""" If the token is valid, details about the token should be returned. """
655
654
656
- expires = datetime . datetime ( 2016 , 1 , 1 , 0 , 0 , 0 )
657
- access_token = AccessToken . objects . create ( user = self . user , client = self . oauth_client , scope = READ , expires = expires )
655
+ access_token = AccessToken . objects . create ( user = self . user , client = self . oauth_client , scope = constants . READ ,
656
+ expires = datetime . datetime ( 2016 , 1 , 1 , 0 , 0 , 0 ) )
658
657
659
658
url = reverse ('oauth2:access_token_detail' , kwargs = {'token' : access_token .token })
660
659
661
- # Mock datetime.datetime.now() so that we can validate the expiration date
662
- now = datetime .datetime (2015 , 1 , 1 , 0 , 0 , 0 )
663
- with mock .patch ('provider.oauth2.models.now' , return_value = now ):
664
- response = self .client .get (url )
665
-
660
+ response = self .client .get (url )
666
661
self .assertEqual (response .status_code , 200 )
667
662
self .assertEqual (response ['Content-Type' ], self .JSON_CONTENT_TYPE )
668
663
669
664
expected = {
670
665
'username' : self .user .username ,
671
666
'scope' : 'read' ,
672
- 'expires_in ' : int (( expires - now ). total_seconds ())
667
+ 'expires ' : '2016-01-01T00:00:00'
673
668
}
674
669
self .assertEqual (response .content , json .dumps (expected ))
0 commit comments