本文整理匯總了Python中AerospikeClientMock.AerospikeClientMock.query方法的典型用法代碼示例。如果您正苦於以下問題:Python AerospikeClientMock.query方法的具體用法?Python AerospikeClientMock.query怎麽用?Python AerospikeClientMock.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AerospikeClientMock.AerospikeClientMock
的用法示例。
在下文中一共展示了AerospikeClientMock.query方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestAerospikeQueryMock
# 需要導入模塊: from AerospikeClientMock import AerospikeClientMock [as 別名]
# 或者: from AerospikeClientMock.AerospikeClientMock import query [as 別名]
class TestAerospikeQueryMock(unittest.TestCase):
def setUp(self):
self.asm = AerospikeClientMock()
self.asm.put(("a", "b", 1), {"a": 1, "b": 1})
self.asm.put(("a", "b", 2), {"a": 2, "b": 2})
self.asm.put(("a", "b", 3), {"a": 3, "b": 3})
self.asm.put(("a", "c", 4), {"a": 4, "b": 4})
def test_query(self):
query = self.asm.query('a', 'b')
query.select('a', 'c')
self.assertEqual(
[
(('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'c': None}),
(('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'c': None}),
(('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'c': None}),
],
query.results())
def test_query_namespace(self):
query = self.asm.query('a')
query.select('a', 'b')
self.assertEqual(
[
(('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'b': 1}),
(('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'b': 2}),
(('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'b': 3}),
(('a', 'c', 4), {'gen': 1, 'ttl': 0}, {'a': 4, 'b': 4}),
],
query.results())
def test_query_callback(self):
result = []
def callback(data):
(key, meta, bins) = data
result.append((key, meta, bins))
query = self.asm.query('a', 'b')
query.select('a', 'c')
query.foreach(callback)
self.assertEqual(
[
(
(('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'c': None}),
(('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'c': None}),
(('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'c': None}),
)
],
result)
def test_query_equals(self):
query = self.asm.query('a', 'b')
query.select('a', 'c')
query.where(AerospikePredicatesMock().equals("a", 1))
self.assertEqual(
[(('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'c': None})],
query.results())
def test_query_between(self):
query = self.asm.query('a', 'b')
query.select('a', 'c')
query.where(AerospikePredicatesMock().between("a", 1, 4))
self.assertEqual(
[(('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'c': None}),
(('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'c': None})],
query.results())
def test_query_contains(self):
self.asm.put(("a", "l", 1), {"list": [1, 2, 3, 4, 5]})
self.asm.put(("a", "l", 2), {"list": [1, 3, 4, 5]})
query = self.asm.query('a', 'l')
query.select('list')
query.where(AerospikePredicatesMock().contains("list", list, 2))
self.assertEqual(
[(('a', 'l', 1), {'gen': 1, 'ttl': 0}, {'list': [1, 2, 3, 4, 5]})],
query.results())
def test_query_range(self):
self.asm.put(("a", "l", 1), {"list": [1, 2, 3, 4, 5]})
self.asm.put(("a", "l", 2), {"list": [4, 5]})
query = self.asm.query('a', 'l')
query.select('list')
query.where(AerospikePredicatesMock().range("list", list, 1, 3))
self.assertEqual(
[(('a', 'l', 1), {'gen': 1, 'ttl': 0}, {'list': [1, 2, 3, 4, 5]})],
query.results())