友好的python客户机到james d.bloom令人敬畏的mockserver
mockserver-client的Python项目详细描述
#mockserver python客户端
[![构建状态](https://travis-ci.org/internap/python-mockserver-client.svg?branch=master)(http s://travis ci.org/internap/python mock server client)
python client to james d.bloom's awesome mockserver:http://www.mock-server.com/
这个库试图使用python的kwargs使它保持简单和直接,以避免大的声明。
响应(代码=401,body="unauthorized"))
```
直接从[pypi](https://pypi.python.org/pypi/kubernetes/)安装
```
请参阅http://www.mock-server.com/mock-server/getting-started.html\start-mockserver
此项目的测试使用docker映像:http s://github.com/internap/python mockserver-friendly client/blob/master/docker compose.yml
覆盖**我们刚刚实现了我们需要的,如果您需要尚未实现的东西,您可以打开一个问题和/或贡献
请求,响应
client=mockserverclient("http://localhost:1080")
client.stub(
请求(method="get",path="/that/thing",querystring={"is":"good"},headers={"so":"good"}),
响应(code=418,body="i'm a teapot",headers={"hi":"haa"})
)
````
*您还可以添加一个"times(n)"作为第三个参数来限制这个存根可以被调用的次数,默认值是unlimited
*所有参数都是可选的。如果没有指定,匹配所有内容。
响应,时间
client=mockserverclient("http://localhost:1080")
请求(method="post",path="/postme",body=json.dumps({"some":"json"})),
响应(code=204,body=json.dumps({"return":"something"}),headers={"content type":"application/json"}),
次(1)
)
client.verify()断言错误!
```
*times(n)参数对于expect
=mock server client("http://localhost:1080")
`````
\来自mockserver import mockserver client,request,response,form
client=mockserverclient("http://localhost:1080")
request(method="post",body=form({"user":"foo","pass":"bar"})),
响应(代码=201)
)
```
这目前采用1级"dict"。对于数组模拟,使用来自mockserver import mockserverclie的`{"key[index]:"value"}`
nt,request,json-response
client=mockserverclient("http://localhost:1080")
client.stub(
request(path="/stuff"),
json-response(code=200,body={"full":"json","structure":["with","stuff",1]})
)
````
将"application/json"内容类型追加到头中。
json_等于
client=mockserverclient("http://localhost:1080")
client.expect(
请求(body=json_等于({"key":"value"})),
响应(),
次(1)
)
`````
这只与提供的json体匹配请求。json对话是自动完成的。
如果您只想匹配给定json的部分,那么您只能使用mockserver import mockserverclient中的"json"contains提供匹配的部分,request,json_包含
client=mockserverclient("http://localhost:1080")
client.expect(
请求(body=json_包含({"key":"value"})),
响应(),
次(1)
)
``````
,即这将匹配{"key":"value"}或{"key":"value","another":"key"}`
##更多文档
目前没有正式文档,但是您可以将测试视为一种文档类型,它们非常明确,易于遵循,有助于阐明每个功能的目的。
super(servermockingtestbase,self).setup()
self.client=mockserverclient(mock server url)
self.client.reset()
def teardown(self):
super(servermockingtestbase,self).teardown()
self.client.verify()
````
如果您没有看到任何日志,请尝试其他日志级别,例如info。
如果问题在代码中,请打开一个问题:)
请随意提出问题并发送一些请求,我们将很高兴看到它们!
确保所有新代码都经过测试,当前测试在mockserver容器上运行。
需要安装https://pypi.python.org/pypi/nose
[![构建状态](https://travis-ci.org/internap/python-mockserver-client.svg?branch=master)(http s://travis ci.org/internap/python mock server client)
python client to james d.bloom's awesome mockserver:http://www.mock-server.com/
这个库试图使用python的kwargs使它保持简单和直接,以避免大的声明。
响应(代码=401,body="unauthorized"))
```
直接从[pypi](https://pypi.python.org/pypi/kubernetes/)安装
```
请参阅http://www.mock-server.com/mock-server/getting-started.html\start-mockserver
此项目的测试使用docker映像:http s://github.com/internap/python mockserver-friendly client/blob/master/docker compose.yml
覆盖**我们刚刚实现了我们需要的,如果您需要尚未实现的东西,您可以打开一个问题和/或贡献
请求,响应
client=mockserverclient("http://localhost:1080")
client.stub(
请求(method="get",path="/that/thing",querystring={"is":"good"},headers={"so":"good"}),
响应(code=418,body="i'm a teapot",headers={"hi":"haa"})
)
````
*您还可以添加一个"times(n)"作为第三个参数来限制这个存根可以被调用的次数,默认值是unlimited
*所有参数都是可选的。如果没有指定,匹配所有内容。
响应,时间
client=mockserverclient("http://localhost:1080")
响应(code=204,body=json.dumps({"return":"something"}),headers={"content type":"application/json"}),
次(1)
)
client.verify()断言错误!
```
*times(n)参数对于expect
=mock server client("http://localhost:1080")
\来自mockserver import mockserver client,request,response,form
client=mockserverclient("http://localhost:1080")
响应(代码=201)
)
```
这目前采用1级"dict"。对于数组模拟,使用来自mockserver import mockserverclie的`{"key[index]:"value"}`
nt,request,json-response
client=mockserverclient("http://localhost:1080")
client.stub(
request(path="/stuff"),
json-response(code=200,body={"full":"json","structure":["with","stuff",1]})
)
````
将"application/json"内容类型追加到头中。
json_等于
client=mockserverclient("http://localhost:1080")
client.expect(
请求(body=json_等于({"key":"value"})),
响应(),
次(1)
)
`````
这只与提供的json体匹配请求。json对话是自动完成的。
如果您只想匹配给定json的部分,那么您只能使用mockserver import mockserverclient中的"json"contains提供匹配的部分,request,json_包含
client=mockserverclient("http://localhost:1080")
client.expect(
请求(body=json_包含({"key":"value"})),
响应(),
次(1)
)
``````
,即这将匹配{"key":"value"}或{"key":"value","another":"key"}`
##更多文档
目前没有正式文档,但是您可以将测试视为一种文档类型,它们非常明确,易于遵循,有助于阐明每个功能的目的。
super(servermockingtestbase,self).setup()
self.client=mockserverclient(mock server url)
self.client.reset()
def teardown(self):
super(servermockingtestbase,self).teardown()
self.client.verify()
````
如果您没有看到任何日志,请尝试其他日志级别,例如info。
如果问题在代码中,请打开一个问题:)
请随意提出问题并发送一些请求,我们将很高兴看到它们!
确保所有新代码都经过测试,当前测试在mockserver容器上运行。
需要安装https://pypi.python.org/pypi/nose