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'})
    requests.post('https://api.test.com/products', data={'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.1.0.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

remocker-0.1.0-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

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