python 模拟点击第三方软件_python模拟第三方模块

我正在测试一些处理tweets的类。我使用sixohsix twitter来处理twitter API。

我有一个类作为Twitter类的门面,我的想法是模拟实际的sixohix类,通过随机生成新的tweet或从数据库中检索它们来模拟tweet的到达。在

我的门面看起来像:from twitter import TwitterStream

class TwitterFacade(object):

def __init__(self, dev='soom'):

self._auth = OAuth(dev_keys["ACCESS_TOKEN"], dev_keys["ACCESS_SECRET"], dev_keys["CONSUMER_KEY"], dev_keys["CONSUMER_SECRET"])

def tweets(self, callback=None, users=[], terms=[], locations=[], count=5):

t = TwitterStream(auth=self._auth)

args = {}

if users: args['follow'] = ",".join(users)

if terms: args['track'] = ",".join(terms)

if locations: args['locations'] = ",".join(str(l) for l in locations)

# this controls the general loop, it re-enters if there was an exception,

# otherwise the for loop should take care of looping trough the tweets

cant = count

while cant > 0:

try:

iterator = t.statuses.filter(**args)

for twit in iterator:

if twit.get('text'):

callback(twit)

cant -= 1

if cant == 0:

iterator.close()

break

except Exception as e:

print e

#some error handling code

所以,如果在一个单元测试中,我想测试一些对tweets做一些事情的模块,我该如何模拟TwitterStream类呢?

我试过使用Mock:

^{pr2}$

这不起作用,仍在调用twitter api。我本以为,自从没有向mock类添加任何代码之后,我会得到一个错误或其他什么,而是调用了sixhoh6个twitter类。在

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值