Skip to content

Commit

Permalink
Add session_id as an optional parameter in create_session_in_cache fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
Dennis Lee committed Mar 5, 2024
1 parent 3170437 commit 05cfc7b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/auth/test_session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import uuid
import random
from typing import Optional
from datetime import datetime, timedelta
from app.auth.session import add, exists, update_last_activity, remove, retrieve_by_userid, retrieve
from app.auth.schemas import SessionInfo
Expand All @@ -10,7 +11,7 @@

async def create_session_in_cache(
user_id: str,
session_id: str,
session_id: Optional[str] = None,
ttl: int = 3600) -> bool:
"""
Create a new session in the cache.
Expand All @@ -27,6 +28,9 @@ async def create_session_in_cache(
Returns:
bool: True if the session was successfully added to the cache, False otherwise.
"""
if session_id is None:
session_id = "session-" + str(uuid.uuid4())[8:]

# Get the current time
now = datetime.utcnow()

Expand Down Expand Up @@ -133,6 +137,16 @@ async def test_remove():
with pytest.raises(ValueError) as exc_info:
await remove("", session_id)

@pytest.mark.asyncio
async def test_remove():
await create_session_in_cache(user_id)
await create_session_in_cache(user_id)

result = await remove(user_id)
print(result)

assert result > 1

@pytest.mark.asyncio
async def test_retrieve_by_userid():
"""
Expand Down

0 comments on commit 05cfc7b

Please sign in to comment.