From 05cfc7b27fec8cacf49baf7d6dbb53598c09db4e Mon Sep 17 00:00:00 2001 From: Dennis Lee Date: Tue, 5 Mar 2024 18:52:57 +0800 Subject: [PATCH] Add session_id as an optional parameter in create_session_in_cache function --- tests/auth/test_session.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/auth/test_session.py b/tests/auth/test_session.py index 1fce720..495df76 100644 --- a/tests/auth/test_session.py +++ b/tests/auth/test_session.py @@ -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 @@ -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. @@ -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() @@ -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(): """