aioresponses | fake web requests in python aiohttp package | Reactive Programming library
kandi X-RAY | aioresponses Summary
kandi X-RAY | aioresponses Summary
Aioresponses is a helper for mock/fake web requests in python aiohttp package.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Wrapper for requests
- Build the headers from the headers dict
- Sends a GET request
- Build a response object
- Return True if response is an exception
- Normalize a URL
- Merge query params into a new URL
- Build a client response
- Matches given URL
- Match method
- Returns True if the given URL matches the regexp
- Return True if the given URL matches this request
- Add a HEAD request
- Add a PUT request
- Add a PATCH request
- Add a DELETE request
- Add an OPTIONS request
aioresponses Key Features
aioresponses Examples and Code Snippets
Community Discussions
Trending Discussions on aioresponses
QUESTION
I have a Sanic app that makes some async calls to an external api. I wish to write some unit tests which mock these external calls.
In the code below the tests do pass as we can see from the logs. However after they have completed a RuntimeError: this event loop is already running is thrown
Simplified Sanic app:
...ANSWER
Answered 2019-Jun-14 at 10:15I think you can fix your bug by changing this method:
QUESTION
Using aiohttp for both client requests and websocket connection I am trying to find a proper pytest implementation.
For client requests I am using aioresponses
https://pypi.python.org/pypi/aioresponses/0.1.2
For mocking a websocket connecting I am not sure what to do. Anyone any suggestions ?
Thanks !
...ANSWER
Answered 2017-Nov-12 at 07:14Don't mock but use fake server for testing the client (like you probably use a test client provided by aiohttp for testing the server).
Example of fake client: https://github.com/aio-libs/aiohttp/blob/master/examples/fake_server.py
The example doesn't demonstrate websockets usage but I pretty sure you've got my idea and have enough knowledge to extend the shown approach to websockets.
[edit]
In WSGI world testing against a fake server is hard: it requires a separate thread at least. It asyncio the task is pretty easy.
Thus please don't get me wrong. I don't advise against aioresponses etc, I just want to emphasize: in asyncio world the need for mocking responses is pretty low.
The fake server based approach is much more reliable: you are testing the whole transport layer, not only mocked (monkey-patched actually) data.
Libraries like aioresponse uses private attributes of aiohttp classes, the behavior could be broken by next aiohttp release. Moreover it is maybe broken already in some rare use cases.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install aioresponses
You can use aioresponses like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page