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.2.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

remocker-0.2.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for remocker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 13937578b91c53050d6570696f4a90f036026b92518ab33aa26f2ef925fd5662
MD5 777a8b58054b8720a9755722e472ca36
BLAKE2b-256 9bc5ab0b2d2fc89fbe9cffa54562b61ebe45079e8fa9628d0a22f7f029620e69

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for remocker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc1abb64f47d3ce79a9b36f9bc38f9c5631a3908f288b9e2f30b0f3bd8b5f8ec
MD5 748471fbdec59aec65e3981abe548646
BLAKE2b-256 179e7be8dc0cf4a00a293e558e20370756e19a54dc2490c741e335b8769634cc

See more details on using hashes here.

Supported by

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