Django Blip
Django Blip is a python package that mocks any external API(s) call when running Django test(s). It allows to set global
mocked response and status code for these external API(s) calls. Notably, if you've previously used @httpretty.activate
to mock a test, Django Blip will not overwrite that behavior, ensuring backward compatibility.
How to configure:
pip install django-blipto install in your virtual env.- Add
TEST_RUNNER = "blip.custom_test_runner.BlipTestRunner"in your Django'ssettings.py.
Optionally
3) Add,
BLIP_CONFIG = {
"blip_status_code": 500, # Default 200
"blip_response": '{"key": "value"}', # Default {}
"blip_verbose": False, # Default True
"blip_silently_bypass": False # Default True, If set to False, it will raise an exception if any
# external API call is encountered within the test
}
in your settings.py.
Also if you wanna register any additional url you can do it like this,
from blip.service import BlipService
import httpretty
import json
BLIP_CONFIG = {
"blip_additional_global_mocks": [
BlipService.BlipAdditionalGlobalMocks(
request_uri="https://xyz.com",
request_method=httpretty.POST,
response_status_code=200,
response=json.dumps({"key": "value"}),
)
]
}
Blip will give first priority to urls passed via blip_additional_global_mocks.
Basic Usage
import httpretty
from django.test import TestCase
import requests
import json
class TestBlipWorks(TestCase):
@httpretty.activate(verbose=True, allow_net_connect=False)
def test_blip_do_not_alter_the_behaviour_of_existing_mocked_apis_with_httpretty(self):
url = "https://google.com"
httpretty.register_uri(httpretty.GET, url, body=json.dumps({"key": "value"}), status=500)
# blip's default behaviour is it mocks any api call and return status code = 200 and response={}
# this test will ensure blip don't override existing test which is already decorated with @httpretty.activate
res = requests.get(url)
self.assertEqual(res.json()["key"], "value") # blip returns response = {}
self.assertEqual(res.status_code, 500) # blip returns default 200 status code
def test_blip_works_and_mock_any_api_call(self):
url = "https://google.com"
# blip's default behaviour is it mocks any api call and return status = 200 and response={}
res = requests.get(url)
self.assertEqual(res.json(), {}) # blip returns response = {}
self.assertEqual(res.status_code, 200) # blip returns default 200 status code
In the provided code examples, test_blip_works_and_mock_any_api_call shows that Blip returns a mocked status_code of 200 and an empty response {}. Additionally, in test_blip_do_not_alter_the_behaviour_of_existing_mocked_apis_with_httpretty, you can see how Blip is designed to work seamlessly with @httpretty.activate decorators, ensuring that it doesn't override existing behaviors.
Metadata
Release files for django-blip 0.0.10
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 | Actions |
|---|---|---|---|---|
| django-blip-0.0.10.tar.gz | 5.3 kB | Without provenance | Details for django-blip-0.0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_blip-0.0.10-py3-none-any.whl | Python 3 | none | any | Details for django_blip-0.0.10-py3-none-any.whl |
Total release size: 11.2 kB
Release files / django-blip-0.0.10.tar.gz
| Download URL | django-blip-0.0.10.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
634e0e8d31961f00fb06b8d22bfb04926e0579ead9f4cc26e10da7f5469c6178
|
|
BLAKE2b-256 checksum How to use checksums |
70c5bab71b91bf4e5cb9dad812811c389c2f73227fd3d639bead93cfa42fd846
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Release files / django_blip-0.0.10-py3-none-any.whl
| Download URL | django_blip-0.0.10-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4356609257ca3fd92d180e16a0690c3faef209f25878371f8e31bbf2dcaeac9
|
|
BLAKE2b-256 checksum How to use checksums |
fa9b24e7ef2f6790062d86fc5e2a417847129308347362b1fe3fb65d8afd5a43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Security for django-blip 0.0.10
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.