test utc_now, hacky fix for TZ Aware/Naive comparison when fetching datetimes

This commit is contained in:
2024-11-09 17:30:28 -06:00
parent d725d1b863
commit afd29806dc
2 changed files with 11 additions and 1 deletions

View File

@@ -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

View 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