Skip to content

Commit

Permalink
add some coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegt0rr committed Apr 15, 2024
1 parent 5a6949d commit 15d1454
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 8 deletions.
27 changes: 27 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3610,3 +3610,30 @@ async def not_ok_handler(request):
"/ok", timeout=aiohttp.ClientTimeout(total=0.01)
) as resp_ok:
assert 200 == resp_ok.status


async def test_request_with_wrong_ssl_type(aiohttp_client: AiohttpClient) -> None:
app = web.Application()
session = await aiohttp_client(app)

with pytest.raises(TypeError, match="ssl should be SSLContext, Fingerprint, .*"):
await session.get("/", ssl=42) # type: ignore[arg-type]


async def test_request_with_wrong_proxy(aiohttp_client: AiohttpClient) -> None:
app = web.Application()
session = await aiohttp_client(app)

with pytest.raises(TypeError):
await session.get("/", proxy=42) # type: ignore[arg-type]


async def test_raise_for_status_is_none(aiohttp_client: AiohttpClient) -> None:
async def handler(_: web.Request) -> web.Response:
return web.Response()

app = web.Application()
app.router.add_get("/", handler)
session = await aiohttp_client(app, raise_for_status=None) # type: ignore[arg-type]

await session.get("/")
21 changes: 21 additions & 0 deletions tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from http.cookies import SimpleCookie
from typing import Any, List
from unittest import mock
from uuid import uuid4

import pytest
from multidict import CIMultiDict, MultiDict
Expand Down Expand Up @@ -851,3 +852,23 @@ async def test_instantiation_with_invalid_timeout_value(loop):
ClientSession(timeout=1)
# should not have "Unclosed client session" warning
assert not logs


@pytest.mark.parametrize(
("outer_name", "inner_name"),
[
("skip_auto_headers", "_skip_auto_headers"),
("auth", "_default_auth"),
("json_serialize", "_json_serialize"),
("connector_owner", "_connector_owner"),
("raise_for_status", "_raise_for_status"),
("trust_env", "_trust_env"),
("trace_configs", "_trace_configs"),
],
)
async def test_properties(
session: ClientSession, outer_name: str, inner_name: str
) -> None:
value = uuid4()
setattr(session, inner_name, value)
assert value == getattr(session, outer_name)
9 changes: 9 additions & 0 deletions tests/test_client_ws_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aiohttp import hdrs, web
from aiohttp.client_ws import ClientWSTimeout
from aiohttp.http import WSCloseCode
from aiohttp.pytest_plugin import AiohttpClient

if sys.version_info >= (3, 11):
import asyncio as async_timeout
Expand Down Expand Up @@ -897,3 +898,11 @@ async def handler(request):
assert "answer" == msg.data

await resp.close()


async def test_ws_connect_with_wrong_ssl_type(aiohttp_client: AiohttpClient) -> None:
app = web.Application()
session = await aiohttp_client(app)

with pytest.raises(TypeError, match="ssl should be SSLContext, .*"):
await session.ws_connect("/", ssl=42)
2 changes: 1 addition & 1 deletion tests/test_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def test_test_client_props() -> None:

async def test_test_client_raw_server_props() -> None:
async def hello(request):
return web.Response(body=_hello_world_bytes)
return web.Response() # pragma: no cover

server = _RawTestServer(hello, scheme="http", host="127.0.0.1")
client = _TestClient(server)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_app_run_middlewares() -> None:
assert root._run_middlewares is False

async def middleware(request: web.Request, handler: Handler) -> web.StreamResponse:
return await handler(request)
return await handler(request) # pragma: no cover

root = web.Application(middlewares=[middleware])
sub = web.Application()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Logger:
async def test_app_make_handler_access_log_class1() -> None:
class Logger(AbstractAccessLogger):
def log(self, request, response, time):
pass
"""Pass log method."""

app = web.Application()
runner = web.AppRunner(app, access_log_class=Logger)
Expand All @@ -176,7 +176,7 @@ def log(self, request, response, time):
async def test_app_make_handler_access_log_class2() -> None:
class Logger(AbstractAccessLogger):
def log(self, request, response, time):
pass
"""Pass log method."""

app = web.Application(handler_args={"access_log_class": Logger})
runner = web.AppRunner(app)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ async def test_handler_metadata_persistence() -> None:

async def async_handler(request: web.Request) -> web.Response:
"""Doc"""
return web.Response()
return web.Response() # pragma: no cover

app.router.add_get("/async", async_handler)

Expand Down Expand Up @@ -558,7 +558,7 @@ def test_reuse_last_added_resource(path: str) -> None:
app = web.Application()

async def handler(request: web.Request) -> web.Response:
return web.Response()
return web.Response() # pragma: no cover

app.router.add_get(path, handler, name="a")
app.router.add_post(path, handler, name="a")
Expand All @@ -570,7 +570,7 @@ def test_resource_raw_match() -> None:
app = web.Application()

async def handler(request: web.Request) -> web.Response:
return web.Response()
return web.Response() # pragma: no cover

route = app.router.add_get("/a", handler, name="a")
assert route.resource is not None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

try:
import uvloop
except ImportError:
except ImportError: # pragma: no cover
uvloop = None # type: ignore[assignment]


Expand Down

0 comments on commit 15d1454

Please sign in to comment.