patrys / Httmock
Licence: other
A mocking library for requests
Stars: ✭ 421
Programming Languages
python
139335 projects - #7 most used programming language
Projects that are alternatives of or similar to Httmock
Pytest Responsemock
Simplified requests calls mocking for pytest
Stars: ✭ 24 (-94.3%)
Mutual labels: requests, mock
Drissionpage
A module that integrates selenium and requests session, encapsulates common page operations, can achieve seamless switching between the two modes.
Stars: ✭ 409 (-2.85%)
Mutual labels: requests
Nothing
A chainable, callable mock object which always returns itself
Stars: ✭ 362 (-14.01%)
Mutual labels: mock
Macaca Datahub
Continuous data provider for development, testing, staging and production. Just enjoy the data out-of-the-box.📦
Stars: ✭ 366 (-13.06%)
Mutual labels: mock
S3monkey
A Python library that allows you to interact with Amazon S3 Buckets as if they are your local filesystem.
Stars: ✭ 399 (-5.23%)
Mutual labels: mock
Cpr
C++ Requests: Curl for People, a spiritual port of Python Requests.
Stars: ✭ 4,200 (+897.62%)
Mutual labels: requests
Graphql Tools
🔧 Build, mock, and stitch a GraphQL schema using the schema language
Stars: ✭ 4,556 (+982.19%)
Mutual labels: mock
Khttp
Kotlin HTTP requests library. Similar to Python requests.
Stars: ✭ 410 (-2.61%)
Mutual labels: requests
Many requests
Dead easy interface for executing many HTTP requests asynchronously. Also provides helper functions for executing embarrassingly parallel async coroutines.
Stars: ✭ 384 (-8.79%)
Mutual labels: requests
Bilili
🍻 bilibili video (including bangumi) and danmaku downloader | B站视频(含番剧)、弹幕下载器
Stars: ✭ 379 (-9.98%)
Mutual labels: requests
Rewiremock
The right way to mock dependencies in Node.js or webpack environment.
Stars: ✭ 399 (-5.23%)
Mutual labels: mock
Requests Threads
🎭 Twisted Deferred Thread backend for Requests.
Stars: ✭ 366 (-13.06%)
Mutual labels: requests
Proxy requests
a class that uses scraped proxies to make http GET/POST requests (Python requests)
Stars: ✭ 357 (-15.2%)
Mutual labels: requests
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (-10.93%)
Mutual labels: mock
Miragejs
A client-side server to build, test and share your JavaScript app
Stars: ✭ 4,384 (+941.33%)
Mutual labels: mock
Django Request
django-request is a statistics module for django. It stores requests in a database for admins to see, it can also be used to get statistics on who is online etc.
Stars: ✭ 419 (-0.48%)
Mutual labels: requests
Requests Respectful
Minimalist Requests wrapper to work within rate limits of any amount of services simultaneously. Parallel processing friendly.
Stars: ✭ 417 (-0.95%)
Mutual labels: requests
httmock
A mocking library for requests
for Python 2.7 and 3.4+.
Installation
pip install httmock
Or, if you are a Gentoo user:
emerge dev-python/httmock
Usage
You can use it to mock third-party APIs and test libraries that use requests
internally, conditionally using mocked replies with the urlmatch
decorator:
from httmock import urlmatch, HTTMock
import requests
@urlmatch(netloc=r'(.*\.)?google\.com$')
def google_mock(url, request):
return 'Feeling lucky, punk?'
with HTTMock(google_mock):
r = requests.get('http://google.com/')
print r.content # 'Feeling lucky, punk?'
The all_requests
decorator doesn't conditionally block real requests. If you return a dictionary, it will map to the requests.Response
object returned:
from httmock import all_requests, HTTMock
import requests
@all_requests
def response_content(url, request):
return {'status_code': 200,
'content': 'Oh hai'}
with HTTMock(response_content):
r = requests.get('https://foo_bar')
print r.status_code
print r.content
If you pass in Set-Cookie
headers, requests.Response.cookies
will contain the values. You can also use response
method directly instead of returning a dict:
from httmock import all_requests, response, HTTMock
import requests
@all_requests
def response_content(url, request):
headers = {'content-type': 'application/json',
'Set-Cookie': 'foo=bar;'}
content = {'message': 'API rate limit exceeded'}
return response(403, content, headers, None, 5, request)
with HTTMock(response_content):
r = requests.get('https://api.github.com/users/whatever')
print r.json().get('message')
print r.cookies['foo']
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].