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


Python Eve.validate_schema方法代码示例

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


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

示例1: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_schema [as 别名]

#.........这里部分代码省略.........

    def test_custom_validator(self):
        class MyTestValidator(Validator):
            pass
        self.app = Eve(validator=MyTestValidator,
                       settings=self.settings_file)
        self.assertEqual(self.app.validator, MyTestValidator)

    def test_custom_datalayer(self):
        class MyTestDataLayer(DataLayer):
            def init_app(self, app):
                pass
        self.app = Eve(data=MyTestDataLayer, settings=self.settings_file)
        self.assertEqual(type(self.app.data), MyTestDataLayer)

    def test_validate_domain_struct(self):
        del self.app.config['DOMAIN']
        self.assertValidateConfigFailure('missing')

        self.app.config['DOMAIN'] = []
        self.assertValidateConfigFailure('must be a dict')

        self.app.config['DOMAIN'] = {}
        self.assertValidateConfigSuccess()

    def test_validate_resource_methods(self):
        self.app.config['RESOURCE_METHODS'] = ['PUT', 'GET', 'DELETE', 'POST']
        self.assertValidateConfigFailure('PUT')

    def test_validate_item_methods(self):
        self.app.config['ITEM_METHODS'] = ['PUT', 'GET', 'POST', 'DELETE']
        self.assertValidateConfigFailure(['POST', 'PUT'])

    def test_validate_schema_methods(self):
        test = {
            'resource_methods': ['PUT', 'GET', 'DELETE', 'POST'],
        }
        self.app.config['DOMAIN']['test_resource'] = test
        self.assertValidateConfigFailure('PUT')

    def test_validate_schema_item_methods(self):
        test = {
            'resource_methods': ['GET'],
            'item_methods': ['POST'],
        }
        self.app.config['DOMAIN']['test_resource'] = test
        self.assertValidateConfigFailure('PUT')

    def test_validate_datecreated_in_schema(self):
        self.assertUnallowedField(eve.DATE_CREATED)

    def test_validate_lastupdated_in_schema(self):
        self.assertUnallowedField(eve.LAST_UPDATED)

    def assertUnallowedField(self, field, field_type='datetime'):
        self.domain.clear()
        schema = {field: {'type': field_type}}
        self.domain['resource'] = {'schema': schema}
        self.app.set_defaults()
        self.assertValidateSchemaFailure('resource', schema, field)

    def test_validate_schema(self):
        # lack of 'collection' key for 'data_collection' rule
        schema = self.domain['invoices']['schema']
        del(schema['person']['data_relation']['resource'])
        self.assertValidateSchemaFailure('invoices', schema, 'resource')
开发者ID:Adam-Koza,项目名称:python-services-rest-api,代码行数:70,代码来源:config.py

示例2: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_schema [as 别名]

#.........这里部分代码省略.........
    def test_custom_validator(self):
        class MyTestValidator(Validator):
            pass

        self.app = Eve(validator=MyTestValidator, settings=self.settings_file)
        self.assertEqual(self.app.validator, MyTestValidator)

    def test_custom_datalayer(self):
        class MyTestDataLayer(DataLayer):
            def init_app(self, app):
                pass

        self.app = Eve(data=MyTestDataLayer, settings=self.settings_file)
        self.assertEqual(type(self.app.data), MyTestDataLayer)

    def test_validate_domain_struct(self):
        del self.app.config["DOMAIN"]
        self.assertValidateConfigFailure("missing")

        self.app.config["DOMAIN"] = []
        self.assertValidateConfigFailure("must be a dict")

        self.app.config["DOMAIN"] = {}
        self.assertValidateConfigSuccess()

    def test_validate_resource_methods(self):
        self.app.config["RESOURCE_METHODS"] = ["PUT", "GET", "DELETE", "POST"]
        self.assertValidateConfigFailure("PUT")

    def test_validate_item_methods(self):
        self.app.config["ITEM_METHODS"] = ["PUT", "GET", "POST", "DELETE"]
        self.assertValidateConfigFailure(["POST", "PUT"])

    def test_validate_schema_methods(self):
        test = {"resource_methods": ["PUT", "GET", "DELETE", "POST"]}
        self.app.config["DOMAIN"]["test_resource"] = test
        self.assertValidateConfigFailure("PUT")

    def test_validate_schema_item_methods(self):
        test = {"resource_methods": ["GET"], "item_methods": ["POST"]}
        self.app.config["DOMAIN"]["test_resource"] = test
        self.assertValidateConfigFailure("PUT")

    def test_validate_datecreated_in_schema(self):
        self.assertUnallowedField(eve.DATE_CREATED)

    def test_validate_lastupdated_in_schema(self):
        self.assertUnallowedField(eve.LAST_UPDATED)

    def assertUnallowedField(self, field, field_type="datetime"):
        self.domain.clear()
        schema = {field: {"type": field_type}}
        self.domain["resource"] = {"schema": schema}
        self.app.set_defaults()
        self.assertValidateSchemaFailure("resource", schema, field)

    def test_validate_schema(self):
        # lack of 'collection' key for 'data_collection' rule
        schema = self.domain["invoices"]["schema"]
        del schema["person"]["data_relation"]["resource"]
        self.assertValidateSchemaFailure("invoices", schema, "resource")

    def test_validate_invalid_field_names(self):
        schema = self.domain["invoices"]["schema"]
        schema["te$t"] = {"type": "string"}
        self.assertValidateSchemaFailure("invoices", schema, "te$t")
开发者ID:sunbit,项目名称:eve,代码行数:70,代码来源:config.py

示例3: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_schema [as 别名]
class TestConfig(TestBase):
    def test_default_import_name(self):
        self.assertEqual(self.app.import_name, eve.__package__)

    def test_custom_import_name(self):
        self.app = Eve('custom_import_name',
                       settings='eve/tests/test_settings.py')
        self.assertEqual(self.app.import_name, 'custom_import_name')

    def test_custom_kwargs(self):
        self.app = Eve('custom_import_name', static_folder='/',
                       settings='eve/tests/test_settings.py')
        self.assertEqual(self.app.static_folder, '/')

    def test_regexconverter(self):
        regex_converter = self.app.url_map.converters.get('regex')
        self.assertEqual(regex_converter, RegexConverter)

    def test_default_validator(self):
        self.assertEqual(self.app.validator, Validator)

    def test_default_datalayer(self):
        self.assertEqual(type(self.app.data), Mongo)

    def test_default_settings(self):
        self.assertEqual(self.app.settings, self.settings_file)

        # TODO add tests for other global default values
        self.assertEqual(self.app.config['RATE_LIMIT_GET'], None)
        self.assertEqual(self.app.config['RATE_LIMIT_POST'], None)
        self.assertEqual(self.app.config['RATE_LIMIT_PATCH'], None)
        self.assertEqual(self.app.config['RATE_LIMIT_DELETE'], None)

        self.assertEqual(self.app.config['MONGO_HOST'], 'localhost')
        self.assertEqual(self.app.config['MONGO_PORT'], 27017)
        self.assertEqual(self.app.config['MONGO_QUERY_BLACKLIST'], ['$where',
                                                                    '$regex'])
        self.assertEqual(self.app.config['MONGO_WRITE_CONCERN'], {'w': 1})

    def test_unexisting_pyfile_config(self):
        self.assertRaises(IOError, Eve, settings='an_unexisting_pyfile.py')

    def test_unexisting_env_config(self):
        env = os.environ
        try:
            os.environ = {'EVE_SETTINGS': 'an_unexisting_pyfile.py'}
            self.assertRaises(IOError, Eve)
        finally:
            os.environ = env

    def test_custom_validator(self):
        class MyTestValidator(Validator):
            pass
        self.app = Eve(validator=MyTestValidator,
                       settings=self.settings_file)
        self.assertEqual(self.app.validator, MyTestValidator)

    def test_custom_datalayer(self):
        class MyTestDataLayer(DataLayer):
            def init_app(self, app):
                pass
            pass
        self.app = Eve(data=MyTestDataLayer, settings=self.settings_file)
        self.assertEqual(type(self.app.data), MyTestDataLayer)

    def test_validate_domain_struct(self):
        del self.app.config['DOMAIN']
        self.assertValidateConfigFailure('missing')

        self.app.config['DOMAIN'] = []
        self.assertValidateConfigFailure('must be a dict')

        self.app.config['DOMAIN'] = {}
        self.assertValidateConfigFailure('must contain at least one')

    def test_validate_resource_methods(self):
        self.app.config['RESOURCE_METHODS'] = ['PUT', 'GET', 'DELETE', 'POST']
        self.assertValidateConfigFailure('PUT')

    def test_validate_item_methods(self):
        self.app.config['ITEM_METHODS'] = ['PUT', 'GET', 'POST', 'DELETE']
        self.assertValidateConfigFailure(['POST', 'PUT'])

    def test_validate_schema_methods(self):
        test = {
            'resource_methods': ['PUT', 'GET', 'DELETE', 'POST'],
        }
        self.app.config['DOMAIN']['test_resource'] = test
        self.assertValidateConfigFailure('PUT')

    def test_validate_schema_item_methods(self):
        test = {
            'resource_methods': ['GET'],
            'item_methods': ['PUT'],
        }
        self.app.config['DOMAIN']['test_resource'] = test
        self.assertValidateConfigFailure('PUT')

    def test_validate_datecreated_in_schema(self):
        self.assertUnallowedField(eve.DATE_CREATED)
#.........这里部分代码省略.........
开发者ID:AdamJB,项目名称:eve,代码行数:103,代码来源:config.py

示例4: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_schema [as 别名]

#.........这里部分代码省略.........

    def test_custom_validator(self):
        class MyTestValidator(Validator):
            pass
        self.app = Eve(validator=MyTestValidator,
                       settings=self.settings_file)
        self.assertEqual(self.app.validator, MyTestValidator)

    def test_custom_datalayer(self):
        class MyTestDataLayer(DataLayer):
            def init_app(self, app):
                pass
        self.app = Eve(data=MyTestDataLayer, settings=self.settings_file)
        self.assertEqual(type(self.app.data), MyTestDataLayer)

    def test_validate_domain_struct(self):
        del self.app.config['DOMAIN']
        self.assertValidateConfigFailure('missing')

        self.app.config['DOMAIN'] = []
        self.assertValidateConfigFailure('must be a dict')

        self.app.config['DOMAIN'] = {}
        self.assertValidateConfigSuccess()

    def test_validate_resource_methods(self):
        self.app.config['RESOURCE_METHODS'] = ['PUT', 'GET', 'DELETE', 'POST']
        self.assertValidateConfigFailure('PUT')

    def test_validate_item_methods(self):
        self.app.config['ITEM_METHODS'] = ['PUT', 'GET', 'POST', 'DELETE']
        self.assertValidateConfigFailure(['POST', 'PUT'])

    def test_validate_schema_methods(self):
        test = {
            'resource_methods': ['PUT', 'GET', 'DELETE', 'POST'],
        }
        self.app.config['DOMAIN']['test_resource'] = test
        self.assertValidateConfigFailure('PUT')

    def test_validate_schema_item_methods(self):
        test = {
            'resource_methods': ['GET'],
            'item_methods': ['POST'],
        }
        self.app.config['DOMAIN']['test_resource'] = test
        self.assertValidateConfigFailure('PUT')

    def test_validate_datecreated_in_schema(self):
        self.assertUnallowedField(eve.DATE_CREATED)

    def test_validate_lastupdated_in_schema(self):
        self.assertUnallowedField(eve.LAST_UPDATED)

    def test_validate_idfield_in_schema(self):
        self.assertUnallowedField(eve.ID_FIELD, 'objectid')

    def assertUnallowedField(self, field, field_type='datetime'):
        self.domain.clear()
        schema = {field: {'type': field_type}}
        self.domain['resource'] = {'schema': schema}
        self.app.set_defaults()
        self.assertValidateSchemaFailure('resource', schema, field)

    def test_validate_schema(self):
        # lack of 'collection' key for 'data_collection' rule
开发者ID:Zealsathish,项目名称:eve,代码行数:70,代码来源:config.py


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