Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a few more get_response tests
  • Loading branch information
cognifloyd committed Dec 7, 2019
commit f3e763efefdacf7e48339bc2db6657430b56cd99
22 changes: 22 additions & 0 deletions tests/aiohttp/test_get_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def test_get_response_from_string(api):
assert dict(response.headers) == {'Content-Type': 'text/plain; charset=utf-8'}


@asyncio.coroutine
def test_get_response_from_string_tuple(api):
response = yield from api.get_response(('foo',))
assert isinstance(response, web.Response)
assert response.status == 200
assert response.body == b'foo'
assert response.content_type == 'text/plain'
assert dict(response.headers) == {'Content-Type': 'text/plain; charset=utf-8'}


@asyncio.coroutine
def test_get_response_from_string_status(api):
response = yield from api.get_response(('foo', 201))
Expand All @@ -53,6 +63,16 @@ def test_get_response_from_string_status(api):
assert dict(response.headers) == {'Content-Type': 'text/plain; charset=utf-8'}


@asyncio.coroutine
def test_get_response_from_string_headers(api):
response = yield from api.get_response(('foo', {'X-header': 'value'}))
assert isinstance(response, web.Response)
assert response.status == 200
assert response.body == b'foo'
assert response.content_type == 'text/plain'
assert dict(response.headers) == {'Content-Type': 'text/plain; charset=utf-8', 'X-header': 'value'}


@asyncio.coroutine
def test_get_response_from_string_status_headers(api):
response = yield from api.get_response(('foo', 201, {'X-header': 'value'}))
Expand All @@ -75,6 +95,8 @@ def test_get_response_from_dict(api):
response = yield from api.get_response({'foo': 'bar'})
assert isinstance(response, web.Response)
assert response.status == 200
# odd, yes. but backwards compatible. see test_response_with_non_str_and_non_json_body in tests/aiohttp/test_aiohttp_simple_api.py
# TODO: This should be made into JSON when aiohttp and flask serialization can be harmonized.
assert response.body == b"{'foo': 'bar'}"
assert response.content_type == 'text/plain'
assert dict(response.headers) == {'Content-Type': 'text/plain; charset=utf-8'}
Expand Down