• Stars
    star
    2,107
  • Rank 21,901 (Top 0.5 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 14 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

HTTPretty 1.1.4

image

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

image

image

image

image

image

image

image

image

image

image

image

image

image

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:

More Repositories

1

lettuce

Behavior-driven-development tool for python, inspired by Cucumber for Ruby ⛺
Python
1,274
star
2

sure

idiomatic assertion toolkit with human-friendly failure messages, inspired by RSpec Expectations and should.js
Python
687
star
3

flask-react-bootstrap

Flask + ZeroMQ + ReactJS + Webpack + Bootstrap + Socket.IO
JavaScript
165
star
4

unclebob

django tool for running tests organized between unit, functional and integration
Python
56
star
5

jquery-yql

jQuery plugin for YQL querying with JSONP abstraction and some fancyness
JavaScript
46
star
6

nginx-markdown-module

renderize markdown as HTML directly from your upstream server
C
42
star
7

couleur

ANSI terminal tool for python, colored shell and other handy fancy features
Python
41
star
8

go-horse

Funny, and simple HTTP Server DSL written entirely in C
C
37
star
9

pyenv-action

Enables pyenv within your github actions workflow
TypeScript
34
star
10

tornadio-chat

socket.io + tornado chat example
Python
29
star
11

dominic

jquery-based python-pure implementation of CSS Selectors, good for using with google app engine
Python
18
star
12

bolacha

Bolacha is a simple http client for python, built on top of httplib2, but automatically handles cookies and upload.
Python
17
star
13

dead-parrot

A djangoish RESTful framework in python
Python
16
star
14

steadymark

use your python snippets from your README.md as regression tests
Python
13
star
15

tornado-bdd-sample

simple web application that demonstrate how to use lettuce + webdriver with tornado
Python
13
star
16

django_dreamhost

Super-duper script that configures a clean Python 2.5, Django, PIL, FLUP and Mysql support in Dreamhost
Shell
12
star
17

guake

obsolete guake code, please go to https://github.com/guake/guake instead
Python
11
star
18

markment

markdown + document = markment
CSS
11
star
19

plant

requests for filesystem operations
Python
10
star
20

Makefile-python-basic

Use a good old Makefile in lieu of Pipenv, Poetry etc.
Makefile
10
star
21

tomb

password manager written in rust with TUI, stores aes-256-cbc encrypted data in a yaml file
Rust
10
star
22

agentzero

Python ZeroMQ for Humans
Python
8
star
23

vargas

tempo relativo em português para python
Python
7
star
24

sphinx-bulma-theme

Sphinx Theme based on bulma.io
CSS
7
star
25

jquery-shout

component-based event bus for jquery
JavaScript
6
star
26

sponge

sponge is a web framework aiming to get things dry, built on top of CherryPy
Python
6
star
27

LittleJoy

really tiny framework for php
PHP
5
star
28

plural

A Git-backed graph database as a library
Python
5
star
29

emacs_config

My pretty much customized emacs configuration
Emacs Lisp
4
star
30

chemist

Simple, flexible and testable active-record powered by SQLAlchemy - supports seamless encryption of fields through PyNaCL
Python
4
star
31

mac-disk-monitor

rust library to monitor disk activity on mac os
Rust
4
star
32

djangogevent

Django GEvent support
Python
4
star
33

jquery-embeddata

Embed and retrieve JSON metadata in any HTML tag, with server-side saving and recovering
JavaScript
4
star
34

modelpress

Django-like ORM for wordpress
PHP
3
star
35

keybone

command-line GPG for humans
Python
3
star
36

Projetos-VB6

Visual Basic 6.0
3
star
37

hacklab

Web application for hosting git repositories
JavaScript
3
star
38

heroku-buildpack-aptitude

Shell
3
star
39

gspec

Test runner for the Go language
Go
3
star
40

pyev

python libev interface
C
2
star
41

speakers

Let your python code speak
Python
2
star
42

rustic-toolz

crabby command-line tools
Rust
2
star
43

pycallback-example

Simple example of how to call a python function from inside a C program
C
2
star
44

deadparrot_sample

usage example of deadparrot
Python
2
star
45

ma-cherie

Ma Chérie is a web-based picture viewer powered by CherryPy
Python
2
star
46

vimfiles

my old vim stuff
Vim Script
2
star
47

sagacity

Your dot files are finally modularized now
Shell
2
star
48

happy-time

old repos in which I used to put C and GObject programs
C
2
star
49

tesla-editor

A toy project that combines React + Webpack + Electron + Monaco Editor
JavaScript
2
star
50

from-your-editor-to-pypi

Guide for the workshop: "From your editor to PyPI: Creating and Releasing robust Python packages"
Makefile
2
star
51

carpentry

continuous integration for the people
Python
2
star
52

gabrielfalcao

1
star
53

redis-gnupg

Store GPG-encrypted values in a redis server seamlessly
Python
1
star
54

lineup

Python
1
star
55

tumbler

A flask that you can take to the office
Python
1
star
56

pho

PHOnetic alphabet renderer
Rust
1
star
57

xmpp

stateless and concurrency-agnostic XMPP implementation in python
Python
1
star
58

github-forks-2019-snapshot

For the past 10 years I'd been using the github "fork" feature as a way to favorite interesting repos. In 2019 I used the github API and a personal token to delete all forks and save a snapshot of the JSON data.
1
star
59

shrine

django + tornado
JavaScript
1
star
60

github-py

python library that leverages the GitHub API (includes support to the OAuth2 interface)
Python
1
star
61

pep8checker

Something I was playing with at 2007, a rough pep8 checker made with glib
C
1
star
62

agile

Meta-package for python with tools for an agile development workflow.
Python
1
star
63

echidna

small web framework for golang
Go
1
star