• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unit.mock_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.unit.mock_response函数的典型用法代码示例。如果您正苦于以下问题:Python mock_response函数的具体用法?Python mock_response怎么用?Python mock_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: it_handles_no_error_type

    def it_handles_no_error_type(self):
        payload = {
            'errors': [
                {
                    'code': 'unique_user_constraint',
                    'message': 'User already exists.'
                }
            ],
            'request_id': '00000000-0000-0000-0000-000000000000',
            'type': 'error.list'
        }
        content = json.dumps(payload).encode('utf-8')
        resp = mock_response(content)
        with patch('requests.request') as mock_method:
            mock_method.return_value = resp
            with assert_raises(intercom.MultipleMatchingUsersError):
                Intercom.get('/users')

        payload = {
            'errors': [
                {
                    'code': 'parameter_not_found',
                    'message': 'missing data parameter'
                }
            ],
            'request_id': None,
            'type': 'error.list'
        }
        content = json.dumps(payload).encode('utf-8')
        resp = mock_response(content)
        with patch('requests.request') as mock_method:
            mock_method.return_value = resp
            with assert_raises(intercom.BadRequestError):
                Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:34,代码来源:test_request.py


示例2: it_handles_empty_responses

    def it_handles_empty_responses(self):
        resp = mock_response('', status_code=202)
        with patch('requests.request') as mock_method:
            mock_method.return_value = resp
            Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)

        resp = mock_response(' ', status_code=202)
        with patch('requests.request') as mock_method:
            mock_method.return_value = resp
            Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:10,代码来源:test_request.py


示例3: it_raises_service_unavailable_error

 def it_raises_service_unavailable_error(self):
     resp = mock_response(None, status_code=503)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.ServiceUnavailableError):
             request = Request('GET', 'notes')
             request.send_request_to_path('', ('x', 'y'), resp)
开发者ID:iwoca,项目名称:python-intercom,代码行数:7,代码来源:test_request.py


示例4: it_raises_bad_gateway_error

 def it_raises_bad_gateway_error(self):
     resp = mock_response(None, status_code=502)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.BadGatewayError):
             request = Request('GET', 'notes')
             request.send_request_to_path('', ('x', 'y'), resp)
开发者ID:iwoca,项目名称:python-intercom,代码行数:7,代码来源:test_request.py


示例5: it_raises_authentication_error_forbidden

 def it_raises_authentication_error_forbidden(self):
     resp = mock_response(None, status_code=403)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.AuthenticationError):
             request = Request('GET', 'notes')
             request.send_request_to_path('', ('x', 'y'), resp)
开发者ID:iwoca,项目名称:python-intercom,代码行数:7,代码来源:test_request.py


示例6: it_raises_resource_not_found

 def it_raises_resource_not_found(self):
     resp = mock_response(None, status_code=404)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.ResourceNotFound):
             request = Request('GET', 'notes')
             request.send_request_to_path('', ('x', 'y'), resp)
开发者ID:iwoca,项目名称:python-intercom,代码行数:7,代码来源:test_request.py


示例7: it_handles_no_encoding

    def it_handles_no_encoding(self):
        resp = mock_response(
            ' ', status_code=200, encoding=None, headers=None)
        resp.apparent_encoding = 'utf-8'

        with patch('requests.request') as mock_method:
            mock_method.return_value = resp
            Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:8,代码来源:test_request.py


示例8: it_needs_encoding_or_apparent_encoding

    def it_needs_encoding_or_apparent_encoding(self):
        payload = '{}'

        if not hasattr(payload, 'decode'):
            # python 3
            payload = payload.encode('utf-8')

        resp = mock_response(
            payload, status_code=200, encoding=None, headers=None)

        with patch('requests.request') as mock_method:
            mock_method.return_value = resp
            with assert_raises(TypeError):
                Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:14,代码来源:test_request.py


示例9: it_raises_a_multiple_matching_users_error

 def it_raises_a_multiple_matching_users_error(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'type': 'conflict',
                 'message': 'Two many cooks.'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.MultipleMatchingUsersError):
             Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:16,代码来源:test_request.py


示例10: it_raises_a_service_unavailable_error

 def it_raises_a_service_unavailable_error(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'type': 'service_unavailable',
                 'message': 'Zzzzz.'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.ServiceUnavailableError):
             Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:16,代码来源:test_request.py


示例11: it_raises_resource_not_found_by_type

 def it_raises_resource_not_found_by_type(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'type': 'not_found',
                 'message': 'Waaaaally?'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.ResourceNotFound):
             Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:16,代码来源:test_request.py


示例12: it_handles_accented_characters

 def it_handles_accented_characters(self):
     # create a user dict with a name that contains accented characters
     payload = get_user(name='Jóe Schmö')
     # create bytes content
     content = json.dumps(payload).encode('utf-8')
     # create mock response
     resp = mock_response(content)
     with patch('requests.sessions.Session.request') as mock_method:
         mock_method.return_value = resp
         user = self.client.users.find(email='[email protected]')
         try:
             # Python 2
             eq_(unicode('Jóe Schmö', 'utf-8'), user.name)
         except NameError:
             # Python 3
             eq_('Jóe Schmö', user.name)
开发者ID:jkeyes,项目名称:python-intercom,代码行数:16,代码来源:test_user.py


示例13: it_raises_rate_limit_exceeded

 def it_raises_rate_limit_exceeded(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'type': 'rate_limit_exceeded',
                 'message': 'Fair use please.'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.RateLimitExceeded):
             Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:16,代码来源:test_request.py


示例14: it_raises_token_unauthorized

 def it_raises_token_unauthorized(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'type': 'token_unauthorized',
                 'message': 'The PAT is not authorized for this action.'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.sessions.Session.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.TokenUnauthorizedError):
             self.client.get('/users', {})
开发者ID:jkeyes,项目名称:python-intercom,代码行数:16,代码来源:test_request.py


示例15: it_raises_a_multiple_matching_users_error_when_receiving_a_conflict

 def it_raises_a_multiple_matching_users_error_when_receiving_a_conflict(self):  # noqa
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'code': 'conflict',
                 'message': 'Multiple existing users match this email address - must be more specific using user_id'  # noqa
             }
         ]
     }
     # create bytes content
     content = json.dumps(payload).encode('utf-8')
     # create mock response
     resp = mock_response(content)
     with patch('requests.sessions.Session.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(MultipleMatchingUsersError):
             self.client.get('/users', {})
开发者ID:jkeyes,项目名称:python-intercom,代码行数:18,代码来源:test_user.py


示例16: it_raises_an_unexpected_untyped_error

 def it_raises_an_unexpected_untyped_error(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'message': 'UNIVAC'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         try:
             Intercom.get('/users')
             self.fail('UnexpectedError not raised.')
         except (UnexpectedError) as err:
             ok_("An unexpected error occured." in err.message)
             eq_(err.context['application_error_code'], None)
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:19,代码来源:test_request.py


示例17: it_raises_an_authentication_error

    def it_raises_an_authentication_error(self):
        payload = {
            'type': 'error.list',
            'errors': [
                {
                    'type': 'unauthorized',
                    'message': 'Your name\'s not down.'
                }
            ]
        }
        for code in ['unauthorized', 'forbidden']:
            payload['errors'][0]['type'] = code

            content = json.dumps(payload).encode('utf-8')
            resp = mock_response(content)
            with patch('requests.request') as mock_method:
                mock_method.return_value = resp
                with assert_raises(intercom.AuthenticationError):
                    Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:19,代码来源:test_request.py


示例18: it_raises_a_bad_request_error

    def it_raises_a_bad_request_error(self):
        payload = {
            'type': 'error.list',
            'errors': [
                {
                    'type': None,
                    'message': 'email is required'
                }
            ]
        }

        for code in ['missing_parameter', 'parameter_invalid', 'bad_request']:
            payload['errors'][0]['type'] = code

            content = json.dumps(payload).encode('utf-8')
            resp = mock_response(content)
            with patch('requests.request') as mock_method:
                mock_method.return_value = resp
                with assert_raises(intercom.BadRequestError):
                    Intercom.get('/users')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:20,代码来源:test_request.py


示例19: it_raises_an_unexpected_typed_error

 def it_raises_an_unexpected_typed_error(self):
     payload = {
         'type': 'error.list',
         'errors': [
             {
                 'type': 'hopper',
                 'message': 'The first compiler.'
             }
         ]
     }
     content = json.dumps(payload).encode('utf-8')
     resp = mock_response(content)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         try:
             Intercom.get('/users')
             self.fail('UnexpectedError not raised.')
         except (UnexpectedError) as err:
             ok_("The error of type 'hopper' is not recognized" in err.message)  # noqa
             eq_(err.context['http_code'], 200)
             eq_(err.context['application_error_code'], 'hopper')
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:21,代码来源:test_request.py


示例20: it_raises_authentication_error_unauthorized

 def it_raises_authentication_error_unauthorized(self):
     resp = mock_response('{}', status_code=401)
     with patch('requests.request') as mock_method:
         mock_method.return_value = resp
         with assert_raises(intercom.AuthenticationError):
             Request.send_request_to_path('GET', 'notes', ('x', 'y'), resp)
开发者ID:50onRed,项目名称:python-intercom-1,代码行数:6,代码来源:test_request.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base.get_wf_fixture_meta_data函数代码示例发布时间:2022-05-27
下一篇:
Python tools.wrap_nb函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap