当前位置: 首页>>代码示例>>Python>>正文


Python RequestFactory.session方法代码示例

本文整理汇总了Python中test_utils.RequestFactory.session方法的典型用法代码示例。如果您正苦于以下问题:Python RequestFactory.session方法的具体用法?Python RequestFactory.session怎么用?Python RequestFactory.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test_utils.RequestFactory的用法示例。


在下文中一共展示了RequestFactory.session方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_session_version_sidebar

# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import session [as 别名]
    def test_session_version_sidebar(self):
        request = RequestFactory()
        request.GET = {}
        request.session = {}
        request.APP = amo.FIREFOX

        request.get(reverse('search.search'))
        facets = {
            u'platforms': [{u'count': 58, u'term': 1}],
            u'appversions': [{u'count': 58, u'term': 5000000200100}],
            u'categories': [{u'count': 55, u'term': 1}],
            u'tags': [],
        }
        versions = version_sidebar(request, {}, facets)
        assert versions[0].selected

        versions = version_sidebar(request, {'appver': '5.0'}, facets)
        assert versions[1].selected

        versions = version_sidebar(request, {}, facets)
        assert versions[1].selected

        request.GET['appver'] = ''
        versions = version_sidebar(request, {}, facets)
        assert versions[0].selected
开发者ID:at-kevinlau,项目名称:zamboni,代码行数:27,代码来源:test_views.py

示例2: _create_mocked_tweet_request

# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import session [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
开发者ID:Archaeopteryx,项目名称:kitsune,代码行数:30,代码来源:test_views.py

示例3: test_post_reply

# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import session [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'])
开发者ID:Binzzzz,项目名称:kitsune,代码行数:47,代码来源:test_views.py


注:本文中的test_utils.RequestFactory.session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。