本文整理汇总了Python中backend.Backend.get_root方法的典型用法代码示例。如果您正苦于以下问题:Python Backend.get_root方法的具体用法?Python Backend.get_root怎么用?Python Backend.get_root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backend.Backend
的用法示例。
在下文中一共展示了Backend.get_root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBackend
# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import get_root [as 别名]
class TestBackend():
'''A unittest class for nosetests. Tests backend and database functionality.
'''
def setUp(self):
log.basicConfig(level=log.DEBUG)
self.backend = Backend()
def tearDown(self):
self.backend = None
def test_init(self):
pass
def test_get_root(self):
try:
self.backend.get_root()
except:
assert False
def test_connection(self):
try:
obj = self.backend.db.products.find_one()
log.info(obj)
assert type(obj) is DictType
except:
assert False
def test_parse_args(self):
args = ImmutableMultiDict()
# No args should return base dictionary
assert self.backend.parse_args(args) == BASE_ARGS
# Incorrect args should return base dict
args = ImmutableMultiDict([('dfdd', 'frefrf'), (342, 4334)])
assert self.backend.parse_args(args) == BASE_ARGS
def test_get_categories(self):
categories = set([
'electronics',
'books',
'movies',
'comics',
'games'
])
assert categories == set(self.backend.get_categories())
def test_parse_args_limit(self):
# Correct arg should return dict with arg as key
args = ImmutableMultiDict([
('limit', 20),
('limit', 15)
])
val = self.backend.parse_args(args)
assert 'limit' in val
# value should be the last passed parameter
assert val['limit'] == 15
def test_parse_args_field(self):
# giving a field argument should return dict with fields as key
args = ImmutableMultiDict([
('field', 'price'),
('notfield', 'description')
])
val = self.backend.parse_args(args)
assert 'fields' in val
# Should be dict
assert type(val['fields']) is dict
assert 'price' not in val['fields']
assert not val['fields']['description']
def test_parse_args_field_id(self):
# giving a field argument should return dict with fields as key
args = ImmutableMultiDict([
('field', '_id'),
('notfield', 'description')
])
val = self.backend.parse_args(args)
assert 'fields' in val
# Should be dict
assert type(val['fields']) is dict
# _id should be false
assert not val['fields']['_id']
assert not val['fields']['description']
def test_parse_args_category(self):
args = ImmutableMultiDict([
('category', 'electronics'),
('notcategory', 'Flim flam')
])
val = self.backend.parse_args(args)
assert 'spec' in val
assert 'electronics' in val['spec']['category']['$in']
assert 'flim flam' in val['spec']['category']['$nin']
def test_parse_args_price(self):
args = ImmutableMultiDict([
('maxprice', 50),
('maxprice', 200)
])
val = self.backend.parse_args(args)
#.........这里部分代码省略.........