到目前为止,这是我的测试:test_500(self): client = ClientConfiguration(token=token, url=url) client.url = 'https://localhost:1234/v1/' + bucket keys = None try: get_bucket = json.loads(str(client.get_bucket(bucket))) result = get_bucket['result'] except Exception as e: expected_status_code = 500 failure_message = "Expected status code %s but got status code %s" % (expected_status_code, e) self.assertEquals(e, expected_status_code, failure_message)我需要编写一个500在使用'https://localhost:1234/v1/' + bucketurl时返回响应的模拟。这可以通过 unittest 来完成,如果可以,我如何或在哪里可以找到有关此的一些文档?我浏览过这个网站、unittest 文档和 Youtube,但找不到任何特定于我想做的事情。
1 回答
MM们
TA贡献1886条经验 获得超2个赞
我最终使用它来创建我的测试。
最终结果是:
@responses.activate
test_500(self):
responses.add(responses.GET, 'https://localhost:1234/v1/' + bucket,
json={'error': 'server error'}, status=500)
client = ClientConfiguration(token=token, url=url)
client.url = 'https://localhost:1234/v1/'
keys = None
try:
get_bucket = json.loads(str(client.get_bucket(bucket)))
result = get_bucket['result']
except Exception as e:
expected_status_code = 500
failure_message = "Expected status code %s but got status code %s" % (expected_status_code, e)
self.assertEquals(e, expected_status_code, failure_message)
添加回答
举报
0/150
提交
取消