HTTPretty是一个Python的HTTP客户端模拟工具。
示例代码:
importrequestsfromsureimportexpectfromhttprettyimportHTTPrettyfromhttprettyimporthttprettified@httprettifieddeftest_yipit_api_returning_deals():HTTPretty.register_uri(HTTPretty.GET,"https://api.yipit.com/v1/deals/",body='[{"title":"TestDeal"}]',content_type="application/json")response=requests.get('https://api.yipit.com/v1/deals/')expect(response.json()).to.equal([{"title":"TestDeal"}])
评论