From aa53bf83a39ac7700ab378aafe88a902326a963d Mon Sep 17 00:00:00 2001 From: Roman Snegirev Date: Wed, 2 Oct 2024 15:02:21 +0300 Subject: [PATCH] Add `ignore` decorator tests --- pyproject.toml | 4 ++-- tests/conftest.py | 5 +++++ tests/test_auth.py | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 95a3fea..5eb273e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [tool.black] line-length = 99 -target-version = ['py37', 'py38', 'py39'] +target-version = ['py38', 'py39', 'py310', 'py311', 'py312'] skip-string-normalization = true -experimental-string-processing = true +preview = true verbose = true [tool.pytest.ini_options] diff --git a/tests/conftest.py b/tests/conftest.py index 005d9d1..d8a5d7b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,9 +33,14 @@ async def public_view(request): async def secret_view(request): return web.Response(text='Secret view') + @auth.ignore + async def ignored_view(request): + return web.Response(text='Ignored view') + app = web.Application(middlewares=[auth], loop=loop) app.router.add_get('/', public_view) app.router.add_get('/secret', secret_view) + app.router.add_get('/ignored', ignored_view) return app return factory diff --git a/tests/test_auth.py b/tests/test_auth.py index b7d3644..ad0f40b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -19,6 +19,14 @@ async def test_public_views_respond_200_when_auth_not_forced(aiohttp_client, app assert resp.status == 200 +async def test_ignored_views_respond_200_when_auth_forced(aiohttp_client, app_factory): + app = app_factory(auth_force=True) + client = await aiohttp_client(app) + resp = await client.get('/ignored') + + assert resp.status == 200 + + async def test_protected_views_respond_401_when_auth_not_forced(aiohttp_client, app_factory): app = app_factory(auth_force=False) client = await aiohttp_client(app)