24 lines
1019 B
Python
24 lines
1019 B
Python
from datetime import timedelta
|
|
from ea_chatbot.api.utils import create_access_token, create_refresh_token, decode_access_token
|
|
|
|
def test_create_access_token_with_custom_delta():
|
|
"""Test creating an access token with a custom expiration delta."""
|
|
data = {"sub": "user123"}
|
|
delta = timedelta(minutes=5)
|
|
token = create_access_token(data, expires_delta=delta)
|
|
decoded = decode_access_token(token)
|
|
assert decoded["sub"] == "user123"
|
|
assert "exp" in decoded
|
|
|
|
def test_create_refresh_token():
|
|
"""Test creating a refresh token."""
|
|
data = {"sub": "user123"}
|
|
# This might fail if create_refresh_token is not yet implemented
|
|
token = create_refresh_token(data)
|
|
decoded = decode_access_token(token) # decode_access_token uses same secret/algorithm
|
|
assert decoded["sub"] == "user123"
|
|
assert "exp" in decoded
|
|
# Refresh token should have longer expiration than access token
|
|
# We can check the iat and exp to verify the duration
|
|
assert decoded["exp"] > decoded["iat"]
|