mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-06 09:15:32 -06:00
test utc_now, hacky fix for TZ Aware/Naive comparison when fetching datetimes
This commit is contained in:
@@ -60,6 +60,10 @@ class Session(BaseModel):
|
||||
created_at = DateTimeField(default=utc_now)
|
||||
last_used = DateTimeField(null=True)
|
||||
|
||||
@property
|
||||
def expiry_utc(self) -> datetime.datetime:
|
||||
return self.expiry.replace(tzinfo=datetime.timezone.utc) # type: ignore
|
||||
|
||||
def is_expired(
|
||||
self, revoke: bool = True, now: Optional[datetime.datetime] = None
|
||||
) -> bool:
|
||||
@@ -69,7 +73,7 @@ class Session(BaseModel):
|
||||
if now is None:
|
||||
now = utc_now()
|
||||
|
||||
if self.expiry < now:
|
||||
if self.expiry_utc < now:
|
||||
if revoke:
|
||||
self.delete_instance()
|
||||
return True
|
||||
|
||||
6
backend/linkpulse/tests/test_utilities.py
Normal file
6
backend/linkpulse/tests/test_utilities.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from linkpulse.utilities import utc_now
|
||||
|
||||
|
||||
def test_utcnow_tz_aware():
|
||||
dt = utc_now()
|
||||
dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
|
||||
Reference in New Issue
Block a user