Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump redis from 5.0.0 to 5.0.1 #931

Merged
merged 10 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiohttp_session/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RedisStorage(AbstractStorage):

def __init__(
self,
redis_pool: "aioredis.Redis[bytes]",
redis_pool: "aioredis.Redis",
*,
cookie_name: str = "AIOHTTP_SESSION",
domain: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion demo/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def handler(request: web.Request) -> web.Response:

async def redis_pool(app: web.Application) -> AsyncIterator[None]:
redis_address = "redis://127.0.0.1:6379"
async with aioredis.from_url(redis_address) as redis:
async with aioredis.from_url(redis_address) as redis: # type: ignore[no-untyped-call]
storage = RedisStorage(redis)
setup(app, storage)
yield
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ mypy==1.6.1
pep257==0.7.0
pre-commit==3.5.0
sphinx==7.2.6
types-redis==4.6.0.6
typing-extensions==4.8.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pytest-aiohttp==1.0.5
pytest-cov==4.1.0
pytest-mock==3.12.0
pytest-sugar==0.9.7
redis==5.0.0
redis==5.0.1
yarl==1.9.2
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ async def redis_server( # type: ignore[misc] # No docker types.
delay = 0.1
for _i in range(20): # pragma: no cover
try:
conn = aioredis.from_url(f"redis://{host}:{port}")
conn = aioredis.from_url(f"redis://{host}:{port}") # type: ignore[no-untyped-call]
await conn.set("foo", "bar")
break
except aioredis.ConnectionError:
time.sleep(delay)
delay *= 2
finally:
await conn.close()
await conn.aclose()
else: # pragma: no cover
pytest.fail("Cannot start redis server")

Expand All @@ -117,14 +117,14 @@ def redis_url(redis_server: _ContainerInfo) -> str: # type: ignore[misc]
@pytest.fixture
async def redis(
redis_url: str,
) -> AsyncIterator[aioredis.Redis[bytes]]:
async def start(pool: aioredis.ConnectionPool) -> aioredis.Redis[bytes]:
) -> AsyncIterator[aioredis.Redis]:
async def start(pool: aioredis.ConnectionPool) -> aioredis.Redis:
return aioredis.Redis(connection_pool=pool)

pool = aioredis.ConnectionPool.from_url(redis_url)
redis = await start(pool)
yield redis
await redis.close()
await redis.aclose()
await pool.disconnect()


Expand Down
36 changes: 18 additions & 18 deletions tests/test_redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def create_app(
handler: Handler,
redis: aioredis.Redis[bytes],
redis: aioredis.Redis,
max_age: Optional[int] = None,
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex,
) -> web.Application:
Expand All @@ -34,7 +34,7 @@ def create_app(


async def make_cookie(
client: TestClient, redis: aioredis.Redis[bytes], data: Dict[Any, Any]
client: TestClient, redis: aioredis.Redis, data: Dict[Any, Any]
) -> None:
session_data = {"session": data, "created": int(time.time())}
value = json.dumps(session_data)
Expand All @@ -43,21 +43,21 @@ async def make_cookie(
client.session.cookie_jar.update_cookies({"AIOHTTP_SESSION": key})


async def make_cookie_with_bad_value(client: TestClient, redis: aioredis.Redis[bytes]) -> None:
async def make_cookie_with_bad_value(client: TestClient, redis: aioredis.Redis) -> None:
key = uuid.uuid4().hex
await redis.set("AIOHTTP_SESSION_" + key, "")
client.session.cookie_jar.update_cookies({"AIOHTTP_SESSION": key})


async def load_cookie(client: TestClient, redis: aioredis.Redis[bytes]) -> Any:
async def load_cookie(client: TestClient, redis: aioredis.Redis) -> Any:
cookies = client.session.cookie_jar.filter_cookies(client.make_url("/"))
key = cookies["AIOHTTP_SESSION"]
value_bytes = await redis.get("AIOHTTP_SESSION_" + key.value)
return None if value_bytes is None else json.loads(value_bytes)


async def test_create_new_session(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -73,7 +73,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_load_existing_session(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -90,7 +90,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_load_bad_session(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -107,7 +107,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_change_session(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -134,7 +134,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_clear_cookie_on_session_invalidation(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -155,7 +155,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_create_cookie_in_handler(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -182,7 +182,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_set_ttl_on_session_saving(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -202,7 +202,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_set_ttl_manually_set(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -223,7 +223,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_create_new_session_if_key_doesnt_exists_in_redis(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -237,7 +237,7 @@ async def handler(request: web.Request) -> web.StreamResponse:


async def test_create_storage_with_custom_key_factory(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand All @@ -260,7 +260,7 @@ def key_factory() -> str:


async def test_redis_session_fixation(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def login(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand Down Expand Up @@ -289,9 +289,9 @@ async def test_redis_from_create_pool(redis_url: str) -> None:
async def handler(request: web.Request) -> web.Response: # type: ignore[empty-body]
"""Dummy handler"""

redis = aioredis.from_url(redis_url)
redis = aioredis.from_url(redis_url) # type: ignore[no-untyped-call]
create_app(handler=handler, redis=redis)
await redis.close()
await redis.aclose()


async def test_not_redis_provided_to_storage() -> None:
Expand Down Expand Up @@ -321,7 +321,7 @@ async def handler(request: web.Request) -> web.Response: # type: ignore[empty-b


async def test_load_session_dont_load_expired_session(
aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes]
aiohttp_client: AiohttpClient, redis: aioredis.Redis
) -> None:
async def handler(request: web.Request) -> web.StreamResponse:
session = await get_session(request)
Expand Down