Coder Social home page Coder Social logo

requests-testing's Introduction

Requests-testing =========

image

A utility library for mocking out the requests Python library.

Starting with requests-testing ------

Here is a simple example:

import requests
import requests_testing


@requests_testing.activate
def example():
    requests_testing.add(request={'url': 'http://example.com'}, response={'body': 'ok'})
    resp = requests.get('http://example.com')

    assert resp.text == 'ok'
    assert len(requests_testing.calls) == 1
    assert requests_testing.calls[0].request.url == 'http://example.com/'

If your attempts to fetch a url which doesn't hit a match, ConnectionError will raise:

import requests
import requests_testing

from requests.exceptions import ConnectionError

@responses.activate
def test_error():
    with pytest.raises(ConnectionError):
        requests.get('http://example.com')

requests-testing's People

Contributors

a-pertsev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fabaff

requests-testing's Issues

Tag the source

Could you please tag the source? This allows distributions to get the complete source from GitHub if they want.

Would also help as the source is no published on PyPI.

Thanks

Readme improvements

Hi, really nice lib, thank you!
I suggest include in the readme.str file examples with status_code, headers and calls_limit, like:
requests_testing.add(request={'url': url}, response={'body': 'test', 'status': 418})
requests_testing.add(request={'url': url, 'headers': req_headers}, response={'body': body, 'headers': response_headers})
At first I thought this library don't have status_code and headers features and calls_limit got me some problems until I figure it out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.