Redis fixtures and fixture factories for Pytest.
Overall
score
95%
Build a simple session storage service that uses Redis to store and retrieve user session data.
Implement a SessionStore class that manages user sessions in Redis. The class should:
Write tests using pytest fixtures to verify the SessionStore class behavior:
@generates
import json
from typing import Optional, Dict, Any
class SessionStore:
"""Manages user sessions in Redis."""
def __init__(self, redis_client):
"""Initialize with a Redis client.
Args:
redis_client: A Redis client instance
"""
pass
def create_session(self, user_id: str, session_data: Dict[str, Any]) -> None:
"""Store a new session.
Args:
user_id: The user's unique identifier
session_data: Dictionary containing session information
"""
pass
def get_session(self, user_id: str) -> Optional[Dict[str, Any]]:
"""Retrieve session data.
Args:
user_id: The user's unique identifier
Returns:
Session data dictionary if found, None otherwise
"""
pass
def delete_session(self, user_id: str) -> None:
"""Remove a session.
Args:
user_id: The user's unique identifier
"""
pass
def session_exists(self, user_id: str) -> bool:
"""Check if a session exists.
Args:
user_id: The user's unique identifier
Returns:
True if session exists, False otherwise
"""
passProvides Redis fixtures for testing.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-pytest-redisdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10