當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。