Skip to main content

mocking http request more easy

Project description

remocker

mocking http request more easy

installing

pip install remocker

How to use

First, you define Remocker app.

from remocker import Remocker, RemockerRequest, RemockerResponse

mocker_app = Remocker('https://api.test.com')

@mocker_app.mock(method='GET', path='products')
def get_products_mocker(request: RemockerRequest):
    return RemockerResponse({
        'success': True,
        'given_params': request.query_params,
    })

@mocker_app.mock(method='POST', path='products')
def create_product_mocker(request: RemockerRequest):
    return RemockerResponse({
        'success': True,
        'given_data': request.data,
    })

@mocker_app.mock(method='GET', path=r'products/(?P<product_id>\d+)', regex=True)
def get_product_mocker(request: RemockerRequest):
    return RemockerResponse({
        'success': True,
        'given_product_id': request.url_params['product_id'],
    })

Next, you can use mocking context manager.

import requests

with mocker_app.mocking():
    requests.get('https://api.test.com/products', params={'foo': 'var'})
    # Remocker only allow json request. Not form data
    requests.post('https://api.test.com/products', json={'foo': 'var'})
    requests.get('https://api.test.com/products/1')


# Also can
import remocker

with remocker.mocking(mocker_app):
    ...

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

remocker-0.3.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

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

remocker-0.3.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file remocker-0.3.0.tar.gz.

File metadata

  • Download URL: remocker-0.3.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-49-generic

File hashes

Hashes for remocker-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d9f9a48633a8661eef90284e15ced45adee31d352865efeea2ce0fcebcb355a2
MD5 0f344dffd6ae46584704768b0f3a014d
BLAKE2b-256 0cc01d3b305ae3699965be9d7cca1a9d5e0566ed2ed0d2f15ca8518172ae34c8

See more details on using hashes here.

File details

Details for the file remocker-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: remocker-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-49-generic

File hashes

Hashes for remocker-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42c740b4c3f19ec88edea297499bf615d5b9943f146907c375abb42ad03823e1
MD5 a2dda985fa81db4dd047627fb512b8aa
BLAKE2b-256 726a4e5e356df43d45afbdaae6aac695bb255e5dc9074e8325b7188853ab5296

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