Skip to content

Commit

Permalink
Update Auth handler to expect expiredIn to be a string and not an int
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrayner committed Feb 7, 2024
1 parent c368313 commit 7bbcfac
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions podpointclient/helpers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def __update_access_token(self, refresh: bool = False) -> bool:
self.access_token = json["idToken"]
self.refresh_token = json["refreshToken"]
self.access_token_expiry = datetime.now() + timedelta(
seconds=json["expiresIn"] - 10
seconds=int(json["expiresIn"]) - 10
)
return_value = True

Expand All @@ -118,7 +118,7 @@ async def __update_access_token(self, refresh: bool = False) -> bool:
response.status,
f"Error processing access token response. {exception} not found in json."
) from exception
except TypeError as exception:
except (TypeError, ValueError) as exception:
raise AuthError(
response.status,
f"Error processing access token response. \
Expand Down
2 changes: 1 addition & 1 deletion podpointclient/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version for the podpointclient library"""

__version__ = "1.4.1-b2"
__version__ = "1.4.1-b3"
2 changes: 1 addition & 1 deletion tests/fixtures/auth.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"expiresIn": 1234,
"expiresIn": "1234",
"idToken": "1234",
"refreshToken": "1234"
}
16 changes: 8 additions & 8 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def test_access_token_not_set():
@pytest.mark.asyncio
async def test_update_access_token_when_not_set(aiohttp_client):
auth_response = {
"expiresIn": 1234,
"expiresIn": "1234",
"idToken": "1234",
"refreshToken": "1234"
}
Expand Down Expand Up @@ -91,7 +91,7 @@ async def test_update_access_token_when_not_set(aiohttp_client):
@pytest.mark.asyncio
async def test_auth_with_session_error(aiohttp_client):
auth_response = {
"expiresIn": 1234,
"expiresIn": "1234",
"idToken": "1234",
"refreshToken": "1234"
}
Expand All @@ -118,7 +118,7 @@ async def test_auth_with_session_error(aiohttp_client):
@pytest.mark.asyncio
async def test_auth_with_auth_error(aiohttp_client):
auth_response = {
"expiresIn": 1234,
"expiresIn": "1234",
"idToken": "1234",
"refreshToken": "1234"
}
Expand All @@ -145,7 +145,7 @@ async def test_auth_with_auth_error(aiohttp_client):
@pytest.mark.asyncio
async def test_update_access_token_when_not_set(aiohttp_client):
auth_response = {
"expiresIn": 1234,
"expiresIn": "1234",
"idToken": "1234",
"refreshToken": "1234"
}
Expand Down Expand Up @@ -192,7 +192,7 @@ async def test_auth_401_error():
async def test_auth_json_error():
# MISSING ELEMENT
auth_response = {
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}

Expand Down Expand Up @@ -223,12 +223,12 @@ async def test_auth_json_error():
with pytest.raises(AuthError) as exc_info:
await auth.async_update_access_token()

assert "Auth Error (200) - Error processing access token response. When calculating expiry date, got: unsupported operand type(s) for -: 'str' and 'int'." in str(exc_info.value)
assert "Auth Error (200) - Error processing access token response. When calculating expiry date, got: invalid literal for int() with base 10: 'F14A3'." in str(exc_info.value)


async def test_session_401_error():
auth_response = {
"expiresIn": 1234,
"expiresIn": "1234",
"idToken": "1234",
"refreshToken": "1234"
}
Expand All @@ -248,7 +248,7 @@ async def test_session_401_error():
async def test_session_json_error():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down
44 changes: 22 additions & 22 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
async def test_async_credentials_verified():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -52,7 +52,7 @@ async def test_async_credentials_verified():
async def test_async_credentials_verified_returns_false_if_no_pods():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -80,7 +80,7 @@ async def test_async_credentials_verified_returns_false_if_no_pods():
async def test_async_credentials_verified_returns_false_if_body_unexpected():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand All @@ -106,7 +106,7 @@ async def test_async_credentials_verified_returns_false_if_body_unexpected():
async def test_async_get_pods_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -137,7 +137,7 @@ async def test_async_get_pods_response():
async def test_async_get_pods_response_without_timestamp():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -168,7 +168,7 @@ async def test_async_get_pods_response_without_timestamp():
async def test_async_get_all_pods_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -213,7 +213,7 @@ async def test_async_get_all_pods_response():
async def test_async_get_all_pods_response_with_includes_overridden_and_timestamp():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -257,7 +257,7 @@ async def test_async_get_all_pods_response_with_includes_overridden_and_timestam
async def test_async_get_all_pods_response_with_includes_empty_and_timestamp():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -301,7 +301,7 @@ async def test_async_get_all_pods_response_with_includes_empty_and_timestamp():
async def test_async_set_schedules_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -338,7 +338,7 @@ async def test_async_set_schedules_response():
async def test_async_get_charges_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -504,7 +504,7 @@ async def test__schedule_data():
async def test_async_get_firmware():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -541,7 +541,7 @@ async def test_async_get_firmware():
async def test_async_get_user():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -570,7 +570,7 @@ async def test_async_get_user():
async def test_async_set_schedules_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -607,7 +607,7 @@ async def test_async_set_schedules_response():
async def test_async_get_all_charges_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -638,7 +638,7 @@ async def test_async_get_all_charges_response():
async def test_async_get_charge_override_with_an_empty_response_meaning_smart_mode():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand All @@ -663,7 +663,7 @@ async def test_async_get_charge_override_with_an_empty_response_meaning_smart_mo
async def test_async_get_charge_override_with_a_manual_mode_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -697,7 +697,7 @@ async def test_async_get_charge_override_with_a_manual_mode_response():
async def test_async_get_charge_override_with_a_charge_override_time_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -731,7 +731,7 @@ async def test_async_get_charge_override_with_a_charge_override_time_response():
async def test_async_set_charge_override_with_a_time_set():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -765,7 +765,7 @@ async def test_async_set_charge_override_with_a_time_set():
async def test_async_set_charge_override_with_an_invalid_time_set():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -797,7 +797,7 @@ async def test_async_set_charge_override_with_an_invalid_time_set():
async def test_async_set_charge_mode_manual_with_expected_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -828,7 +828,7 @@ async def test_async_set_charge_mode_manual_with_expected_response():
async def test_async_set_charge_mode_manual_with_unexpected_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down Expand Up @@ -881,7 +881,7 @@ async def test_async_set_charge_mode_smart_with_204_response():
async def test_async_set_charge_mode_smart_with_unexpected_response():
auth_response = {
"idToken": "1234",
"expiresIn": 1234,
"expiresIn": "1234",
"refreshToken": "1234"
}
session_response = {
Expand Down

0 comments on commit 7bbcfac

Please sign in to comment.