【发布时间】:2014-10-14 00:16:31
【问题描述】:
我有一个发送到外部服务器的类,自然会检索我对其进行一些处理的数据。我真的需要对整个事情进行单元测试,但我不想每次提出请求时都一直访问外部服务器。我的问题:什么是正确的协议?我正在使用生菜,但我也愿意接受其他想法。
这是我的课:
## in my class
class SomeClass:
def doHttpGet(self):
## return request from http://somewhere.com
应该发生的是我覆盖 doHttpGet...
class SomeClass:
def doHttpGet(self):
## return { "some": "data", "which": "mocks" }
【问题讨论】:
-
你见过:voidspace.org.uk/python/mock 吗?
-
对于它的价值,在我的 http 获取代码中,我有一个全局
if TESTING: ...语句,它将所有远程 http 请求重新路由到驻留在我系统上的静态测试文件。不是最优雅的,但它确实有效。 -
如何从
somewhere.com获取数据?是通过urllib(2)吗?
标签: python django unit-testing lettuce