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


Python colander.MappingSchema方法代码示例

本文整理汇总了Python中colander.MappingSchema方法的典型用法代码示例。如果您正苦于以下问题:Python colander.MappingSchema方法的具体用法?Python colander.MappingSchema怎么用?Python colander.MappingSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colander的用法示例。


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

示例1: test_covert_body_with_request_validator_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_covert_body_with_request_validator_schema(self):

        class RequestSchema(colander.MappingSchema):
            body = BodySchema()

        node = RequestSchema()
        params = self.handler.from_schema(node)
        self.assertEquals(len(params), 1)

        expected = {
            'name': 'BodySchema',
            'in': 'body',
            'required': True,
            'schema': convert_schema(BodySchema(title='BodySchema'))
        }

        self.assertDictEqual(params[0], expected) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:19,代码来源:test_parameter_handler.py

示例2: test_covert_query_with_request_validator_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_covert_query_with_request_validator_schema(self):

        class RequestSchema(colander.MappingSchema):
            querystring = QuerySchema()

        node = RequestSchema()
        params = self.handler.from_schema(node)
        self.assertEquals(len(params), 1)

        expected = {
            'name': 'foo',
            'in': 'query',
            'type': 'string',
            'required': False,
            'minLength': 3
        }
        self.assertDictEqual(params[0], expected) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:19,代码来源:test_parameter_handler.py

示例3: test_covert_headers_with_request_validator_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_covert_headers_with_request_validator_schema(self):

        class RequestSchema(colander.MappingSchema):
            headers = HeaderSchema()

        node = RequestSchema()
        params = self.handler.from_schema(node)
        self.assertEquals(len(params), 1)

        expected = {
            'name': 'bar',
            'in': 'header',
            'type': 'string',
            'required': False,
        }
        self.assertDictEqual(params[0], expected) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:18,代码来源:test_parameter_handler.py

示例4: test_covert_path_with_request_validator_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_covert_path_with_request_validator_schema(self):

        class RequestSchema(colander.MappingSchema):
            path = PathSchema()

        node = RequestSchema()
        params = self.handler.from_schema(node)
        self.assertEquals(len(params), 1)

        expected = {
            'name': 'meh',
            'in': 'path',
            'type': 'string',
            'required': True,
            'default': 'default'
        }
        self.assertDictEqual(params[0], expected) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:19,代码来源:test_parameter_handler.py

示例5: test_convert_descriptions

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_convert_descriptions(self):
        class RequestSchema(colander.MappingSchema):
            body = BodySchema(description='my body')

        node = RequestSchema()
        params = self.handler.from_schema(node)

        expected = {
            'name': 'BodySchema',
            'in': 'body',
            'required': True,
            'description': 'my body',
            'schema': convert_schema(BodySchema(title='BodySchema',
                                                description='my body'))
        }

        self.assertDictEqual(params[0], expected) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:19,代码来源:test_parameter_handler.py

示例6: test_ref_from_request_validator_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_ref_from_request_validator_schema(self):

        class RequestSchema(colander.MappingSchema):
            querystring = QuerySchema()

        node = RequestSchema()
        params = self.handler.from_schema(node)

        expected = {
            'name': 'foo',
            'in': 'query',
            'type': 'string',
            'required': False,
            'minLength': 3
        }

        self.assertEquals(params, [{'$ref': '#/parameters/foo'}])
        self.assertDictEqual(self.handler.parameter_registry, dict(foo=expected)) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:20,代码来源:test_parameter_handler.py

示例7: test_required

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_required(self):
        class Mapping(colander.MappingSchema):
            foo = colander.SchemaNode(colander.String())

        node = Mapping()
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'object',
            'properties': {
                'foo': {
                    'title': 'Foo',
                    'type': 'string'
                }
            },
            'required': ['foo']
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:18,代码来源:test_schema.py

示例8: test_not_required

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_not_required(self):
        class Mapping(colander.MappingSchema):
            foo = colander.SchemaNode(colander.String(),
                                      missing=colander.drop)

        node = Mapping()
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'object',
            'properties': {
                'foo': {
                    'title': 'Foo',
                    'type': 'string'
                }
            },
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:18,代码来源:test_schema.py

示例9: test_open_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_open_schema(self):
        class Mapping(colander.MappingSchema):
            foo = colander.SchemaNode(colander.String(),
                                      missing=colander.drop)

            @staticmethod
            def schema_type():
                return colander.Mapping(unknown='preserve')

        node = Mapping()
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'object',
            'properties': {
                'foo': {
                    'title': 'Foo',
                    'type': 'string'
                }
            },
            'additionalProperties': {}
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:23,代码来源:test_schema.py

示例10: _extract_transform_colander_schema

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def _extract_transform_colander_schema(self, args):
        """
        Extract schema from view args and transform it using
        the pipeline of schema transformers

        :param args:
            Arguments from the view decorator.

        :rtype: colander.MappingSchema()
        :returns: View schema cloned and transformed
        """

        schema = args.get('schema', colander.MappingSchema())
        if not isinstance(schema, colander.Schema):
            schema = schema()
        schema = schema.clone()
        for transformer in self.schema_transformers:
            schema = transformer(schema, args)
        return schema 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:21,代码来源:swagger.py

示例11: test_sanity

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_sanity(self):
        node = colander.MappingSchema()
        params = self.handler.from_schema(node)
        self.assertEquals(params, []) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:6,代码来源:test_parameter_handler.py

示例12: test_cornice_location_synonyms

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_cornice_location_synonyms(self):

        class RequestSchema(colander.MappingSchema):
            header = HeaderSchema()
            GET = QuerySchema()

        node = RequestSchema()
        params = self.handler.from_schema(node)

        names = [param['name'] for param in params]
        expected = ['foo', 'bar']
        self.assertEqual(sorted(names), sorted(expected)) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:14,代码来源:test_parameter_handler.py

示例13: test_response_schema_with_example

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_response_schema_with_example(self):
        class ResponseSchema(colander.MappingSchema):
            body = BodySchema()

        response_schemas = {'200': ResponseSchema(description='Return gelatto')}
        responses = self.handler.from_schema_mapping(response_schemas)
        self.assertTrue('ex' in responses['200']['schema']['properties'])
        self.assertTrue('example' in responses['200']['schema']['properties']['ex'])
        self.assertEquals(responses['200']['schema']['properties']['ex']['example'],
                          'example string') 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:12,代码来源:test_response_handler.py

示例14: test_cornice_location_synonyms

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_cornice_location_synonyms(self):

        class ResponseSchema(colander.MappingSchema):
            header = HeaderSchema()

        response_schemas = {'200': ResponseSchema(description='Return gelatto')}
        responses = self.handler.from_schema_mapping(response_schemas)

        self.assertDictEqual(responses['200']['headers'],
                             {'bar': {'type': 'string'}}) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:12,代码来源:test_response_handler.py

示例15: test_sanity

# 需要导入模块: import colander [as 别名]
# 或者: from colander import MappingSchema [as 别名]
def test_sanity(self):
        node = colander.MappingSchema()
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'object',
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:8,代码来源:test_schema.py


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