diff options
author | Colin Watson <cjwatson@debian.org> | 2024-04-30 18:15:04 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2024-04-30 18:19:02 +0100 |
commit | 21fdbcaee69e49aef846bdbb1818b5777c14887f (patch) | |
tree | 1129ac41383729ccfaa26637c9d97988775063a0 | |
parent | ca30f25cc22438310bcc5aaf76f845e7c73d2936 (diff) | |
parent | 835fe42b46c32f66d57ffde6a9e82c7f53692ca3 (diff) |
Update upstream source from tag 'upstream/2.12.0'
Update to upstream version '2.12.0'
with Debian dir 39f36d38b324fc88b811c1a8994e188459eb04fa
-rw-r--r-- | .github/workflows/ci.yaml | 4 | ||||
-rw-r--r-- | .isort.cfg | 1 | ||||
-rw-r--r-- | .mypy.ini | 3 | ||||
-rw-r--r-- | .pre-commit-config.yaml | 16 | ||||
-rw-r--r-- | CHANGES.txt | 6 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README.rst | 10 | ||||
-rw-r--r-- | aiohttp_session/__init__.py | 3 | ||||
-rw-r--r-- | aiohttp_session/redis_storage.py | 37 | ||||
-rw-r--r-- | debian/changelog | 8 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debian/patches/privacy-breach-fixes.patch | 16 | ||||
-rw-r--r-- | debian/patches/use-local-docs-for-intersphinx-links.patch | 18 | ||||
-rw-r--r-- | demo/redis_storage.py | 7 | ||||
-rw-r--r-- | docs/conf.py | 2 | ||||
-rw-r--r-- | docs/glossary.rst | 4 | ||||
-rw-r--r-- | docs/index.rst | 4 | ||||
-rw-r--r-- | docs/reference.rst | 12 | ||||
-rw-r--r-- | pytest.ini | 1 | ||||
-rw-r--r-- | requirements-dev.txt | 39 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | tests/conftest.py | 18 | ||||
-rw-r--r-- | tests/test_encrypted_cookie_storage.py | 6 | ||||
-rw-r--r-- | tests/test_redis_storage.py | 50 |
24 files changed, 148 insertions, 122 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index eff2279..567535b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,8 +33,8 @@ jobs: run: flake8 - name: Prepare twine checker run: | - pip install -U twine wheel - python setup.py sdist bdist_wheel + pip install -U build twine wheel + python -m build - name: Run twine checker run: twine check dist/* @@ -4,3 +4,4 @@ include_trailing_comma=True multi_line_output=3 force_grid_wrap=0 combine_as_imports=True +known_first_party=aiohttp_session @@ -27,9 +27,6 @@ disallow_any_unimported = False [mypy-aiopg.*] ignore_missing_imports = True -[mypy-aioredis.*] -ignore_missing_imports = True - [mypy-aiomcache.*] ignore_missing_imports = True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b0dbf0..112e1ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,24 +17,24 @@ repos: pass_filenames: true types: [file, rst] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.0.1' + rev: 'v4.3.0' hooks: - id: check-merge-conflict - repo: https://github.com/asottile/yesqa - rev: v1.3.0 + rev: v1.4.0 hooks: - id: yesqa - repo: https://github.com/PyCQA/isort - rev: '5.9.3' + rev: '5.10.1' hooks: - id: isort - repo: https://github.com/psf/black - rev: '21.10b0' + rev: '22.10.0' hooks: - id: black language_version: python3 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.0.1' + rev: 'v4.3.0' hooks: - id: end-of-file-fixer exclude: >- @@ -66,16 +66,16 @@ repos: - id: detect-private-key exclude: ^examples/ - repo: https://github.com/asottile/pyupgrade - rev: 'v2.29.0' + rev: 'v3.1.0' hooks: - id: pyupgrade args: ['--py36-plus'] - repo: https://github.com/PyCQA/flake8 - rev: '4.0.1' + rev: '5.0.4' hooks: - id: flake8 exclude: "^docs/" -- repo: git://github.com/Lucas-C/pre-commit-hooks-markup +- repo: https://github.com/Lucas-C/pre-commit-hooks-markup rev: v1.0.1 hooks: - id: rst-linter diff --git a/CHANGES.txt b/CHANGES.txt index 146f65e..ee54cbc 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,11 @@ .. towncrier release notes start +2.12.0 (2022-10-28) +=================== + +* Migrated from `aioredis` to `redis` (if using redis without installing + `aiohttp-session[aioredis]` then it will be necessary to manually install `redis`). + 2.11.0 (2021-01-31) =================== @@ -7,7 +7,6 @@ setup: flake fmt: python -m pre_commit run --all-files - test: py.test ./tests/ @@ -1,7 +1,7 @@ aiohttp_session =============== -.. image:: https://travis-ci.com/aio-libs/aiohttp-session.svg?branch=master - :target: https://travis-ci.com/aio-libs/aiohttp-session +.. image:: https://github.com/aio-libs/aiohttp-session/actions/workflows/ci.yaml/badge.svg?branch=master + :target: https://github.com/aio-libs/aiohttp-session/actions/workflows/ci.yaml .. image:: https://codecov.io/github/aio-libs/aiohttp-session/coverage.svg?branch=master :target: https://codecov.io/github/aio-libs/aiohttp-session .. image:: https://readthedocs.org/projects/aiohttp-session/badge/?version=latest @@ -79,10 +79,8 @@ Available session storages are: * ``aiohttp_session.redis_storage.RedisStorage(redis_pool)`` -- stores JSON encoded data in *redis*, keeping only the redis key (a random UUID) in - the cookie. ``redis_pool`` is a ``aioredis`` pool object, created by - ``await aioredis.create_redis_pool(...)`` call. - - Requires ``aioredis`` library (only versions ``1.0+`` are supported):: + the cookie. ``redis_pool`` is a ``redis`` object, created by + ``await aioredis.from_url(...)`` call. $ pip install aiohttp_session[aioredis] diff --git a/aiohttp_session/__init__.py b/aiohttp_session/__init__.py index e810a7a..abbf672 100644 --- a/aiohttp_session/__init__.py +++ b/aiohttp_session/__init__.py @@ -1,6 +1,6 @@ """User sessions for aiohttp.web.""" -__version__ = "2.11.0" +__version__ = "2.12.0" import abc import json @@ -304,7 +304,6 @@ class AbstractStorage(metaclass=abc.ABCMeta): self._cookie_name, domain=params["domain"], path=params["path"] ) else: - # Ignoring type for params until aiohttp#4238 is released response.set_cookie(self._cookie_name, cookie_data, **params) diff --git a/aiohttp_session/redis_storage.py b/aiohttp_session/redis_storage.py index cd447d1..9ef56ce 100644 --- a/aiohttp_session/redis_storage.py +++ b/aiohttp_session/redis_storage.py @@ -1,6 +1,5 @@ import json import uuid -from distutils.version import StrictVersion from typing import Any, Callable, Optional from aiohttp import web @@ -8,9 +7,17 @@ from aiohttp import web from . import AbstractStorage, Session try: - import aioredis + from redis import VERSION as REDIS_VERSION, asyncio as aioredis except ImportError: # pragma: no cover - aioredis = None # type: ignore[assignment] + try: + import aioredis # type: ignore[import, no-redef] # noqa: I900 + except ImportError: + aioredis = None # type: ignore[assignment] + else: + import warnings + warnings.warn("aioredis library is deprecated, please replace with redis.", + DeprecationWarning) + REDIS_VERSION = (4, 3) class RedisStorage(AbstractStorage): @@ -18,7 +25,7 @@ class RedisStorage(AbstractStorage): def __init__( self, - redis_pool: "aioredis.Redis", + redis_pool: "aioredis.Redis[bytes]", *, cookie_name: str = "AIOHTTP_SESSION", domain: Optional[str] = None, @@ -43,13 +50,13 @@ class RedisStorage(AbstractStorage): decoder=decoder, ) if aioredis is None: - raise RuntimeError("Please install aioredis") + raise RuntimeError("Please install redis") # May have installed aioredis separately (without aiohttp-session[aioredis]). - if StrictVersion(aioredis.__version__).version < (2, 0): - raise RuntimeError("aioredis<2.0 is not supported") + if REDIS_VERSION < (4, 3): + raise RuntimeError("redis<4.3 is not supported") self._key_factory = key_factory if not isinstance(redis_pool, aioredis.Redis): - raise TypeError(f"Expected aioredis.Redis got {type(redis_pool)}") + raise TypeError(f"Expected redis.asyncio.Redis got {type(redis_pool)}") self._redis = redis_pool async def load_session(self, request: web.Request) -> Session: @@ -58,12 +65,12 @@ class RedisStorage(AbstractStorage): return Session(None, data=None, new=True, max_age=self.max_age) else: key = str(cookie) - data = await self._redis.get(self.cookie_name + "_" + key) - if data is None: + data_bytes = await self._redis.get(self.cookie_name + "_" + key) + if data_bytes is None: return Session(None, data=None, new=True, max_age=self.max_age) - data = data.decode("utf-8") + data_str = data_bytes.decode("utf-8") try: - data = self._decoder(data) + data = self._decoder(data_str) except ValueError: data = None return Session(key, data=data, new=False, max_age=self.max_age) @@ -82,9 +89,9 @@ class RedisStorage(AbstractStorage): key = str(key) self.save_cookie(response, key, max_age=session.max_age) - data = self._encoder(self._get_session_data(session)) + data_str = self._encoder(self._get_session_data(session)) await self._redis.set( self.cookie_name + "_" + key, - data, - ex=session.max_age, # type: ignore[arg-type] + data_str, + ex=session.max_age, ) diff --git a/debian/changelog b/debian/changelog index 925fb58..8ca468a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +python-aiohttp-session (2.12.0-1) UNRELEASED; urgency=medium + + * Team upload. + * New upstream release. + * Replace python3-aioredis build-dependency with python3-redis. + + -- Colin Watson <cjwatson@debian.org> Tue, 30 Apr 2024 18:17:42 +0100 + python-aiohttp-session (2.11.0-1) unstable; urgency=medium * New upstream version diff --git a/debian/control b/debian/control index 99257c8..ec1f2a9 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,6 @@ Uploaders: Martin <debacle@debian.org> Build-Depends: debhelper-compat (= 13), dh-python, python3-aiohttp, - python3-aioredis, python3-all, python3-attr, python3-chardet, @@ -18,6 +17,7 @@ Build-Depends: debhelper-compat (= 13), python3-pytest-cov, python3-pytest-mock, python3-pytest-sugar, + python3-redis, python3-sphinx, python3-yarl, Standards-Version: 4.1.5 diff --git a/debian/patches/privacy-breach-fixes.patch b/debian/patches/privacy-breach-fixes.patch index 8443bc7..576dde8 100644 --- a/debian/patches/privacy-breach-fixes.patch +++ b/debian/patches/privacy-breach-fixes.patch @@ -1,12 +1,20 @@ -Description: fix documentation privacy breaches -Author: Martin <debacle@debian.org> +From: Martin <debacle@debian.org> +Date: Tue, 30 Apr 2024 18:13:32 +0100 +Subject: fix documentation privacy breaches + Origin: vendor Last-Update: 2019-12-22 + +Last-Update: 2019-12-22 --- -This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ + docs/conf.py | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/docs/conf.py b/docs/conf.py +index aa82e82..bed5f85 100644 --- a/docs/conf.py +++ b/docs/conf.py -@@ -142,11 +142,11 @@ +@@ -142,11 +142,11 @@ html_theme_options = { "description": "user session support for aiohttp.web", "github_user": "aio-libs", "github_repo": "aiohttp-session", diff --git a/debian/patches/use-local-docs-for-intersphinx-links.patch b/debian/patches/use-local-docs-for-intersphinx-links.patch index 94989ff..5d7540c 100644 --- a/debian/patches/use-local-docs-for-intersphinx-links.patch +++ b/debian/patches/use-local-docs-for-intersphinx-links.patch @@ -1,18 +1,26 @@ -Description: use local docs for intersphinx links -Author: Martin <debacle@debian.org> +From: Martin <debacle@debian.org> +Date: Tue, 30 Apr 2024 18:13:32 +0100 +Subject: use local docs for intersphinx links + Origin: vendor Last-Update: 2019-12-22 + +Last-Update: 2019-12-22 --- -This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ + docs/conf.py | 7 +------ + 1 file changed, 1 insertion(+), 6 deletions(-) + +diff --git a/docs/conf.py b/docs/conf.py +index bed5f85..1a47e27 100644 --- a/docs/conf.py +++ b/docs/conf.py -@@ -341,10 +341,5 @@ +@@ -341,10 +341,5 @@ texinfo_documents = [ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - "https://docs.python.org/3": None, - "https://aiohttp.readthedocs.io/en/stable": None, -- "https://aioredis.readthedocs.io/en/latest": None, +- "https://redis.readthedocs.io/en/latest": None, - # 'https://github.com/aio-libs/aiomcache': None, - "http://cryptography.io/en/latest": None, - "https://pynacl.readthedocs.io/en/latest": None, diff --git a/demo/redis_storage.py b/demo/redis_storage.py index 0eab245..126195f 100644 --- a/demo/redis_storage.py +++ b/demo/redis_storage.py @@ -1,8 +1,8 @@ import time from typing import AsyncIterator -import aioredis from aiohttp import web +from redis import asyncio as aioredis from aiohttp_session import get_session, setup from aiohttp_session.redis_storage import RedisStorage @@ -18,10 +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( # type: ignore[no-untyped-call] - redis_address, - timeout=1, - ) as redis: + async with aioredis.from_url(redis_address) as redis: storage = RedisStorage(redis) setup(app, storage) yield diff --git a/docs/conf.py b/docs/conf.py index 6f49d6e..aa82e82 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -343,7 +343,7 @@ texinfo_documents = [ intersphinx_mapping = { "https://docs.python.org/3": None, "https://aiohttp.readthedocs.io/en/stable": None, - "https://aioredis.readthedocs.io/en/latest": None, + "https://redis.readthedocs.io/en/latest": None, # 'https://github.com/aio-libs/aiomcache': None, "http://cryptography.io/en/latest": None, "https://pynacl.readthedocs.io/en/latest": None, diff --git a/docs/glossary.rst b/docs/glossary.rst index 0bb56f4..7ee5860 100644 --- a/docs/glossary.rst +++ b/docs/glossary.rst @@ -10,9 +10,9 @@ aioredis - :term:`asyncio` compatible Redis client library + :term:`asyncio` compatible module in the :term:`redis` library. - https://aioredis.readthedocs.io/ + https://redis-py.readthedocs.io/en/stable/examples/asyncio_examples.html aiomcache diff --git a/docs/index.rst b/docs/index.rst index 1d8528c..c6bbbbd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -79,7 +79,7 @@ Available session storages are: ``e33b57c7ec6e425eb626610f811ab6ae`` (a random UUID) they key inside redis will be ``AIOHTTP_SESSION_e33b57c7ec6e425eb626610f811ab6ae``. - Requires :term:`aioredis` library: + Requires :term:`redis` library: .. code-block:: bash @@ -121,7 +121,7 @@ Dependencies - :term:`cryptography` for :class:`~aiohttp_session.cookie_storage.EncryptedCookieStorage` -- :term:`aioredis` for +- :term:`redis` for :class:`~aiohttp_session.redis_storage.RedisStorage` diff --git a/docs/reference.rst b/docs/reference.rst index 5644524..3577b14 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -378,11 +378,11 @@ Redis Storage The storage that stores session data in Redis database and keeps only Redis keys (UUIDs actually) in HTTP cookies. -It operates with Redis database via :class:`aioredis.RedisPool`. +It operates with Redis database via :class:`redis.asyncio.Redis`. To use the storage you need setup it first:: - redis = await aioredis.create_pool(('localhost', 6379)) + redis = await aioredis.from_url("redis://127.0.0.1:6379") storage = aiohttp_session.redis_storage.RedisStorage(redis) aiohttp_session.setup(app, storage) @@ -398,10 +398,10 @@ To use the storage you need setup it first:: The class is inherited from :class:`~aiohttp_session.AbstractStorage`. - *redis_pool* is a :class:`~aioredis.RedisPool` which should be - created by :func:`~aioredis.create_pool` call, e.g.:: + *redis_pool* is a :class:`~redis.asyncio.Redis` which should be + created by :func:`~redis.asyncio.from_url` call, e.g.:: - redis = await aioredis.create_pool(('localhost', 6379)) + redis = await aioredis.from_url("redis://localhost:6379") storage = aiohttp_session.redis_storage.RedisStorage(redis) Other parameters are the same as for @@ -409,7 +409,7 @@ To use the storage you need setup it first:: Memcached Storage ----------------- +----------------- The storage that stores session data in Memcached and keeps only keys (UUIDs actually) in HTTP cookies. @@ -1,4 +1,5 @@ [pytest] +asyncio_mode = auto filterwarnings= error # This is internal to the docker library. diff --git a/requirements-dev.txt b/requirements-dev.txt index da719a5..e8a6253 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,26 +1,27 @@ -e . -aiohttp==3.8.1 +aiohttp==3.8.3 aiomcache==0.7.0 -aioredis==2.0.0 -attrs==21.4.0 -chardet==4.0.0 -cryptography==36.0.1 -docker==5.0.3 -flake8==4.0.1 -flake8-bandit==2.1.2 -flake8-bugbear==22.1.11 +attrs==22.1.0 +chardet==5.0.0 +cryptography==38.0.1 +docker==6.0.0 +flake8==5.0.4 +flake8-bandit==4.1.1 +flake8-bugbear==22.10.27 flake8-import-order==0.18.1 -flake8-requirements==1.5.2 +flake8-requirements==1.7.3 multidict==6.0.2 -mypy==0.930 +mypy==0.982 pep257==0.7.0 -pre-commit==2.17.0 +pre-commit==2.20.0 pynacl==1.5.0 -pytest==6.2.5 -pytest-aiohttp==1.0.3 -pytest-cov==3.0.0 -pytest-mock==3.7.0 -pytest-sugar==0.9.4 +pytest==7.2.0 +pytest-aiohttp==1.0.4 +pytest-cov==4.0.0 +pytest-mock==3.10.0 +pytest-sugar==0.9.5 +redis==4.3.4 sphinx==4.3.2 -typing-extensions==4.0.1 -yarl==1.7.2 +types-redis==4.3.21.3 +typing-extensions==4.4.0 +yarl==1.8.1 @@ -21,7 +21,7 @@ def read(f): install_requires = ["aiohttp>=3.8", 'typing_extensions>=3.7.4; python_version<"3.8"'] extras_require = { - "aioredis": ["aioredis>=2.0.0"], + "aioredis": ["redis>=4.3.1"], "aiomcache": ["aiomcache>=0.5.2"], "pycrypto": ["cryptography"], "secure": ["cryptography"], diff --git a/tests/conftest.py b/tests/conftest.py index 39fb5d0..61a7abc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import asyncio import gc import socket @@ -7,9 +9,9 @@ import uuid from typing import Iterator import aiomcache -import aioredis import pytest from docker import DockerClient, from_env as docker_from_env, models as docker_models +from redis import asyncio as aioredis if sys.version_info >= (3, 8): from typing import TypedDict @@ -17,10 +19,6 @@ else: from typing_extensions import TypedDict -# TODO: Remove once fixed: https://github.com/aio-libs/aioredis-py/issues/1115 -aioredis.Redis.__del__ = lambda *args: None # type: ignore - - class _ContainerInfo(TypedDict): host: str port: int @@ -106,10 +104,10 @@ def redis_server( # type: ignore[misc] # No docker types. delay = 0.1 for _i in range(20): try: - conn = aioredis.from_url(f"redis://{host}:{port}") # type: ignore[no-untyped-call] # noqa + conn = aioredis.from_url(f"redis://{host}:{port}") event_loop.run_until_complete(conn.set("foo", "bar")) break - except ConnectionError: + except aioredis.ConnectionError: time.sleep(delay) delay *= 2 finally: @@ -134,15 +132,15 @@ def redis_url(redis_server: _ContainerInfo) -> str: # type: ignore[misc] def redis( event_loop: asyncio.AbstractEventLoop, redis_url: str, -) -> Iterator[aioredis.Redis]: - async def start(pool: aioredis.ConnectionPool) -> aioredis.Redis: +) -> Iterator[aioredis.Redis[bytes]]: + async def start(pool: aioredis.ConnectionPool) -> aioredis.Redis[bytes]: return aioredis.Redis(connection_pool=pool) asyncio.set_event_loop(event_loop) pool = aioredis.ConnectionPool.from_url(redis_url) redis = event_loop.run_until_complete(start(pool)) yield redis - event_loop.run_until_complete(redis.close()) # type: ignore[no-untyped-call] + event_loop.run_until_complete(redis.close()) event_loop.run_until_complete(pool.disconnect()) diff --git a/tests/test_encrypted_cookie_storage.py b/tests/test_encrypted_cookie_storage.py index d6805e9..470a75c 100644 --- a/tests/test_encrypted_cookie_storage.py +++ b/tests/test_encrypted_cookie_storage.py @@ -32,7 +32,9 @@ def make_cookie(client: TestClient, fernet: Fernet, data: Dict[str, Any]) -> Non client.session.cookie_jar.update_cookies({"AIOHTTP_SESSION": encrypted_data}) -def create_app(handler: Handler, key: Union[str, bytes, bytearray, Fernet]) -> web.Application: +def create_app( + handler: Handler, key: Union[str, bytes, bytearray, Fernet] +) -> web.Application: middleware = session_middleware(EncryptedCookieStorage(key)) app = web.Application(middlewares=[middleware]) app.router.add_route("GET", "/", handler) @@ -103,7 +105,7 @@ async def test_load_existing_session( async def test_load_existing_session_with_fernet( - aiohttp_client: AiohttpClient, fernet: Fernet + aiohttp_client: AiohttpClient, fernet: Fernet ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) diff --git a/tests/test_redis_storage.py b/tests/test_redis_storage.py index 11466f7..72ea02b 100644 --- a/tests/test_redis_storage.py +++ b/tests/test_redis_storage.py @@ -1,14 +1,16 @@ +from __future__ import annotations + import asyncio import json import time import uuid from typing import Any, Callable, Dict, MutableMapping, Optional, cast -import aioredis import pytest from aiohttp import web from aiohttp.test_utils import TestClient from pytest_mock import MockFixture +from redis import asyncio as aioredis from aiohttp_session import Handler, Session, get_session, session_middleware from aiohttp_session.redis_storage import RedisStorage @@ -18,7 +20,7 @@ from .typedefs import AiohttpClient def create_app( handler: Handler, - redis: aioredis.Redis, + redis: aioredis.Redis[bytes], max_age: Optional[int] = None, key_factory: Callable[[], str] = lambda: uuid.uuid4().hex, ) -> web.Application: @@ -31,7 +33,7 @@ def create_app( async def make_cookie( - client: TestClient, redis: aioredis.Redis, data: Dict[Any, Any] + client: TestClient, redis: aioredis.Redis[bytes], data: Dict[Any, Any] ) -> None: session_data = {"session": data, "created": int(time.time())} value = json.dumps(session_data) @@ -40,23 +42,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) -> None: +async def make_cookie_with_bad_value(client: TestClient, redis: aioredis.Redis[bytes]) -> 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) -> Any: +async def load_cookie(client: TestClient, redis: aioredis.Redis[bytes]) -> Any: cookies = client.session.cookie_jar.filter_cookies(client.make_url("/")) key = cookies["AIOHTTP_SESSION"] - encoded = await redis.get("AIOHTTP_SESSION_" + key.value) - s = encoded.decode("utf-8") - value = json.loads(s) - return value + 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 + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -72,7 +72,7 @@ async def test_create_new_session( async def test_load_existing_session( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -89,7 +89,7 @@ async def test_load_existing_session( async def test_load_bad_session( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -106,7 +106,7 @@ async def test_load_bad_session( async def test_change_session( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -133,7 +133,7 @@ async def test_change_session( async def test_clear_cookie_on_session_invalidation( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -154,7 +154,7 @@ async def test_clear_cookie_on_session_invalidation( async def test_create_cookie_in_handler( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -181,7 +181,7 @@ async def test_create_cookie_in_handler( async def test_set_ttl_on_session_saving( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -201,7 +201,7 @@ async def test_set_ttl_on_session_saving( async def test_set_ttl_manually_set( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -222,7 +222,7 @@ async def test_set_ttl_manually_set( async def test_create_new_session_if_key_doesnt_exists_in_redis( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -236,7 +236,7 @@ async def test_create_new_session_if_key_doesnt_exists_in_redis( async def test_create_storage_with_custom_key_factory( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -259,7 +259,7 @@ async def test_create_storage_with_custom_key_factory( async def test_redis_session_fixation( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def login(request: web.Request) -> web.StreamResponse: session = await get_session(request) @@ -288,7 +288,7 @@ async def test_redis_from_create_pool(redis_url: str) -> None: async def handler(request: web.Request) -> web.StreamResponse: pass - redis = aioredis.from_url(redis_url) # type: ignore[no-untyped-call] + redis = aioredis.from_url(redis_url) create_app(handler=handler, redis=redis) await redis.close() @@ -314,17 +314,13 @@ async def test_old_aioredis_version(mocker: MockFixture) -> None: async def handler(request: web.Request) -> web.StreamResponse: pass - class Dummy: - def __init__(self, *args: object, **kwargs: object) -> None: - self.version = (0, 3) - - mocker.patch("aiohttp_session.redis_storage.StrictVersion", Dummy) + mocker.patch("aiohttp_session.redis_storage.REDIS_VERSION", (0, 3, "dev0")) with pytest.raises(RuntimeError): create_app(handler=handler, redis=None) # type: ignore[arg-type] async def test_load_session_dont_load_expired_session( - aiohttp_client: AiohttpClient, redis: aioredis.Redis + aiohttp_client: AiohttpClient, redis: aioredis.Redis[bytes] ) -> None: async def handler(request: web.Request) -> web.StreamResponse: session = await get_session(request) |