Open kimeuichan opened 4 years ago
In my case, use aiohttp in server side..
aiohttp
requests_mock using like this in test case, It's working on server side mock.
requests_mock
with requests_mock.Mocker() as mock: mock.get('/', text='text')
but aioresponses is not working on server side. It's working only test case.. can i used aioresponses in test case for mock server side request??
aioresponses
my server app is falcon and I write test case like this.
def test_main(client): loop = asyncio.get_event_loop() session = aiohttp.ClientSession() with aioresponses() as m: m.get('http://test.example.com', payload=dict(foo='bar')) resp = loop.run_until_complete(session.get('http://test.example.com')) data = loop.run_until_complete(resp.json()) assert dict(foo='bar') == data resp = client.simulate_get('/') assert resp.status == falcon.HTTP_OK session.close()
In my server code
import asyncio import aiohttp import falcon class MainResource: def on_get(self, req, resp): data = { 'abcd': 'abcd', } resp.media = data session = aiohttp.ClientSession() loop = asyncio.get_event_loop() resp = loop.run_until_complete(session.get('http://test.example.com')) api = falcon.API() api.add_route('/', MainResource())
Hello @kimeuichan Try with this
with aioresponses(passthrough=['http://127.0.0.1:']) as m:
In my case, use
aiohttp
in server side..requests_mock
using like this in test case, It's working on server side mock.but
aioresponses
is not working on server side. It's working only test case.. can i usedaioresponses
in test case for mock server side request??my server app is falcon and I write test case like this.
In my server code