Skip to content

Commit 3af0a8d

Browse files
authored
Fix tests as well
1 parent 72e00df commit 3af0a8d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/test_jwt.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import base64
22
import json
3+
from datetime import datetime, timedelta
34

45
try:
5-
from datetime import UTC, datetime, timedelta
6-
7-
utc_now = datetime.now(UTC) # Preferred in Python 3.13+
6+
from datetime import UTC # Preferred in Python 3.13+
87
except ImportError:
9-
from datetime import datetime, timedelta, timezone
10-
11-
utc_now = datetime.now(timezone.utc) # Preferred in Python 3.12 and below
8+
from datetime import timezone # Preferred in Python 3.12 and below
129
UTC = timezone.utc
1310

1411

@@ -514,14 +511,16 @@ def test_unverified_claims_object(self, claims, key):
514511
[
515512
("aud", "aud"),
516513
("ait", "ait"),
517-
("exp", utc_now + timedelta(seconds=3600)),
518-
("nbf", utc_now - timedelta(seconds=5)),
514+
("exp", lambda: datetime.now(UTC) + timedelta(seconds=3600)),
515+
("nbf", lambda: datetime.now(UTC) - timedelta(seconds=5)),
519516
("iss", "iss"),
520517
("sub", "sub"),
521518
("jti", "jti"),
522519
],
523520
)
524521
def test_require(self, claims, key, claim, value):
522+
if callable(value):
523+
value = value()
525524
options = {"require_" + claim: True, "verify_" + claim: False}
526525

527526
token = jwt.encode(claims, key)

0 commit comments

Comments
 (0)