本文整理汇总了Python中test_utils.RequestFactory.twitter方法的典型用法代码示例。如果您正苦于以下问题:Python RequestFactory.twitter方法的具体用法?Python RequestFactory.twitter怎么用?Python RequestFactory.twitter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test_utils.RequestFactory
的用法示例。
在下文中一共展示了RequestFactory.twitter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_mocked_tweet_request
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import twitter [as 别名]
def _create_mocked_tweet_request(self):
request = RequestFactory().post(
reverse('customercare.twitter_post'),
{'reply_to': 1,
'content': '@foobar try Aurora! #fxhelp'})
request.session = {}
request.twitter = Mock()
request.twitter.authed = True
request.twitter.api = Mock()
return_value = {
'id': 123456790,
'text': '@foobar try Aurora! #fxhelp',
'created_at': datetime.strftime(datetime.utcnow(),
'%a %b %d %H:%M:%S +0000 %Y'),
'user': {
'lang': 'en',
'id': 42,
'screen_name': 'r1cky',
'profile_image_url': 'http://example.com/profile.jpg',
'profile_image_url_https': 'https://example.com/profile.jpg',
}
}
request.twitter.api.update_status.return_value = return_value
credentials = {'screen_name': 'r1cky'}
request.twitter.api.verify_credentials.return_value = credentials
request.user = Mock()
request.user.is_authenticated.return_value = False
return request
示例2: test_post_reply
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import twitter [as 别名]
def test_post_reply(self):
# Create a Tweet to reply to.
Tweet.objects.create(
pk=1,
raw_json='{}',
locale='en',
created=datetime.now())
# Create a request and mock all the required properties and methods.
request = RequestFactory().post(
reverse('customercare.twitter_post'),
{'reply_to': 1,
'content': '@foobar try Aurora! #fxhelp'})
request.session = {}
request.twitter = Mock()
request.twitter.authed = True
request.twitter.api = Mock()
return_value = {
'id': 123456790,
'text': '@foobar try Aurora! #fxhelp',
'created_at': datetime.strftime(datetime.utcnow(),
'%a %b %d %H:%M:%S +0000 %Y'),
'user': {
'lang': 'en',
'id': 42,
'screen_name': 'r1cky',
'profile_image_url': 'http://example.com/profile.jpg',
'profile_image_url_https': 'https://example.com/profile.jpg',
}
}
request.twitter.api.update_status.return_value = return_value
credentials = {'screen_name': 'r1cky'}
request.twitter.api.verify_credentials.return_value = credentials
request.user = Mock()
request.user.is_authenticated = lambda: False
# Pass the request to the view and verify response.
response = twitter_post(request)
eq_(200, response.status_code)
# Verify the reply was inserted with the right data.
reply = Reply.objects.all()[0]
eq_('r1cky', reply.twitter_username)
eq_(1, reply.reply_to_tweet_id)
eq_('@foobar try Aurora! #fxhelp', json.loads(reply.raw_json)['text'])