Skip to main content

Mock requests for testing

Project description

Testi Requesti - Mocking utils for pytest.

Mock HTTP Responses by replying Responses from a capture file. patch python's requests.get(), to search in the capture instead of sending an http request. Currently only supports .har files, and patching requests.get

requests

Requests mocked by replying packet captures in .har file format. I plan to implement .pcap files in the future if i find those necessary, and possibly also scripts to craft responses.

currently only the GET verb is implemented and only match by the URL (headers are ignored) and returns the first packet matched.

To generate a HAR file

Firefox

To generate a .har file in Firefox, open the network console (Ctrl + Shift + E) and start browsing. When done, right click on ths capture window and "Save All As HAR".

Examples

inject mocked requests onto requests.get

from testirequesti import Requesti, patch_requests

URL = "https://some-url.com/"

@patch_requests("project_root/tests/data/session.har")
def test_something():
    mocked_response = requests.get(URL)

To find all captured packets to url

requesti = Requesti(HAR_FILE)
url_regex = "^http.*.parliament\.uk"
matched = requesti.find_packets(url_regex)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

testirequesti-0.0.1.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

testirequesti-0.0.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file testirequesti-0.0.1.tar.gz.

File metadata

  • Download URL: testirequesti-0.0.1.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for testirequesti-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cf12293f6f9ee81e29207860a61e5447852bdab4747ff817d8cd459e41f03a52
MD5 b0be4a1a5aa36ff69c62708ed67136ef
BLAKE2b-256 65f89734a50ffadb50e7ed35a57c079e4489ab453ac4179cf5740f8f87fa19f4

See more details on using hashes here.

File details

Details for the file testirequesti-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: testirequesti-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for testirequesti-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6260cacfee0cc1bb3df4f4ec782b6917345aaa8a6dfe890466f6f231ab2de04
MD5 d7a17a0d921819237fd40be8f6505dab
BLAKE2b-256 5fccca1e50bdc59701b15661cdbb2adfcba2c6ffcc106afc1b5561ebda6ced59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page