本文整理汇总了Python中savory_pie.tests.django.mock_request.savory_dispatch函数的典型用法代码示例。如果您正苦于以下问题:Python savory_dispatch函数的具体用法?Python savory_dispatch怎么用?Python savory_dispatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了savory_dispatch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_delete_success
def test_delete_success(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('DELETE')
savory_dispatch(root_resource, method='DELETE')
self.assertTrue(root_resource.delete.called)
self.assertIsNotNone(root_resource.delete.call_args_list[0].request)
开发者ID:wware,项目名称:savory-pie,代码行数:7,代码来源:test_views.py
示例2: test_child_resolution
def test_child_resolution(self):
child_resource = mock_resource(name='child')
child_resource.allowed_methods.add('GET')
child_resource.get = Mock(return_value={})
root_resource = mock_resource(name='root', child_resource=child_resource)
savory_dispatch(root_resource, method='GET', resource_path='child')
self.assertEqual(call_args_sans_context(root_resource.get_child_resource), ['child'])
self.assertTrue(child_resource.get.called)
self.assertIsNotNone(child_resource.get.call_args_list[0].request)
开发者ID:wware,项目名称:savory-pie,代码行数:12,代码来源:test_views.py
示例3: test_get_success
def test_get_success(self):
response = savory_dispatch(api_resource, method='GET', resource_path='users/1')
self.assertEqual(response.status_code, 200)
self.assertEqual(
json.loads(response.content),
{u'resourceUri': u'http://localhost/api/users/1',
u'age': 31,
u'name': 'Alice'}
)
开发者ID:wware,项目名称:savory-pie,代码行数:9,代码来源:test_integration.py
示例4: test_get_success
def test_get_success(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('GET')
root_resource.get = Mock(return_value={'foo': 'bar'})
response = savory_dispatch(root_resource, method='GET')
self.assertEqual(response.content, '{"foo": "bar"}')
self.assertTrue(root_resource.get.called)
self.assertIsNotNone(root_resource.get.call_args_list[0].request)
开发者ID:wware,项目名称:savory-pie,代码行数:10,代码来源:test_views.py
示例5: test_exception_handling
def test_exception_handling(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('GET')
root_resource.get.side_effect = Exception('Fail')
response = savory_dispatch(root_resource, method='GET')
response_json = json.loads(response.content)
self.assertIn('error', response_json)
self.assertEqual(response.status_code, 500)
开发者ID:RueLaLaTech,项目名称:savory-pie,代码行数:10,代码来源:test_views.py
示例6: test_unauthorized
def test_unauthorized(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('PUT')
root_resource.put.side_effect = AuthorizationError('foo')
response = savory_dispatch(root_resource, method='PUT', body='{"foo": "bar"}')
response_json = json.loads(response.content)
self.assertIn('validation_errors', response_json)
self.assertEqual(response_json['validation_errors'], ['Modification of field foo not authorized'])
self.assertEqual(response.status_code, 403)
开发者ID:wware,项目名称:savory-pie,代码行数:11,代码来源:test_views.py
示例7: test_get_with_apiexception
def test_get_with_apiexception(self, logger):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('GET')
root_resource.get = Mock(side_effect=ApiException('Some kind of server error'))
response = savory_dispatch(root_resource, method='GET')
self.assertEqual(response.status_code, 500)
content = json.loads(response.content)
self.assertTrue('message' in content)
self.assertEqual(content['message'], 'Some kind of server error')
self.assertTrue(logger.error.called)
开发者ID:wware,项目名称:savory-pie,代码行数:12,代码来源:test_views.py
示例8: test_put_with_exception
def test_put_with_exception(self, logger):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('PUT')
root_resource.put = Mock(side_effect=Exception('Some kind of server error'))
response = savory_dispatch(root_resource, method='PUT', body='{"foo": "bar"}')
self.assertEqual(response.status_code, 500)
content = json.loads(response.content)
self.assertTrue('message' in content)
self.assertEqual(content['message'], 'Some kind of server error')
self.assertTrue(logger.exception.called)
开发者ID:wware,项目名称:savory-pie,代码行数:12,代码来源:test_views.py
示例9: test_validation_handling
def test_validation_handling(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('PUT')
root_resource.put.side_effect = validators.ValidationError(
Mock(),
{
'class.field': 'broken',
}
)
response = savory_dispatch(root_resource, method='PUT', body='{}')
response_json = json.loads(response.content)
self.assertIn('validation_errors', response_json)
self.assertEqual(response_json['validation_errors']['class.field'], 'broken')
self.assertEqual(response.status_code, 400)
开发者ID:wware,项目名称:savory-pie,代码行数:16,代码来源:test_views.py
示例10: test_post_with_exception
def test_post_with_exception(self, logger):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('POST')
def side_effect(*args):
raise Exception('Some kind of server error')
root_resource.post = Mock(side_effect=side_effect)
response = savory_dispatch(root_resource, method='POST', body='{}')
self.assertEqual(response.status_code, 500)
content = json.loads(response.content)
self.assertTrue('error' in content)
self.assertTrue(content['error'].startswith('Traceback (most recent call last):'))
self.assertTrue('Some kind of server error' in content['error'])
self.assertTrue(logger.exception.called)
开发者ID:RueLaLaTech,项目名称:savory-pie,代码行数:16,代码来源:test_views.py
示例11: test_post_with_collision_one
def test_post_with_collision_one(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('POST')
def side_effect(*args):
# This could occur if a slightly earlier POST or PUT still had
# the database locked during a DB transaction.
from django.db.transaction import TransactionManagementError
raise TransactionManagementError()
root_resource.post = Mock(side_effect=side_effect)
response = savory_dispatch(root_resource, method='POST', body='{}')
self.assertEqual(response.status_code, 409)
self.assertEqual(response.content, '{"resource": "http://localhost/api/"}')
开发者ID:wware,项目名称:savory-pie,代码行数:16,代码来源:test_views.py
示例12: test_set_expires
def test_set_expires(self):
expires = datetime(2005, 7, 14, 12, 30)
def get(ctx, params):
ctx.set_expires_header(datetime.utcnow())
ctx.set_expires_header(expires)
ctx.set_expires_header(datetime.utcnow())
return {'foo2': 'bar2'}
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('GET')
root_resource.get = get
response = savory_dispatch(root_resource, method='GET')
self.assertEqual(response['Expires'], expires.isoformat('T'))
self.assertEqual(response.content, '{"foo2": "bar2"}')
开发者ID:wware,项目名称:savory-pie,代码行数:17,代码来源:test_views.py
示例13: test_set_header
def test_set_header(self):
"""
Tests the set_header method in the APIContext class
"""
def get(ctx, params):
ctx.set_header('foo1', 'bar1')
return {'foo2': 'bar2'}
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('GET')
root_resource.get = get
response = savory_dispatch(root_resource, method='GET')
self.assertEqual(response['foo1'], 'bar1')
self.assertEqual(response.content, '{"foo2": "bar2"}')
开发者ID:wware,项目名称:savory-pie,代码行数:17,代码来源:test_views.py
示例14: test_post_success
def test_post_success(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('POST')
new_resource = mock_resource(name='new', resource_path='foo')
root_resource.post = Mock(return_value=new_resource)
response = savory_dispatch(root_resource, method='POST', body='{"foo": "bar"}')
self.assertTrue(
call_args_sans_context(root_resource.post),
[
{
'foo': 'bar'
}
]
)
self.assertEqual(response['Location'], 'http://localhost/api/foo')
self.assertIsNotNone(root_resource.post.call_args_list[0].request)
开发者ID:RueLaLaTech,项目名称:savory-pie,代码行数:19,代码来源:test_views.py
示例15: test_post_success_returns_resource_when_indicated
def test_post_success_returns_resource_when_indicated(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('POST')
root_resource.return_on_post = True
root_resource.post.return_value = {'key': 'value'}
response = savory_dispatch(root_resource, method='POST', body='{"foo": "bar"}')
self.assertTrue(
call_args_sans_context(root_resource.post),
[
{
'foo': 'bar'
}
]
)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.content, '{"key": "value"}')
self.assertIsNotNone(root_resource.post.call_args_list[0].request)
开发者ID:RueLaLaTech,项目名称:savory-pie,代码行数:19,代码来源:test_views.py
示例16: test_put_no_content_success
def test_put_no_content_success(self):
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('PUT')
root_resource.get.return_value = {}
root_resource.put.return_value = None
response = savory_dispatch(root_resource, method='PUT', body='{"foo": "bar"}')
self.assertTrue(
call_args_sans_context(root_resource.put),
[
{
'foo': 'bar'
}
]
)
self.assertEqual(response.status_code, 204)
self.assertEqual(response.content, '')
self.assertIsNotNone(root_resource.put.call_args_list[0].request)
开发者ID:wware,项目名称:savory-pie,代码行数:20,代码来源:test_views.py
示例17: test_get_success_streaming
def test_get_success_streaming(self):
def get(ctx, params):
ctx.streaming_response = True
ctx.formatter = Mock()
ctx.formatter.write_to = lambda *args: None
return iter([
'{"foo": ',
'"bar"',
'}',
])
root_resource = mock_resource(name='root')
root_resource.allowed_methods.add('GET')
root_resource.get = Mock(side_effect=get)
response = savory_dispatch(root_resource, method='GET')
self.assertEqual(response.status_code, 200)
self.assertEqual(''.join(response.streaming_content), '{"foo": "bar"}')
self.assertTrue(root_resource.get.called)
self.assertIsNotNone(root_resource.get.call_args_list[0].request)
开发者ID:wware,项目名称:savory-pie,代码行数:21,代码来源:test_views.py
示例18: test_child_resolution_fail
def test_child_resolution_fail(self):
root_resource = mock_resource(name='root')
response = savory_dispatch(root_resource, method='GET', resource_path='child/grandchild')
self.assertEqual(response.status_code, 404)
开发者ID:wware,项目名称:savory-pie,代码行数:5,代码来源:test_views.py
示例19: test_delete_not_supported
def test_delete_not_supported(self):
root_resource = mock_resource(name='root')
response = savory_dispatch(root_resource, method='DELETE')
self.assertEqual(response.status_code, 405)
开发者ID:wware,项目名称:savory-pie,代码行数:5,代码来源:test_views.py
示例20: test_post_not_supported
def test_post_not_supported(self):
root_resource = mock_resource(name='root')
response = savory_dispatch(root_resource, method='POST', body='{}')
self.assertEqual(response.status_code, 405)
开发者ID:wware,项目名称:savory-pie,代码行数:6,代码来源:test_views.py
注:本文中的savory_pie.tests.django.mock_request.savory_dispatch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论