本文整理汇总了Python中eve.flaskapp.Eve.set_defaults方法的典型用法代码示例。如果您正苦于以下问题:Python Eve.set_defaults方法的具体用法?Python Eve.set_defaults怎么用?Python Eve.set_defaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eve.flaskapp.Eve
的用法示例。
在下文中一共展示了Eve.set_defaults方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import set_defaults [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 set_defaults [as 别名]
#.........这里部分代码省略.........
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')
del(schema['te$t'])
schema['te.t'] = {'type': 'string'}
self.assertValidateSchemaFailure('invoices', schema, 'te.t')
del(schema['te.t'])
schema['test_a_dict_schema'] = {
'type': 'dict',
'schema': {'te$t': {'type': 'string'}}
}
self.assertValidateSchemaFailure('invoices', schema, 'te$t')
schema['test_a_dict_schema']['schema'] = {'te.t': {'type': 'string'}}
self.assertValidateSchemaFailure('invoices', schema, 'te.t')
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)
示例3: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import set_defaults [as 别名]
#.........这里部分代码省略.........
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)
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'])
示例4: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import set_defaults [as 别名]
#.........这里部分代码省略.........
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")
del schema["te$t"]
schema["te.t"] = {"type": "string"}
self.assertValidateSchemaFailure("invoices", schema, "te.t")
del schema["te.t"]
schema["test_a_dict_schema"] = {
"type": "dict",
"schema": {"te$t": {"type": "string"}},
}
self.assertValidateSchemaFailure("invoices", schema, "te$t")
schema["test_a_dict_schema"]["schema"] = {"te.t": {"type": "string"}}
self.assertValidateSchemaFailure("invoices", schema, "te.t")
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)
示例5: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import set_defaults [as 别名]
#.........这里部分代码省略.........
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
schema = self.domain['invoices']['schema']
del(schema['person']['data_relation']['resource'])
self.assertValidateSchemaFailure('invoices', schema, 'resource')
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()
self._test_defaults_for_resource(resource)
settings = self.domain[resource]
self.assertEqual(len(settings['schema']), 0)
def _test_defaults_for_resource(self, resource):
settings = self.domain[resource]
self.assertEqual(settings['url'], resource)
self.assertEqual(settings['internal_resource'],
self.app.config['INTERNAL_RESOURCE'])
self.assertEqual(settings['resource_methods'],
self.app.config['RESOURCE_METHODS'])
self.assertEqual(settings['public_methods'],
示例6: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import set_defaults [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 set_defaults [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)
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("PUT, POST")
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)
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"]
#.........这里部分代码省略.........