Skip to content

Commit

Permalink
Document how to deal with JSON responses
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBlack85 committed Apr 29, 2019
1 parent 4181337 commit 56859d8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ async def test_foo(aresponses):
return aresponses.Response(status=200, text=str(request.url))

aresponses.add('foo.com', '/', 'get', my_handler)

# JSON response
aresponses.add('foo.com', '/', 'get', aresponses.Response(body=b'{"status":"ok"}'))

url = 'http://foo.com'
async with aiohttp.ClientSession() as session:
Expand All @@ -68,6 +71,10 @@ async def test_foo(aresponses):
async with session.get(url) as response:
text = await response.text()
assert text == 'http://foo.com/'

async with session.get(url) as response:
data = await response.json()
assert data == {"state": "ok"}
```

```python
Expand Down

0 comments on commit 56859d8

Please sign in to comment.