From c2ba3fcaed9538b3bc893934c81d86ca9c89b3c9 Mon Sep 17 00:00:00 2001 From: MeenBna Date: Fri, 27 Sep 2024 12:31:57 +0200 Subject: [PATCH] Ensured timezone-aware comparison for token expiration. --- requirements.txt | 1 + tests/auth_client_test.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index d2d0d5b..2724d7d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ ipykernel nest_asyncio pre-commit pytest-asyncio +python-dateutil python-dotenv sphinx_rtd_theme tenacity diff --git a/tests/auth_client_test.py b/tests/auth_client_test.py index f780e60..9a86faf 100644 --- a/tests/auth_client_test.py +++ b/tests/auth_client_test.py @@ -5,6 +5,8 @@ from copy import deepcopy from datetime import datetime, timedelta, timezone import requests +from dateutil.parser import parse +from dateutil.tz import tzutc from pyprediktormapclient.auth_client import AUTH_CLIENT, Token @@ -436,11 +438,23 @@ def test_get_self_service_login_token_successful( auth_client.id = auth_id auth_client.get_login_token() + # Parse the expected datetime string + expected_expires_at = parse(auth_expires_at).replace(tzinfo=tzutc()) + test_token = Token( - session_token=auth_session_id, expires_at=auth_expires_at + session_token=auth_session_id, expires_at=expected_expires_at ) + assert auth_client.token.session_token == test_token.session_token - assert auth_client.token.expires_at == test_token.expires_at + + # Compare the datetime objects after ensuring they're both timezone-aware + actual_expires_at = auth_client.token.expires_at + if actual_expires_at.tzinfo is None: + actual_expires_at = actual_expires_at.replace(tzinfo=tzutc()) + + assert ( + actual_expires_at == expected_expires_at + ), f"Expected {expected_expires_at}, but got {actual_expires_at}" @patch( "requests.post",