Skip to content

Commit

Permalink
Directly use minimal expiration seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky committed Jun 25, 2024
1 parent 49638cb commit f6f74f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/neptune_api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def from_tokens(cls, access: str, refresh: str) -> "OAuthToken":

@property
def seconds_left(self) -> float:
return self._expiration_time - time.time()
return self._expiration_time - time.time() - MINIMAL_EXPIRATION_SECONDS

@property
def is_expired(self) -> bool:
return self.seconds_left <= MINIMAL_EXPIRATION_SECONDS
return self.seconds_left <= 0
24 changes: 4 additions & 20 deletions tests/unit/test_oauth_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from freezegun import freeze_time

from neptune_api.errors import InvalidApiTokenException
from neptune_api.types import (
MINIMAL_EXPIRATION_SECONDS,
OAuthToken,
)
from neptune_api.types import OAuthToken


def test_invalid():
Expand All @@ -18,19 +15,6 @@ def test_invalid():
OAuthToken.from_tokens(access=access_token, refresh=refresh_token)


@freeze_time("2024-01-02 03:04:05 UTC")
def test_expiration_time(oauth_token):
# given
access_token, refresh_token = oauth_token.access_token, oauth_token.refresh_token

# when
token = OAuthToken.from_tokens(access=access_token, refresh=refresh_token)

# then
assert token.seconds_left == 0.0
assert token.is_expired is True


@freeze_time("2024-01-02 03:03:34 UTC")
def test_almost_expired(oauth_token):
# given
Expand All @@ -40,7 +24,7 @@ def test_almost_expired(oauth_token):
token = OAuthToken.from_tokens(access=access_token, refresh=refresh_token)

# then
assert token.seconds_left == MINIMAL_EXPIRATION_SECONDS + 1
assert token.seconds_left == 1
assert token.is_expired is False


Expand All @@ -53,7 +37,7 @@ def test_expired_equal(oauth_token):
token = OAuthToken.from_tokens(access=access_token, refresh=refresh_token)

# then
assert token.seconds_left == MINIMAL_EXPIRATION_SECONDS
assert token.seconds_left == 0.0
assert token.is_expired is True


Expand All @@ -66,5 +50,5 @@ def test_expired(oauth_token):
token = OAuthToken.from_tokens(access=access_token, refresh=refresh_token)

# then
assert token.seconds_left == MINIMAL_EXPIRATION_SECONDS - 1
assert token.seconds_left == -1.0
assert token.is_expired is True

0 comments on commit f6f74f7

Please sign in to comment.