requests-mock-flask
requests-mock-flask helps with testing Flask applications with responses or requests-mock.
Installation
Requires Python 3.8+.
pip install requests-mock-flask
Usage example
import flask
import requests
import responses
import requests_mock
from requests_mock_flask import add_flask_app_to_mock
app = flask.Flask(__name__)
@app.route('/')
def _() -> str:
return 'Hello, World!'
@responses.activate
def test_responses_decorator() -> None:
"""
It is possible to use the helper with a ``responses`` decorator.
"""
add_flask_app_to_mock(
mock_obj=responses,
flask_app=app,
base_url='http://www.example.com',
)
response = requests.get('http://www.example.com')
assert response.status_code == 200
assert response.text == 'Hello, World!'
def test_responses_context_manager() -> None:
"""
It is possible to use the helper with a ``responses`` context manager.
"""
with responses.RequestsMock(
assert_all_requests_are_fired=False,
) as resp_m:
add_flask_app_to_mock(
mock_obj=resp_m,
flask_app=app,
base_url='http://www.example.com',
)
response = requests.get('http://www.example.com')
assert response.status_code == 200
assert response.text == 'Hello, World!'
def test_requests_mock_context_manager() -> None:
"""
It is possible to use the helper with a ``requests_mock`` context
manager.
"""
with requests_mock.Mocker() as resp_m:
add_flask_app_to_mock(
mock_obj=resp_m,
flask_app=app,
base_url='http://www.example.com',
)
response = requests.get('http://www.example.com')
assert response.status_code == 200
assert response.text == 'Hello, World!'
def test_requests_mock_adapter() -> None:
"""
It is possible to use the helper with a ``requests_mock`` fixture.
"""
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
add_flask_app_to_mock(
mock_obj=adapter,
flask_app=app,
base_url='mock://www.example.com',
)
response = session.get('mock://www.example.com')
assert response.status_code == 200
assert response.text == 'Hello, World!'
Use cases
Use the requests API for testing applications.
Create a test suite which can test a Flask application as well as a live web application, to make a verified fake.
Test a service which calls a Flask application that you have the source code for.
Full documentation
See the full documentation for more information including how to contribute.
Metadata
Release files for requests-mock-flask 2020.9.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| requests-mock-flask-2020.9.16.0.tar.gz | 20.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| requests_mock_flask-2020.9.16.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.7 kB
Release files / requests-mock-flask-2020.9.16.0.tar.gz
| Download URL | requests-mock-flask-2020.9.16.0.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ad1ef0feb1f1ac9b6816d6ea223ae8f24ff63c113399b4d576097b6397763a6
|
|
BLAKE2b-256 checksum How to use checksums |
cd1fa6ad75e5732b90ead07ad8e84398aee78507fdf76266b21bf0ad4e75de60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
|
Release files / requests_mock_flask-2020.9.16.0-py3-none-any.whl
| Download URL | requests_mock_flask-2020.9.16.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9aa5ec50f02dab7c868d8b0a5ce6636b5888eccf3fb6dcff85d9671ad4829fe8
|
|
BLAKE2b-256 checksum How to use checksums |
e7f690b88b61d6c92b10cfea94adbb0415efd66c5ad41e70ddaf35242558302c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
|
Security for requests-mock-flask 2020.9.16.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.