• Stars
    star
    2,092
  • Rank 21,174 (Top 0.5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 1 month 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,269
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

markment

markdown + document = markment
CSS
11
star
18

guake

obsolete guake code, please go to https://github.com/guake/guake instead
Python
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

gspec

Test runner for the Go language
Go
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

modelpress

Django-like ORM for wordpress
PHP
3
star
40

pyev

python libev interface
C
2
star
41

ma-cherie

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

rustic-toolz

crabby command-line tools
Rust
2
star
43

deadparrot_sample

usage example of deadparrot
Python
2
star
44

pycallback-example

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

vimfiles

my old vim stuff
Vim Script
2
star
46

sagacity

Your dot files are finally modularized now
Shell
2
star
47

happy-time

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

tesla-editor

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

from-your-editor-to-pypi

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

carpentry

continuous integration for the people
Python
2
star
51

speakers

Let your python code speak
Python
2
star
52

shrine

django + tornado
JavaScript
1
star
53

redis-gnupg

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

agile

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

lineup

Python
1
star
56

tumbler

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

pho

PHOnetic alphabet renderer
Rust
1
star
58

xmpp

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

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
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

echidna

small web framework for golang
Go
1
star
63

pyright

Static type checker for Python
Python
1
star
64

tenacity

Retrying library for Python
Python
1
star