1
- from datetime import datetime as dt
2
-
3
1
import pytest
4
2
from django .contrib .auth import get_user_model
5
3
from django .core .exceptions import ImproperlyConfigured , ValidationError
@@ -305,23 +303,23 @@ def setUp(self):
305
303
AccessToken .objects .create (
306
304
id = 1 ,
307
305
token = "555" ,
308
- expires = dt .now (),
306
+ expires = timezone .now (),
309
307
scope = 2 ,
310
308
application_id = 3 ,
311
309
user_id = 1 ,
312
- created = dt .now (),
313
- updated = dt .now (),
310
+ created = timezone .now (),
311
+ updated = timezone .now (),
314
312
source_refresh_token_id = "0" ,
315
313
)
316
314
AccessToken .objects .create (
317
315
id = 2 ,
318
316
token = "666" ,
319
- expires = dt .now (),
317
+ expires = timezone .now (),
320
318
scope = 2 ,
321
319
application_id = 3 ,
322
320
user_id = 1 ,
323
- created = dt .now (),
324
- updated = dt .now (),
321
+ created = timezone .now (),
322
+ updated = timezone .now (),
325
323
source_refresh_token_id = "1" ,
326
324
)
327
325
@@ -340,9 +338,9 @@ def test_clear_expired_tokens_with_tokens(self):
340
338
self .client .login (username = "test_user" , password = "123456" )
341
339
oauth2_settings .REFRESH_TOKEN_EXPIRE_SECONDS = 0
342
340
ttokens = AccessToken .objects .count ()
343
- expiredt = AccessToken .objects .filter (expires__lte = dt .now ()).count ()
341
+ expiredt = AccessToken .objects .filter (expires__lte = timezone .now ()).count ()
344
342
assert ttokens == 2
345
343
assert expiredt == 2
346
344
clear_expired ()
347
- expiredt = AccessToken .objects .filter (expires__lte = dt .now ()).count ()
345
+ expiredt = AccessToken .objects .filter (expires__lte = timezone .now ()).count ()
348
346
assert expiredt == 0
0 commit comments