diff --git a/bookops_worldcat/authorize.py b/bookops_worldcat/authorize.py index e83647d..e71a26a 100644 --- a/bookops_worldcat/authorize.py +++ b/bookops_worldcat/authorize.py @@ -161,6 +161,7 @@ def _hasten_expiration_time(self, utc_stamp_str: str) -> datetime.datetime: utcstamp = datetime.datetime.strptime( utc_stamp_str, "%Y-%m-%d %H:%M:%SZ" ) - datetime.timedelta(seconds=1) + utcstamp = utcstamp.replace(tzinfo=datetime.timezone.utc) return utcstamp def _parse_server_response(self, response: requests.Response) -> None: diff --git a/tests/conftest.py b/tests/conftest.py index 8821e95..e78db1e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,7 +28,7 @@ def live_keys(): class FakeUtcNow(datetime.datetime): @classmethod def now(cls, tzinfo=datetime.timezone.utc): - return cls(2020, 1, 1, 17, 0, 0, 0) + return cls(2020, 1, 1, 17, 0, 0, 0, tzinfo=datetime.timezone.utc) @pytest.fixture diff --git a/tests/test_authorize.py b/tests/test_authorize.py index 7c559e0..4e96d41 100644 --- a/tests/test_authorize.py +++ b/tests/test_authorize.py @@ -265,7 +265,9 @@ def test_hasten_expiration_time(self, mock_token): token = mock_token timestamp = token._hasten_expiration_time(utc_stamp) assert isinstance(timestamp, datetime.datetime) - assert timestamp == datetime.datetime(2020, 1, 1, 17, 19, 58, 0) + assert timestamp == datetime.datetime( + 2020, 1, 1, 17, 19, 58, 0, tzinfo=datetime.timezone.utc + ) def test_payload(self, mock_successful_post_token_response): token = WorldcatAccessToken( diff --git a/tests/test_metadata_api.py b/tests/test_metadata_api.py index da1a8fe..a6d615d 100644 --- a/tests/test_metadata_api.py +++ b/tests/test_metadata_api.py @@ -49,7 +49,7 @@ def test_get_new_access_token(self, mock_token, mock_now): assert session.authorization.is_expired() is True session._get_new_access_token() assert session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert session.authorization.is_expired() is False @@ -209,7 +209,7 @@ def test_get_brief_bib_with_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.get_brief_bib(oclcNumber=12345) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 200 @@ -254,7 +254,7 @@ def test_get_full_bib_with_stale_token(self, stub_session, mock_session_response response = stub_session.get_full_bib(12345) assert stub_session.authorization.is_expired() is False assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert response.status_code == 200 @@ -281,7 +281,7 @@ def test_holding_get_status_with_stale_token( response = stub_session.holding_get_status(12345) assert stub_session.authorization.is_expired() is False assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert response.status_code == 200 @@ -305,7 +305,7 @@ def test_holding_set_stale_token(self, stub_session, mock_session_response): assert stub_session.authorization.is_expired() is True response = stub_session.holding_set(850940548) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 201 @@ -332,7 +332,7 @@ def test_holding_unset_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.holding_unset(850940548) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 200 @@ -370,7 +370,7 @@ def test_holdings_set_stale_token( assert stub_session.authorization.is_expired() is True stub_session.holdings_set([850940548, 850940552, 850940554]) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False @@ -409,7 +409,7 @@ def test_holdings_unset_stale_token( assert stub_session.authorization.is_expired() is True stub_session.holdings_unset([850940548, 850940552, 850940554]) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False @@ -447,7 +447,7 @@ def test_holdings_set_multi_institutions_stale_token( oclcNumber=850940548, instSymbols="NYP,BKL" ) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False @@ -501,7 +501,7 @@ def test_holdings_unset_multi_institutions_stale_token( oclcNumber=850940548, instSymbols="NYP,BKL" ) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False @@ -521,7 +521,7 @@ def test_search_brief_bibs_other_editions_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.search_brief_bib_other_editions(12345) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 200 @@ -552,7 +552,7 @@ def test_search_brief_bibs_with_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.search_brief_bibs(q="ti:foo") assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 200 @@ -594,7 +594,7 @@ def test_search_current_control_numbers_with_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.search_current_control_numbers(["12345", "65891"]) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 207 @@ -625,7 +625,7 @@ def test_search_general_holdings_with_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.search_general_holdings(oclcNumber=12345) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 200 @@ -661,7 +661,7 @@ def test_search_shared_print_holdings_with_stale_token( assert stub_session.authorization.is_expired() is True response = stub_session.search_shared_print_holdings(oclcNumber=12345) assert stub_session.authorization.token_expires_at == datetime.datetime( - 2020, 1, 1, 17, 19, 58 + 2020, 1, 1, 17, 19, 58, tzinfo=datetime.timezone.utc ) assert stub_session.authorization.is_expired() is False assert response.status_code == 200