httpservermock
httpservermock provides a HTTP server mock that can be used to test code that needs to interact with an HTTP server.
pip install httpservermock
# or
poetry add --dev httpservermock
Example usage:
from urllib.error import HTTPError
from urllib.request import urlopen
import pytest
from httpservermock import MethodName, MockHTTPResponse, ServedBaseHTTPServerMock
def test_example() -> None:
with ServedBaseHTTPServerMock() as httpmock:
httpmock.responses[MethodName.GET].append(
MockHTTPResponse(404, "Not Found", b"gone away", {})
)
httpmock.responses[MethodName.GET].append(
MockHTTPResponse(200, "OK", b"here it is", {})
)
# send a request to get the first response
with pytest.raises(HTTPError) as raised:
urlopen(f"{httpmock.url}/bad/path")
assert raised.value.code == 404
# get and validate request that the mock received
req = httpmock.requests[MethodName.GET].pop(0)
assert req.path == "/bad/path"
# send a request to get the second response
resp = urlopen(f"{httpmock.url}/")
assert resp.status == 200
assert resp.read() == b"here it is"
httpmock.responses[MethodName.GET].append(
MockHTTPResponse(404, "Not Found", b"gone away", {})
)
httpmock.responses[MethodName.GET].append(
MockHTTPResponse(200, "OK", b"here it is", {})
)
Metadata
Release files for httpservermock 0.1.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 | Actions |
|---|---|---|---|---|
| httpservermock-0.1.0.tar.gz | 7.7 kB | Without provenance | Details for httpservermock-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| httpservermock-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for httpservermock-0.1.0-py3-none-any.whl |
Total release size: 15.3 kB
Release files / httpservermock-0.1.0.tar.gz
| Download URL | httpservermock-0.1.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50040da959d83a31a50dcfdbf336ec9d8a810287c7f1336c5be30e901967ed30
|
|
BLAKE2b-256 checksum How to use checksums |
3dbfae99defe32a5afd45d1616f2dc8623e464e1ded5963bb1882bcd8c649292
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.6.15 Linux/5.4.109+
|
Release files / httpservermock-0.1.0-py3-none-any.whl
| Download URL | httpservermock-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c48d512a2e048345e0acc98760d8ab9c5de66390cc2f65ab516586529445582
|
|
BLAKE2b-256 checksum How to use checksums |
7ab58044cd1616bb8149762109982b7a3671f0eba298e8e0128dfd130364cb69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.6.15 Linux/5.4.109+
|
Security for httpservermock 0.1.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.