Python 的 HTTP 客户端模拟工具:HTTPretty

jopen 11年前

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"}])

项目主页:http://www.open-open.com/lib/view/home/1360931199041