本文整理汇总了Python中eve.flaskapp.Eve._init_oplog方法的典型用法代码示例。如果您正苦于以下问题:Python Eve._init_oplog方法的具体用法?Python Eve._init_oplog怎么用?Python Eve._init_oplog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eve.flaskapp.Eve
的用法示例。
在下文中一共展示了Eve._init_oplog方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import _init_oplog [as 别名]
#.........这里部分代码省略.........
settings = {
"schema": {
"title": {"type": "string", "default": "Mr."},
"price": {"type": "integer", "default": 100},
}
}
self.app.register_resource(resource, settings)
self._test_defaults_for_resource(resource)
self._test_datasource_for_resource(resource)
self.test_validate_roles()
def test_auth_field_as_idfield(self):
resource = "resource"
settings = {"auth_field": self.app.config["ID_FIELD"]}
self.assertRaises(
ConfigException, self.app.register_resource, resource, settings
)
def test_auth_field_as_custom_idfield(self):
resource = "resource"
settings = {
"schema": {"id": {"type": "string"}},
"id_field": "id",
"auth_field": "id",
}
self.assertRaises(
ConfigException, self.app.register_resource, resource, settings
)
def test_oplog_config(self):
# if OPLOG_ENDPOINT is eanbled the endoint is included with the domain
self.app.config["OPLOG_ENDPOINT"] = "oplog"
self.app._init_oplog()
self.assertOplog("oplog", "oplog")
del self.domain["oplog"]
# OPLOG can be also with a custom name (which will be used
# as the collection/table name on the db)
oplog = "custom"
self.app.config["OPLOG_NAME"] = oplog
self.app._init_oplog()
self.assertOplog(oplog, "oplog")
del self.domain[oplog]
# oplog can be defined as a regular API endpoint, with a couple caveats
self.domain["oplog"] = {
"resource_methods": ["POST", "DELETE"], # not allowed
"resource_items": ["PATCH", "PUT"], # not allowed
"url": "custom_url",
"datasource": {"source": "customsource"},
}
self.app.config["OPLOG_NAME"] = "oplog"
settings = self.domain["oplog"]
self.app._init_oplog()
# endpoint is always read-only
self.assertEqual(settings["resource_methods"], ["GET"])
self.assertEqual(settings["item_methods"], ["GET"])
# other settings are customizable
self.assertEqual(settings["url"], "custom_url")
self.assertEqual(settings["datasource"]["source"], "customsource")
def assertOplog(self, key, endpoint):
self.assertTrue(key in self.domain)
示例2: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import _init_oplog [as 别名]
#.........这里部分代码省略.........
'default': 100
},
}
}
self.app.register_resource(resource, settings)
self._test_defaults_for_resource(resource)
self._test_datasource_for_resource(resource)
self.test_validate_roles()
def test_auth_field_as_idfield(self):
resource = 'resource'
settings = {
'auth_field': self.app.config['ID_FIELD'],
}
self.assertRaises(ConfigException, self.app.register_resource,
resource, settings)
def test_auth_field_as_custom_idfield(self):
resource = 'resource'
settings = {
'schema': {
'id': {'type': 'string'}
},
'id_field': 'id',
'auth_field': 'id'
}
self.assertRaises(ConfigException, self.app.register_resource,
resource, settings)
def test_oplog_config(self):
# if OPLOG_ENDPOINT is eanbled the endoint is included with the domain
self.app.config['OPLOG_ENDPOINT'] = 'oplog'
self.app._init_oplog()
self.assertOplog('oplog', 'oplog')
del(self.domain['oplog'])
# OPLOG can be also with a custom name (which will be used
# as the collection/table name on the db)
oplog = 'custom'
self.app.config['OPLOG_NAME'] = oplog
self.app._init_oplog()
self.assertOplog(oplog, 'oplog')
del(self.domain[oplog])
# oplog can be defined as a regular API endpoint, with a couple caveats
self.domain['oplog'] = {
'resource_methods': ['POST', 'DELETE'], # not allowed
'resource_items': ['PATCH', 'PUT'], # not allowed
'url': 'custom_url',
'datasource': {'source': 'customsource'}
}
self.app.config['OPLOG_NAME'] = 'oplog'
settings = self.domain['oplog']
self.app._init_oplog()
# endpoint is always read-only
self.assertEqual(settings['resource_methods'], ['GET'])
self.assertEqual(settings['item_methods'], ['GET'])
# other settings are customizable
self.assertEqual(settings['url'], 'custom_url')
self.assertEqual(settings['datasource']['source'], 'customsource')
def assertOplog(self, key, endpoint):
self.assertTrue(key in self.domain)
示例3: TestConfig
# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import _init_oplog [as 别名]
#.........这里部分代码省略.........
for resource, settings in self.domain.items():
self.assertEqual(settings['datasource'],
self.app.config['SOURCES'][resource])
def test_pretty_resource_urls(self):
""" test that regexes are stripped out of urls and #466 is fixed. """
resource_url = self.app.config['URLS']['peopleinvoices']
pretty_url = 'users/<person>/invoices'
self.assertEqual(resource_url, pretty_url)
resource_url = self.app.config['URLS']['peoplesearches']
pretty_url = 'users/<person>/saved_searches'
self.assertEqual(resource_url, pretty_url)
def test_url_rules(self):
map_adapter = self.app.url_map.bind('')
del(self.domain['peopleinvoices'])
del(self.domain['peoplesearches'])
del(self.domain['internal_transactions'])
for _, settings in self.domain.items():
for method in settings['resource_methods']:
self.assertTrue(map_adapter.test('/%s/' % settings['url'],
method))
# TODO test item endpoints as well. gonna be tricky since
# we have to reverse regexes here. will be fun.
def test_register_resource(self):
resource = 'resource'
settings = {
'schema': {
'title': {
'type': 'string',
'default': 'Mr.',
},
'price': {
'type': 'integer',
'default': 100
},
}
}
self.app.register_resource(resource, settings)
self._test_defaults_for_resource(resource)
self._test_datasource_for_resource(resource)
self.test_validate_roles()
def test_auth_field_as_idfield(self):
resource = 'resource'
settings = {
'auth_field': self.app.config['ID_FIELD'],
}
self.assertRaises(ConfigException, self.app.register_resource,
resource, settings)
def test_oplog_config(self):
# OPLOG_ENDPOINT is disabled by default so we don't have the endpoint
# in our domain
self.assertFalse('oplog' in self.domain)
# if OPLOG_ENDPOINT is eanbled the endoint is included with the domain
self.app.config['OPLOG_ENDPOINT'] = 'oplog'
self.app._init_oplog()
self.assertOplog('oplog', 'oplog')
del(self.domain['oplog'])
# OPLOG can be also with a custom name (which will be used
# as the collection/table name on the db)
oplog = 'custom'
self.app.config['OPLOG_NAME'] = oplog
self.app._init_oplog()
self.assertOplog(oplog, 'oplog')
del(self.domain[oplog])
# oplog can be defined as a regular API endpoint, with a couple caveats
self.domain['oplog'] = {
'resource_methods': ['POST', 'DELETE'], # not allowed
'resource_items': ['PATCH', 'PUT'], # not allowed
'url': 'custom_url',
'datasource': {'source': 'customsource'}
}
self.app.config['OPLOG_NAME'] = 'oplog'
settings = self.domain['oplog']
self.app._init_oplog()
# endpoint is always read-only
self.assertEqual(settings['resource_methods'], ['GET'])
self.assertEqual(settings['item_methods'], ['GET'])
# other settings are customizable
self.assertEqual(settings['url'], 'custom_url')
self.assertEqual(settings['datasource']['source'], 'customsource')
def assertOplog(self, key, endpoint):
self.assertTrue(key in self.domain)
settings = self.domain[key]
self.assertEqual(settings['resource_methods'], ['GET'])
self.assertEqual(settings['item_methods'], ['GET'])
self.assertEqual(settings['url'], endpoint)
self.assertEqual(settings['datasource']['source'], key)