1- import json
2-
31import jwt
42import pytest
5- import unittest
63
74from citrine .exceptions import (
85 BadRequest ,
9- CitrineException ,
106 Conflict ,
117 NonRetryableException ,
128 WorkflowNotReadyException ,
139 RetryableException )
1410
15- from datetime import datetime , timedelta
16- import pytz
11+ from datetime import datetime , timedelta , timezone
12+
1713import mock
1814import requests
1915import requests_mock
@@ -32,7 +28,7 @@ def refresh_token(expiration: datetime = None) -> dict:
3228
3329@pytest .fixture
3430def session ():
35- token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = pytz .utc ))
31+ token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = timezone .utc ))
3632 with requests_mock .Mocker () as m :
3733 m .post ('http://citrine-testing.fake/api/v1/tokens/refresh' , json = token_refresh_response )
3834 session = Session (
@@ -43,13 +39,13 @@ def session():
4339 # Default behavior is to *not* require a refresh - those tests can clear this out
4440 # As rule of thumb, we should be using freezegun or similar to never rely on the system clock
4541 # for these scenarios, but I thought this is light enough to postpone that for the time being
46- session .access_token_expiration = datetime .utcnow ( ) + timedelta (minutes = 3 )
42+ session .access_token_expiration = datetime .now ( timezone . utc ) + timedelta (minutes = 3 )
4743
4844 return session
4945
5046
5147def test_session_signature (monkeypatch ):
52- token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = pytz .utc ))
48+ token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = timezone .utc ))
5349 with requests_mock .Mocker () as m :
5450 m .post ('ftp://citrine-testing.fake:8080/api/v1/tokens/refresh' , json = token_refresh_response )
5551
@@ -77,8 +73,8 @@ def test_session_signature(monkeypatch):
7773
7874
7975def test_get_refreshes_token (session : Session ):
80- session .access_token_expiration = datetime .utcnow ( ) - timedelta (minutes = 1 )
81- token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = pytz .utc ))
76+ session .access_token_expiration = datetime .now ( timezone . utc ) - timedelta (minutes = 1 )
77+ token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = timezone .utc ))
8278
8379 with requests_mock .Mocker () as m :
8480 m .post ('http://citrine-testing.fake/api/v1/tokens/refresh' , json = token_refresh_response )
@@ -89,11 +85,11 @@ def test_get_refreshes_token(session: Session):
8985 resp = session .get_resource ('/foo' )
9086
9187 assert {'foo' : 'bar' } == resp
92- assert datetime (2019 , 3 , 14 ) == session .access_token_expiration
88+ assert datetime (2019 , 3 , 14 , tzinfo = timezone . utc ) == session .access_token_expiration
9389
9490
9591def test_get_refresh_token_failure (session : Session ):
96- session .access_token_expiration = datetime .utcnow ( ) - timedelta (minutes = 1 )
92+ session .access_token_expiration = datetime .now ( timezone . utc ) - timedelta (minutes = 1 )
9793
9894 with requests_mock .Mocker () as m :
9995 m .post ('http://citrine-testing.fake/api/v1/tokens/refresh' , status_code = 401 )
@@ -197,7 +193,7 @@ def test_connection_error(session: Session):
197193
198194
199195def test_post_refreshes_token_when_denied (session : Session ):
200- token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = pytz .utc ))
196+ token_refresh_response = refresh_token (datetime (2019 , 3 , 14 , tzinfo = timezone .utc ))
201197
202198 with requests_mock .Mocker () as m :
203199 m .post ('http://citrine-testing.fake/api/v1/tokens/refresh' , json = token_refresh_response )
@@ -209,7 +205,7 @@ def test_post_refreshes_token_when_denied(session: Session):
209205 resp = session .post_resource ('/foo' , json = {'data' : 'hi' })
210206
211207 assert {'foo' : 'bar' } == resp
212- assert datetime (2019 , 3 , 14 ) == session .access_token_expiration
208+ assert datetime (2019 , 3 , 14 , tzinfo = timezone . utc ) == session .access_token_expiration
213209
214210
215211# this test exists to provide 100% coverage for the legacy 401 status on Unauthorized responses
0 commit comments