All Projects → gabrielfalcao → Httpretty

gabrielfalcao / Httpretty

Licence: mit
Intercept HTTP requests at the Python socket level. Fakes the whole socket module

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Httpretty

Prig
Prig is a lightweight framework for test indirections in .NET Framework.
Stars: ✭ 106 (-94.51%)
Mutual labels:  testing-tools, mock, mocking
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (-14.72%)
Mutual labels:  testing-tools, mock, mocking
Pester
Pester is the ubiquitous test and mock framework for PowerShell.
Stars: ✭ 2,620 (+35.75%)
Mutual labels:  mock, tdd, mocking
Python Mocket
a socket mock framework - for all kinds of socket animals, web-clients included
Stars: ✭ 209 (-89.17%)
Mutual labels:  mock, tdd, mocking
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (-94.87%)
Mutual labels:  mock, mocking, testing-tools
Mockito
Most popular Mocking framework for unit tests written in Java
Stars: ✭ 12,453 (+545.23%)
Mutual labels:  testing-tools, mock, mocking
Moka
A Go mocking framework.
Stars: ✭ 53 (-97.25%)
Mutual labels:  mock, tdd, mocking
Mocktopus
Mocking framework for Rust
Stars: ✭ 179 (-90.73%)
Mutual labels:  testing-tools, mock, mocking
Testdeck
Object oriented testing
Stars: ✭ 206 (-89.33%)
Mutual labels:  decorators, testing-tools, tdd
Mockito Scala
Mockito for Scala language
Stars: ✭ 231 (-88.03%)
Mutual labels:  testing-tools, mock, tdd
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (-98.65%)
Mutual labels:  mock, tdd, mocking
Retromock
Java library for mocking responses in a Retrofit service.
Stars: ✭ 48 (-97.51%)
Mutual labels:  mock, mocking, testing-tools
Webmockr
R library for stubbing and setting expectations on HTTP requests
Stars: ✭ 37 (-98.08%)
Mutual labels:  testing-tools, mock, tdd
Testdouble.js
A minimal test double library for TDD with JavaScript
Stars: ✭ 1,214 (-37.1%)
Mutual labels:  testing-tools, mocking
Gock
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
Stars: ✭ 1,185 (-38.6%)
Mutual labels:  mock, mocking
Cuckoo
Boilerplate-free mocking framework for Swift!
Stars: ✭ 1,344 (-30.36%)
Mutual labels:  mock, mocking
Go Dynamock
Amazon Dynamo DB Mock Driver for Golang to Test Database Interactions
Stars: ✭ 71 (-96.32%)
Mutual labels:  mock, tdd
Unit Threaded
Advanced unit test framework for D
Stars: ✭ 100 (-94.82%)
Mutual labels:  mock, mocking
Mongodb Memory Server
Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).
Stars: ✭ 1,376 (-28.7%)
Mutual labels:  testing-tools, mock
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+420.62%)
Mutual labels:  mock, mocking

HTTPretty 1.1.4

https://github.com/gabrielfalcao/HTTPretty/raw/master/docs/source/_static/logo.svg?sanitize=true

HTTP Client mocking tool for Python created by Gabriel Falcão . It provides a full fake TCP socket module. Inspired by FakeWeb

Python Support:

  • 3.6
  • 3.7
  • 3.8
  • 3.9
https://img.shields.io/pypi/dm/HTTPretty https://img.shields.io/codecov/c/github/gabrielfalcao/HTTPretty https://img.shields.io/github/workflow/status/gabrielfalcao/HTTPretty/HTTPretty%20Tests?label=Python%203.6%20-%203.9 https://img.shields.io/readthedocs/httpretty https://img.shields.io/github/license/gabrielfalcao/HTTPretty?label=Github%20License https://img.shields.io/pypi/v/HTTPretty https://img.shields.io/pypi/l/HTTPretty?label=PyPi%20License https://img.shields.io/pypi/format/HTTPretty https://img.shields.io/pypi/status/HTTPretty https://img.shields.io/pypi/pyversions/HTTPretty https://img.shields.io/pypi/implementation/HTTPretty https://img.shields.io/snyk/vulnerabilities/github/gabrielfalcao/HTTPretty https://img.shields.io/github/v/tag/gabrielfalcao/HTTPretty

Install

pip install httpretty

Common Use Cases

  • Test-driven development of API integrations
  • Fake responses of external APIs
  • Record and playback HTTP requests

Simple Example

import sure
import httpretty
import requests


@httpretty.activate(verbose=True, allow_net_connect=False)
def test_httpbin():
    httpretty.register_uri(
        httpretty.GET,
        "https://httpbin.org/ip",
        body='{"origin": "127.0.0.1"}'
    )

    response = requests.get('https://httpbin.org/ip')
    response.json().should.equal({'origin': '127.0.0.1'})

    httpretty.latest_requests().should.have.length_of(1)
    httpretty.last_request().should.equal(httpretty.latest_requests()[0])
    httpretty.last_request().body.should.equal('{"origin": "127.0.0.1"}')

checking multiple responses

@httpretty.activate(verbose=True, allow_net_connect=False)
def test_post_bodies():
    url = 'http://httpbin.org/post'
    httpretty.register_uri(httpretty.POST, url, status=200)
    httpretty.register_uri(httpretty.POST, url, status=400)
    requests.post(url, data={'foo': 'bar'})
    requests.post(url, data={'zoo': 'zoo'})
    assert 'foo=bar' in httpretty.latest_requests()[0].body
    assert 'zoo=bar' in httpretty.latest_requests()[1].body

License

<HTTPretty - HTTP client mock for Python>
Copyright (C) <2011-2021> Gabriel Falcão <[email protected]>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Main contributors

HTTPretty has received many contributions but some folks made remarkable contributions and deserve extra credit:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].