Skip to main content

Cassette 存储和重放 HTTP 请求。

项目描述

Cassette 存储和重放 Python 应用程序中发出的 HTTP 请求。

import urllib2

import cassette

with cassette.play("data/responses.yaml"):

    # If the request is not already stored in responses.yaml, cassette
    # will request the URL and store its response in the file.
    r = urllib2.urlopen("http://www.internic.net/domain/named.root")

    # This time, the request response must be in the file. The external
    # request is not made. cassette retrieves the response from the
    # file.
    r = urllib2.urlopen("http://www.internic.net/domain/named.root")

assert "A.ROOT-SERVERS.NET" in r.read(10000)

Cassette 还支持requests 库。

import requests

with cassette.play("data/responses.yaml"):
    r = requests.get("http://www.internic.net/domain/named.root")

请注意,存储在不同库之间的请求可能彼此不兼容。也就是说,使用urllib2存储的请求可能仍会触发外部请求,因为使用requests 请求的 URL 相同。

安装

$ pip install cassette

文档

最新文档:cassette.readthedocs.org

执照

盒式磁带在 MIT 许可证下可用。

版权所有 Uber 2013,Charles-Axel Dein < charles @ uber com >

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

盒式磁带-0.3.8.zip (25.4 kB 查看哈希

已上传 source