No project description provided
Project description
Testing utilities for aiohttp. Python 3.5+ only.
Installation
$ pip install testing-aiohttp
Usage
rsps.MockRoutesTestCase
The MockRoutesTestCase will set up a mock application for mocking response.
The API is inspired by the responses library:
from aiohttp.test_utils import unittest_run_loop from testing_aiohttp.rsps import MockRoutesTestCase # Create your tests here. class MyTestCase(MockRoutesTestCase): @unittest_run_loop async def test_response_data(self): with self.mock_response() as rsps: rsps.add('GET', '/users', data=[ { 'id': 1, 'username': 'user1', 'group': 'watchers', }, { 'id': 2, 'username': 'user2', 'group': 'watchers', }, ]) response = await self.client.get('/users') self.assertEqual(response, 200) users = await response.json() self.assertEqual(len(users), 2)
from aiohttp.test_utils import unittest_run_loop from testing_aiohttp.rsps import MockRoutesTestCase async def request_callback(request): return (200, {}, await request.text()) class MyTestCase(MockRoutesTestCase): @unittest_run_loop async def test_endpoint_detail_route(self): with self.mock_response() as rsps: rsps.add_callback( 'POST', '/users/2/notify', callback=request_callback, content_type='application/json', ) response = await self.generic_client.users(id=2).notify(unread=3) self.assertEqual(await response.json(), {'unread': 3})
from aiohttp.test_utils import unittest_run_loop from testing_aiohttp.rsps import MockRoutesTestCase class MyTestCase(MockRoutesTestCase): @unittest_run_loop async def test_response_match_querystring(self): with self.mock_response() as rsps: rsps.add('GET', '/users?username=user1', [ { 'id': 1, 'username': 'user1', 'group': 'watchers', }, ], match_querystring=True) response = await self.client.get('/users', params={'username': 'user1'}) self.assertEqual(response.status, 200) users = await response.json() self.assertEqual(len(users), 1) with self.assertRaises(RouteNotFoundError): with self.mock_response() as rsps: rsps.add('GET', '/users?username=user1', [ { 'id': 1, 'username': 'user1', 'group': 'watchers', }, ], match_querystring=True) await self.client.get('/users')
License
Licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
testing-aiohttp-0.0.4.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file testing-aiohttp-0.0.4.tar.gz
.
File metadata
- Download URL: testing-aiohttp-0.0.4.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb60147e6c1aa122f3e5d6c72cc5041a4b5029cd5412f638334988e15290a18 |
|
MD5 | 5e302c329335dd2535dc3ac046e199b7 |
|
BLAKE2b-256 | 77975c075cfeac2202fd3b1bcb8de3b7e8f98750bc4be9966273e912bece70db |
Provenance
File details
Details for the file testing_aiohttp-0.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: testing_aiohttp-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3a8d4655b3b8fb1c9d1a0f3fc31cb02babc70fb007f24c3cca0efa1678e6a8a |
|
MD5 | 986bc27e43b1794805fef2849402cf76 |
|
BLAKE2b-256 | ac65d5d9953fa993273ddf8ffa673ba9450aca0d014e1edf59815e609f5ce3c6 |