Python 的 HTTP 客户端模拟工具:HTTPretty
jopen
12年前
HTTPretty 是一个 Python 的 HTTP 客户端模拟工具。
示例代码:
import requests from sure import expect from httpretty import HTTPretty from httpretty import httprettified @httprettified def test_yipit_api_returning_deals(): HTTPretty.register_uri(HTTPretty.GET, "http://api.yipit.com/v1/deals/", body='[{"title": "Test Deal"}]', content_type="application/json") response = requests.get('http://api.yipit.com/v1/deals/') expect(response.json()).to.equal([{"title": "Test Deal"}])