本文整理汇总了Python中eve.flaskapp.Eve类的典型用法代码示例。如果您正苦于以下问题:Python Eve类的具体用法?Python Eve怎么用?Python Eve使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Eve类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_datalayer
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)
示例2: test_allow_unknown_with_soft_delete
def test_allow_unknown_with_soft_delete(self):
my_settings = {
'ALLOW_UNKNOWN': True,
'SOFT_DELETE': True,
'DOMAIN': {'contacts': {}}
}
try:
self.app = Eve(settings=my_settings)
except TypeError:
self.fail("ALLOW_UNKNOWN and SOFT_DELETE enabled should not cause "
"a crash.")
示例3: test_allow_unknown_with_soft_delete
def test_allow_unknown_with_soft_delete(self):
my_settings = {
"ALLOW_UNKNOWN": True,
"SOFT_DELETE": True,
"DOMAIN": {"contacts": {}},
}
try:
self.app = Eve(settings=my_settings)
except TypeError:
self.fail(
"ALLOW_UNKNOWN and SOFT_DELETE enabled should not cause " "a crash."
)
示例4: TestConfig
class TestConfig(TestBase):
def test_allow_unknown_with_soft_delete(self):
my_settings = {
"ALLOW_UNKNOWN": True,
"SOFT_DELETE": True,
"DOMAIN": {"contacts": {}},
}
try:
self.app = Eve(settings=my_settings)
except TypeError:
self.fail(
"ALLOW_UNKNOWN and SOFT_DELETE enabled should not cause " "a crash."
)
def test_default_import_name(self):
self.assertEqual(self.app.import_name, eve.__package__)
def test_custom_import_name(self):
self.app = Eve("unittest", settings=self.settings_file)
self.assertEqual(self.app.import_name, "unittest")
def test_custom_kwargs(self):
self.app = Eve("unittest", static_folder="/", settings=self.settings_file)
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})
self.assertEqual(self.app.config["ISSUES"], "_issues")
self.assertEqual(self.app.config["OPLOG"], False)
self.assertEqual(self.app.config["OPLOG_NAME"], "oplog")
self.assertEqual(self.app.config["OPLOG_ENDPOINT"], None)
self.assertEqual(self.app.config["OPLOG_AUDIT"], True)
self.assertEqual(
self.app.config["OPLOG_METHODS"], ["DELETE", "POST", "PATCH", "PUT"]
)
self.assertEqual(
self.app.config["OPLOG_CHANGE_METHODS"], ["DELETE", "PATCH", "PUT"]
)
self.assertEqual(self.app.config["QUERY_WHERE"], "where")
self.assertEqual(self.app.config["QUERY_PROJECTION"], "projection")
self.assertEqual(self.app.config["QUERY_SORT"], "sort")
self.assertEqual(self.app.config["QUERY_PAGE"], "page")
self.assertEqual(self.app.config["QUERY_MAX_RESULTS"], "max_results")
self.assertEqual(self.app.config["QUERY_EMBEDDED"], "embedded")
self.assertEqual(self.app.config["QUERY_AGGREGATION"], "aggregate")
self.assertEqual(self.app.config["JSON_SORT_KEYS"], False)
self.assertEqual(self.app.config["SOFT_DELETE"], False)
self.assertEqual(self.app.config["DELETED"], "_deleted")
self.assertEqual(self.app.config["SHOW_DELETED_PARAM"], "show_deleted")
self.assertEqual(
self.app.config["STANDARD_ERRORS"],
[400, 401, 404, 405, 406, 409, 410, 412, 422, 428, 429],
)
self.assertEqual(self.app.config["UPSERT_ON_PUT"], True)
self.assertEqual(
self.app.config["JSON_REQUEST_CONTENT_TYPES"], ["application/json"]
)
self.assertEqual(self.app.config["NORMALIZE_DOTTED_FIELDS"], True)
def test_settings_as_dict(self):
my_settings = {"API_VERSION": "override!", "DOMAIN": {"contacts": {}}}
self.app = Eve(settings=my_settings)
self.assertEqual(self.app.config["API_VERSION"], "override!")
# did not reset other defaults
self.assertEqual(self.app.config["MONGO_WRITE_CONCERN"], {"w": 1})
def test_existing_env_config(self):
env = os.environ
os.environ = {"EVE_SETTINGS": "test_settings_env.py"}
self.app = Eve()
self.assertTrue("env_domain" in self.app.config["DOMAIN"])
os.environ = env
def test_unexisting_env_config(self):
env = os.environ
try:
os.environ = {"EVE_SETTINGS": "an_unexisting_pyfile.py"}
#.........这里部分代码省略.........
示例5: test_custom_kwargs
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, '/')
示例6: TestConfig
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:
示例7: TestConfig
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)
#.........这里部分代码省略.........
示例8: test_custom_import_name
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')
示例9: test_custom_kwargs
def test_custom_kwargs(self):
self.app = Eve('unittest', static_folder='/',
settings=self.settings_file)
self.assertEqual(self.app.static_folder, '/')
示例10: test_custom_import_name
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")
示例11: test_custom_validator
def test_custom_validator(self):
class MyTestValidator(Validator):
pass
self.app = Eve(validator=MyTestValidator,
settings=self.settings_file)
self.assertEqual(self.app.validator, MyTestValidator)
示例12: test_custom_kwargs
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, "/")
示例13: test_existing_env_config
def test_existing_env_config(self):
env = os.environ
os.environ = {"EVE_SETTINGS": "test_settings_env.py"}
self.app = Eve()
self.assertTrue("env_domain" in self.app.config["DOMAIN"])
os.environ = env
示例14: TestConfig
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('unittest', settings=self.settings_file)
self.assertEqual(self.app.import_name, 'unittest')
def test_custom_kwargs(self):
self.app = Eve('unittest', static_folder='/',
settings=self.settings_file)
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})
self.assertEqual(self.app.config['ISSUES'], '_issues')
self.assertEqual(self.app.config['OPLOG'], False)
self.assertEqual(self.app.config['OPLOG_NAME'], 'oplog')
self.assertEqual(self.app.config['OPLOG_ENDPOINT'], None)
self.assertEqual(self.app.config['OPLOG_AUDIT'], True)
self.assertEqual(self.app.config['OPLOG_METHODS'], ['DELETE',
'POST',
'PATCH',
'PUT'])
self.assertEqual(self.app.config['QUERY_WHERE'], 'where')
self.assertEqual(self.app.config['QUERY_PROJECTION'], 'projection')
self.assertEqual(self.app.config['QUERY_SORT'], 'sort')
self.assertEqual(self.app.config['QUERY_PAGE'], 'page')
self.assertEqual(self.app.config['QUERY_MAX_RESULTS'], 'max_results')
self.assertEqual(self.app.config['QUERY_EMBEDDED'], 'embedded')
self.assertEqual(self.app.config['JSON_SORT_KEYS'], False)
def test_settings_as_dict(self):
my_settings = {'API_VERSION': 'override!', 'DOMAIN': {'contacts': {}}}
self.app = Eve(settings=my_settings)
self.assertEqual(self.app.config['API_VERSION'], 'override!')
# did not reset other defaults
self.assertEqual(self.app.config['MONGO_WRITE_CONCERN'], {'w': 1})
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
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')
#.........这里部分代码省略.........
示例15: TestConfig
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 = {
'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': {
#.........这里部分代码省略.........