本文整理汇总了Python中tests.unit.mock_response函数的典型用法代码示例。如果您正苦于以下问题:Python mock_response函数的具体用法?Python mock_response怎么用?Python mock_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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')
示例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')
示例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')
示例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)
示例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')
示例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', {})
示例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', {})