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


Python Application.validate_output方法代码示例

本文整理汇总了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(), '')
开发者ID:craigahobbs,项目名称:chisel,代码行数:31,代码来源:test_action.py

示例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')
开发者ID:craigahobbs,项目名称:chisel,代码行数:23,代码来源:test_action.py

示例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}')
开发者ID:craigahobbs,项目名称:chisel,代码行数:23,代码来源:test_action.py


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