跳转到主要内容

允许您在测试中轻松模拟HTTP响应

项目描述

https://travis-ci.org/bearstech/responses_proxy.png?branch=master

responses_proxy 允许您在测试中轻松模拟HTTP响应

安装

使用pip

$ pip install responses_proxy

使用docker

$ docker run --rm -v tests/responses:/tests/responses bearstech/responses_proxy -h

使用方法

检查命令行参数

$ responses-proxy -h

首先使用代理模式保存一些内容

$ responses-proxy --proxy

如果您的目标网站使用ssl,则使用

$ responses-proxy --proxy --use-ssl

代理不支持ssl,因此您需要发出http请求。但首先设置 HTTP_PROXY 环境变量

$ export HTTP_PROXY=http://localhost:3333

然后运行一些代码以发出一些请求

python -c "import requests; requests.get('http://bearstech.com')"

这将在 tests/responses/ 中生成一些文件

注意:在使用docker时,您必须挂载卷

$ docker run --rm -v tests/responses:/tests/responses bearstech/responses_proxy

现在您可以在没有代理模式的情况下重新启动服务器,客户端将像没有调用真实服务器一样做出相同的反应。

您还可以在单元测试中使用 RequestsMock

import responses_proxy
import requsests

def test_url():
    with responses_proxy.RequestsMock():
        requests.get('http://bearstech.com')
        # https will work to. both are registered
        requests.get('https://bearstech.com')

项目详情


下载文件

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

源分布

responses_proxy-0.1.4.tar.gz (12.1 kB 查看哈希值)

上传于 源代码

构建版本

responses_proxy-0.1.4-py2.py3-none-any.whl (6.3 kB 查看哈希值)

上传于 Python 2 Python 3

由以下支持