Skip to content

Commit

Permalink
Fix #3290 missing parameter 'raise_for_status' for aiohttp.request() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
artslob authored and asvetlov committed Sep 29, 2018
1 parent cffc9bf commit 36607da
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/3290.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix missing parameter ``raise_for_status`` for aiohttp.request()
2 changes: 2 additions & 0 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ def request(method, url, *,
compress=None,
chunked=None,
expect100=False,
raise_for_status=False,
connector=None,
loop=None,
read_until_eof=True,
Expand Down Expand Up @@ -965,6 +966,7 @@ def request(method, url, *,
compress=compress,
chunked=chunked,
expect100=expect100,
raise_for_status=raise_for_status,
read_until_eof=read_until_eof,
proxy=proxy,
proxy_auth=proxy_auth,),
Expand Down
39 changes: 39 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,45 @@ async def handler_redirect(request):
resp.close()


async def test_request_raise_for_status_default(aiohttp_server) -> None:
async def handler(request):
raise web.HTTPBadRequest()

app = web.Application()
app.router.add_get('/', handler)
server = await aiohttp_server(app)

async with aiohttp.request('GET', server.make_url('/')) as resp:
assert resp.status == 400


async def test_request_raise_for_status_disabled(aiohttp_server) -> None:
async def handler(request):
raise web.HTTPBadRequest()

app = web.Application()
app.router.add_get('/', handler)
server = await aiohttp_server(app)
url = server.make_url('/')

async with aiohttp.request('GET', url, raise_for_status=False) as resp:
assert resp.status == 400


async def test_request_raise_for_status_enabled(aiohttp_server) -> None:
async def handler(request):
raise web.HTTPBadRequest()

app = web.Application()
app.router.add_get('/', handler)
server = await aiohttp_server(app)
url = server.make_url('/')

with pytest.raises(aiohttp.ClientResponseError):
async with aiohttp.request('GET', url, raise_for_status=True):
assert False, "never executed" # pragma: no cover


async def test_invalid_idna() -> None:
session = aiohttp.ClientSession()
try:
Expand Down

0 comments on commit 36607da

Please sign in to comment.