Skip to content

Commit

Permalink
Ensured timezone-aware comparison for token expiration.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeenaBana committed Sep 27, 2024
1 parent b23ad3b commit c2ba3fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ipykernel
nest_asyncio
pre-commit
pytest-asyncio
python-dateutil
python-dotenv
sphinx_rtd_theme
tenacity
Expand Down
18 changes: 16 additions & 2 deletions tests/auth_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c2ba3fc

Please sign in to comment.