本文整理汇总了Python中eve.flaskapp.Eve.validate_config方法的典型用法代码示例。如果您正苦于以下问题:Python Eve.validate_config方法的具体用法?Python Eve.validate_config怎么用?Python Eve.validate_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eve.flaskapp.Eve
的用法示例。
在下文中一共展示了Eve.validate_config方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
class TestConfig(TestBase):
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)
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.assertValidateConfig('missing')
self.app.config['DOMAIN'] = []
self.assertValidateConfig('must be a dict')
self.app.config['DOMAIN'] = {}
self.assertValidateConfig('must contain at least one')
def test_validate_resource_methods(self):
self.app.config['RESOURCE_METHODS'] = ['PUT', 'GET', 'DELETE', 'POST']
self.assertValidateConfig('PUT')
def test_validate_item_methods(self):
self.app.config['ITEM_METHODS'] = ['PUT', 'GET', 'POST', 'DELETE']
self.assertValidateConfig('PUT, POST')
def test_validate_schema_methods(self):
test = {
'methods': ['PUT', 'GET', 'DELETE', 'POST'],
}
self.app.config['DOMAIN']['test_resource'] = test
self.assertValidateConfig('PUT')
def test_validate_schema_item_methods(self):
test = {
'methods': ['GET'],
'item_methods': ['PUT'],
}
self.app.config['DOMAIN']['test_resource'] = test
self.assertValidateConfig('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)
def assertUnallowedField(self, field):
self.domain.clear()
self.domain['resource'] = {
'schema': {
field: {'type': 'datetime'}
}
}
self.app.set_defaults()
self.assertValidateConfig('automatically')
def assertValidateConfig(self, expected):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException, e:
self.assertTrue(expected.lower() in str(e).lower())
else:
示例2: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
#.........这里部分代码省略.........
self.app.config['ETAG']])
self.assertEqual(datasource['projection'],
dict((field, 1) for (field) in compare))
self.assertEqual(datasource['source'], resource)
self.assertEqual(datasource['filter'], None)
self.assertEqual(datasource['aggregation'], None)
def test_validate_roles(self):
for resource in self.domain:
self.assertValidateRoles(resource, 'allowed_roles')
self.assertValidateRoles(resource, 'allowed_read_roles')
self.assertValidateRoles(resource, 'allowed_write_roles')
self.assertValidateRoles(resource, 'allowed_item_roles')
self.assertValidateRoles(resource, 'allowed_item_read_roles')
self.assertValidateRoles(resource, 'allowed_item_write_roles')
def assertValidateRoles(self, resource, directive):
prev = self.domain[resource][directive]
self.domain[resource][directive] = 'admin'
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = []
self.assertValidateConfigSuccess()
self.domain[resource][directive] = ['admin', 'dev']
self.assertValidateConfigSuccess()
self.domain[resource][directive] = None
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = prev
def assertValidateConfigSuccess(self):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
self.fail('ConfigException not expected: %s' % e)
def assertValidateConfigFailure(self, expected):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
if isinstance(expected, str):
expected = [expected]
for exp in expected:
self.assertTrue(exp.lower() in str(e).lower())
else:
self.fail("ConfigException expected but not raised.")
def assertValidateSchemaFailure(self, resource, schema, expected):
try:
self.app.validate_schema(resource, schema)
except SchemaException as e:
self.assertTrue(expected.lower() in str(e).lower())
else:
self.fail("SchemaException expected but not raised.")
def test_schema_defaults(self):
self.domain.clear()
self.domain['resource'] = {
'schema': {
'title': {
'type': 'string',
'default': 'Mr.',
},
'price': {
示例3: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
#.........这里部分代码省略.........
def test_datasource(self):
resource = 'invoices'
datasource = self.domain[resource]['datasource']
schema = self.domain[resource]['schema']
compare = [key for key in datasource['projection'] if key in schema]
compare.extend([self.app.config['ID_FIELD'],
self.app.config['LAST_UPDATED'],
self.app.config['DATE_CREATED']])
self.assertEqual(datasource['projection'],
dict((field, 1) for (field) in compare))
self.assertEqual(datasource['source'], resource)
self.assertEqual(datasource['filter'], None)
def test_validate_roles(self):
for resource in self.domain:
self.assertValidateRoles(resource, 'allowed_roles')
self.assertValidateRoles(resource, 'allowed_item_roles')
def assertValidateRoles(self, resource, directive):
self.domain[resource][directive] = 'admin'
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = []
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = ['admin', 'dev']
self.assertValidateConfigSuccess()
self.domain[resource][directive] = None
self.assertValidateConfigSuccess()
def assertValidateConfigSuccess(self):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
self.fail('ConfigException not expected: %s' % e)
def assertValidateConfigFailure(self, expected):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
if isinstance(expected, str):
expected = [expected]
for exp in expected:
self.assertTrue(exp.lower() in str(e).lower())
else:
self.fail("ConfigException expected but not raised.")
def assertValidateSchemaFailure(self, resource, schema, expected):
try:
self.app.validate_schema(resource, schema)
except SchemaException as e:
self.assertTrue(expected.lower() in str(e).lower())
else:
self.fail("SchemaException expected but not raised.")
def test_schema_dates(self):
self.domain.clear()
self.domain['resource'] = {
'schema': {
'born': {
'type': 'datetime',
},
'name': {
'type': 'string',
示例4: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
#.........这里部分代码省略.........
self.assertEqual(
datasource["projection"], dict((field, 1) for (field) in compare)
)
self.assertEqual(datasource["source"], resource)
self.assertEqual(datasource["filter"], None)
self.assertEqual(datasource["aggregation"], None)
def test_validate_roles(self):
for resource in self.domain:
self.assertValidateRoles(resource, "allowed_roles")
self.assertValidateRoles(resource, "allowed_read_roles")
self.assertValidateRoles(resource, "allowed_write_roles")
self.assertValidateRoles(resource, "allowed_item_roles")
self.assertValidateRoles(resource, "allowed_item_read_roles")
self.assertValidateRoles(resource, "allowed_item_write_roles")
def assertValidateRoles(self, resource, directive):
prev = self.domain[resource][directive]
self.domain[resource][directive] = "admin"
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = []
self.assertValidateConfigSuccess()
self.domain[resource][directive] = ["admin", "dev"]
self.assertValidateConfigSuccess()
self.domain[resource][directive] = None
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = prev
def assertValidateConfigSuccess(self):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
self.fail("ConfigException not expected: %s" % e)
def assertValidateConfigFailure(self, expected):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
if isinstance(expected, str):
expected = [expected]
for exp in expected:
self.assertTrue(exp.lower() in str(e).lower())
else:
self.fail("ConfigException expected but not raised.")
def assertValidateSchemaFailure(self, resource, schema, expected):
try:
self.app.validate_schema(resource, schema)
except SchemaException as e:
self.assertTrue(expected.lower() in str(e).lower())
else:
self.fail("SchemaException expected but not raised.")
def test_url_helpers(self):
self.assertNotEqual(self.app.config.get("URLS"), None)
self.assertEqual(type(self.app.config["URLS"]), dict)
self.assertNotEqual(self.app.config.get("SOURCES"), None)
self.assertEqual(type(self.app.config["SOURCES"]), dict)
del self.domain["internal_transactions"]
for resource, settings in self.domain.items():
示例5: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
#.........这里部分代码省略.........
self.app.config['LAST_UPDATED'],
self.app.config['DATE_CREATED'],
self.app.config['ETAG']])
self.assertEqual(datasource['projection'],
dict((field, 1) for (field) in compare))
self.assertEqual(datasource['source'], resource)
self.assertEqual(datasource['filter'], None)
def test_validate_roles(self):
for resource in self.domain:
self.assertValidateRoles(resource, 'allowed_roles')
self.assertValidateRoles(resource, 'allowed_read_roles')
self.assertValidateRoles(resource, 'allowed_write_roles')
self.assertValidateRoles(resource, 'allowed_item_roles')
self.assertValidateRoles(resource, 'allowed_item_read_roles')
self.assertValidateRoles(resource, 'allowed_item_write_roles')
def assertValidateRoles(self, resource, directive):
prev = self.domain[resource][directive]
self.domain[resource][directive] = 'admin'
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = []
self.assertValidateConfigSuccess()
self.domain[resource][directive] = ['admin', 'dev']
self.assertValidateConfigSuccess()
self.domain[resource][directive] = None
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = prev
def assertValidateConfigSuccess(self):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
self.fail('ConfigException not expected: %s' % e)
def assertValidateConfigFailure(self, expected):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException as e:
if isinstance(expected, str):
expected = [expected]
for exp in expected:
self.assertTrue(exp.lower() in str(e).lower())
else:
self.fail("ConfigException expected but not raised.")
def assertValidateSchemaFailure(self, resource, schema, expected):
try:
self.app.validate_schema(resource, schema)
except SchemaException as e:
self.assertTrue(expected.lower() in str(e).lower())
else:
self.fail("SchemaException expected but not raised.")
def test_schema_defaults(self):
self.domain.clear()
self.domain['resource'] = {
'schema': {
'title': {
'type': 'string',
'default': 'Mr.',
},
'price': {
示例6: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
#.........这里部分代码省略.........
def test_validate_item_methods(self):
self.app.config['ITEM_METHODS'] = ['PUT', 'GET', 'POST', 'DELETE']
self.assertValidateConfigFailure('PUT, POST')
def test_validate_schema_methods(self):
test = {
'methods': ['PUT', 'GET', 'DELETE', 'POST'],
}
self.app.config['DOMAIN']['test_resource'] = test
self.assertValidateConfigFailure('PUT')
def test_validate_schema_item_methods(self):
test = {
'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)
def test_validate_lastupdated_in_schema(self):
self.assertUnallowedField(eve.LAST_UPDATED)
def test_validate_idfield_in_schema(self):
self.assertUnallowedField(eve.ID_FIELD)
def assertUnallowedField(self, field):
self.domain.clear()
self.domain['resource'] = {
'schema': {
field: {'type': 'datetime'}
}
}
self.app.set_defaults()
self.assertValidateConfigFailure('automatically')
def test_set_defaults(self):
self.domain.clear()
resource = 'plurals'
self.domain[resource] = {}
self.app.set_defaults()
settings = self.domain[resource]
self.assertEqual(settings['url'], resource)
self.assertEqual(settings['methods'],
self.app.config['RESOURCE_METHODS'])
self.assertEqual(settings['public_methods'],
self.app.config['PUBLIC_METHODS'])
self.assertEqual(settings['allowed_roles'],
self.app.config['ALLOWED_ROLES'])
self.assertEqual(settings['cache_control'],
self.app.config['CACHE_CONTROL'])
self.assertEqual(settings['cache_expires'],
self.app.config['CACHE_EXPIRES'])
self.assertEqual(settings['item_methods'],
self.app.config['ITEM_METHODS'])
self.assertEqual(settings['public_item_methods'],
self.app.config['PUBLIC_ITEM_METHODS'])
self.assertEqual(settings['allowed_item_roles'],
self.app.config['ALLOWED_ITEM_ROLES'])
self.assertEqual(settings['item_lookup'],
self.app.config['ITEM_LOOKUP'])
self.assertEqual(settings['item_lookup_field'],
self.app.config['ITEM_LOOKUP_FIELD'])
self.assertEqual(settings['item_url'],
self.app.config['ITEM_URL'])
self.assertEqual(settings['item_title'],
resource.rstrip('s').capitalize())
self.assertEqual(settings['item_cache_control'],
self.app.config['ITEM_CACHE_CONTROL'])
self.assertNotEqual(settings['schema'], None)
self.assertEqual(type(settings['schema']), dict)
self.assertEqual(len(settings['schema']), 0)
self.assertEqual(settings['datasource'],
{'source': resource, 'filter': None})
def test_validate_roles(self):
for resource in self.domain:
self.assertValidateRoles(resource, 'allowed_roles')
self.assertValidateRoles(resource, 'allowed_item_roles')
def assertValidateRoles(self, resource, directive):
self.domain[resource][directive] = 'admin'
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = []
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = ['admin', 'dev']
self.assertValidateConfigSuccess()
self.domain[resource][directive] = None
self.assertValidateConfigSuccess()
def assertValidateConfigSuccess(self):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException, e:
self.fail('ConfigException not expected: %s' % e)
示例7: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import validate_config [as 别名]
#.........这里部分代码省略.........
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)
def test_validate_lastupdated_in_schema(self):
self.assertUnallowedField(eve.LAST_UPDATED)
def test_validate_idfield_in_schema(self):
self.assertUnallowedField(eve.ID_FIELD)
def assertUnallowedField(self, field):
self.domain.clear()
schema = {field: {"type": "datetime"}}
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"]["collection"])
self.assertValidateSchemaFailure("invoices", schema, "collection")
def test_set_schema_defaults(self):
# default data_relation field value
schema = self.domain["invoices"]["schema"]
data_relation = schema["person"]["data_relation"]
self.assertTrue("field" in data_relation)
self.assertEqual(data_relation["field"], self.app.config["ID_FIELD"])
def test_set_defaults(self):
self.domain.clear()
resource = "plurals"
self.domain[resource] = {}
self.app.set_defaults()
settings = self.domain[resource]
self.assertEqual(settings["url"], resource)
self.assertEqual(settings["resource_methods"], self.app.config["RESOURCE_METHODS"])
self.assertEqual(settings["public_methods"], self.app.config["PUBLIC_METHODS"])
self.assertEqual(settings["allowed_roles"], self.app.config["ALLOWED_ROLES"])
self.assertEqual(settings["cache_control"], self.app.config["CACHE_CONTROL"])
self.assertEqual(settings["cache_expires"], self.app.config["CACHE_EXPIRES"])
self.assertEqual(settings["item_methods"], self.app.config["ITEM_METHODS"])
self.assertEqual(settings["public_item_methods"], self.app.config["PUBLIC_ITEM_METHODS"])
self.assertEqual(settings["allowed_item_roles"], self.app.config["ALLOWED_ITEM_ROLES"])
self.assertEqual(settings["item_lookup"], self.app.config["ITEM_LOOKUP"])
self.assertEqual(settings["item_lookup_field"], self.app.config["ITEM_LOOKUP_FIELD"])
self.assertEqual(settings["item_url"], self.app.config["ITEM_URL"])
self.assertEqual(settings["item_title"], resource.rstrip("s").capitalize())
self.assertEqual(settings["filters"], self.app.config["FILTERS"])
self.assertEqual(settings["projection"], self.app.config["PROJECTION"])
self.assertEqual(settings["sorting"], self.app.config["SORTING"])
self.assertEqual(settings["pagination"], self.app.config["PAGINATION"])
self.assertEqual(settings["auth_username_field"], self.app.config["AUTH_USERNAME_FIELD"])
self.assertEqual(settings["allow_unknown"], self.app.config["ALLOW_UNKNOWN"])
self.assertNotEqual(settings["schema"], None)
self.assertEqual(type(settings["schema"]), dict)
self.assertEqual(len(settings["schema"]), 0)
def test_datasource(self):
resource = "invoices"
datasource = self.domain[resource]["datasource"]
schema = self.domain[resource]["schema"]
compare = filter(schema.has_key, datasource["projection"])
compare.extend([self.app.config["ID_FIELD"], self.app.config["LAST_UPDATED"], self.app.config["DATE_CREATED"]])
self.assertEqual(datasource["projection"], dict((field, 1) for (field) in compare))
self.assertEqual(datasource["source"], resource)
self.assertEqual(datasource["filter"], None)
def test_validate_roles(self):
for resource in self.domain:
self.assertValidateRoles(resource, "allowed_roles")
self.assertValidateRoles(resource, "allowed_item_roles")
def assertValidateRoles(self, resource, directive):
self.domain[resource][directive] = "admin"
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = []
self.assertValidateConfigFailure(directive)
self.domain[resource][directive] = ["admin", "dev"]
self.assertValidateConfigSuccess()
self.domain[resource][directive] = None
self.assertValidateConfigSuccess()
def assertValidateConfigSuccess(self):
try:
self.app.validate_domain_struct()
self.app.validate_config()
except ConfigException, e:
self.fail("ConfigException not expected: %s" % e)