本文整理汇总了Python中chisel.Application.validate_output方法的典型用法代码示例。如果您正苦于以下问题:Python Application.validate_output方法的具体用法?Python Application.validate_output怎么用?Python Application.validate_output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chisel.Application
的用法示例。
在下文中一共展示了Application.validate_output方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error_bad_error
# 需要导入模块: from chisel import Application [as 别名]
# 或者: from chisel.Application import validate_output [as 别名]
def test_error_bad_error(self):
@action(spec='''\
action my_action
errors
MyError
''')
def my_action(unused_app, unused_req):
raise ActionError('MyBadError')
app = Application()
app.add_request(my_action)
environ = {'wsgi.errors': StringIO()}
status, headers, response = app.request('POST', '/my_action', wsgi_input=b'{}')
self.assertEqual(status, '500 Internal Server Error')
self.assertEqual(sorted(headers), [('Content-Type', 'application/json')])
self.assertEqual(response.decode('utf-8'),
'{"error":"InvalidOutput","member":"error","message":"Invalid value \'MyBadError\' (type \'str\') '
'for member \'error\', expected type \'my_action_error\'"}')
self.assertEqual(environ['wsgi.errors'].getvalue(), '')
app.validate_output = False
environ = {'wsgi.errors': StringIO()}
status, headers, response = app.request('POST', '/my_action', wsgi_input=b'{}')
self.assertEqual(status, '400 Bad Request')
self.assertEqual(sorted(headers), [('Content-Type', 'application/json')])
self.assertEqual(response.decode('utf-8'), '{"error":"MyBadError"}')
self.assertEqual(environ['wsgi.errors'].getvalue(), '')
示例2: test_error_json
# 需要导入模块: from chisel import Application [as 别名]
# 或者: from chisel.Application import validate_output [as 别名]
def test_error_json(self):
class MyClass:
pass
@action(spec='''\
action my_action
output
float a
''')
def my_action(unused_app, unused_req):
return {'a': MyClass()}
app = Application()
app.add_request(my_action)
app.validate_output = False
status, headers, response = app.request('POST', '/my_action', wsgi_input=b'{}')
self.assertEqual(status, '500 Internal Server Error')
self.assertEqual(sorted(headers), [('Content-Type', 'text/plain')])
self.assertEqual(response, b'Internal Server Error')
示例3: test_get_no_validate_output
# 需要导入模块: from chisel import Application [as 别名]
# 或者: from chisel.Application import validate_output [as 别名]
def test_get_no_validate_output(self):
@action(method='GET', spec='''\
action my_action
input
int a
int b
output
int c
''')
def my_action(unused_app, req):
return {'c': req['a'] + req['b']}
app = Application()
app.add_request(my_action)
app.validate_output = False
status, headers, response = app.request('GET', '/my_action', query_string='a=7&b=8')
self.assertEqual(status, '200 OK')
self.assertEqual(sorted(headers), [('Content-Type', 'application/json')])
self.assertEqual(response.decode('utf-8'), '{"c":15}')