Skip to main content

A simple request-mocker that will download

Project description

frigg coverage Latest Version Downloads

A simple request mocker that caches requests responses to files.

Installation

Install it with pip:

pip install rmoq

Usage

Function decorator

The example below will put the content of fixtures/example.com.txt into the body of the request and if it does not exist the content will be downloaded and stored in fixtures/example.com.txt.

@rmoq.activate()
def test_remote_call():
    response = requests.get('http://example.com')
    assert response.body == 'Example'

The example below works as the one above it just uses the given path (test_fixtures) instead of the default path.

@rmoq.activate('test_fixtures')
def test_remote_call():
    response = requests.get('http://example.com')
    assert response.body == 'Example'

With statements

It can also be used in a with statement

def test_remote_call():
    with rmoq.Mock():
        response = requests.get('http://example.com')
        assert response.body == 'Example'

The mock object can also take a path as an argument.

Class decorator

The decorator will also work for classes, which means you can decorate a whole test-case:

@rmoq.activate()
class RemoteTestCase(unittest.TestCase)
    def test_remote_call():
        response = requests.get('http://example.com')
        assert response.body == 'Example'

MIT © Rolf Erik Lekang

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

rmoq-0.2.5.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

rmoq-0.2.5-py2.py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 2 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