Merge "Clean pagination related methods of impl_mongodb"
This commit is contained in:
commit
9393924c1d
@ -314,38 +314,6 @@ class Connection(pymongo_base.Connection):
|
||||
LOG.debug("Clearing expired metering data is based on native "
|
||||
"MongoDB time to live feature and going in background.")
|
||||
|
||||
@staticmethod
|
||||
def _get_marker(db_collection, marker_pairs):
|
||||
"""Return the mark document according to the attribute-value pairs.
|
||||
|
||||
:param db_collection: Database collection that be query.
|
||||
:param maker_pairs: Attribute-value pairs filter.
|
||||
"""
|
||||
if db_collection is None:
|
||||
return
|
||||
if not marker_pairs:
|
||||
return
|
||||
ret = db_collection.find(marker_pairs, limit=2)
|
||||
|
||||
if ret.count() == 0:
|
||||
raise base.NoResultFound
|
||||
elif ret.count() > 1:
|
||||
raise base.MultipleResultsFound
|
||||
else:
|
||||
_ret = ret.__getitem__(0)
|
||||
return _ret
|
||||
|
||||
@classmethod
|
||||
def _recurse_sort_keys(cls, sort_keys, marker, flag):
|
||||
_first = sort_keys[0]
|
||||
value = marker[_first]
|
||||
if len(sort_keys) == 1:
|
||||
return {_first: {flag: value}}
|
||||
else:
|
||||
criteria_equ = {_first: {'eq': value}}
|
||||
criteria_cmp = cls._recurse_sort_keys(sort_keys[1:], marker, flag)
|
||||
return dict(criteria_equ, ** criteria_cmp)
|
||||
|
||||
@classmethod
|
||||
def _build_sort_instructions(cls, sort_keys=None, sort_dir='desc'):
|
||||
"""Returns a sort_instruction and paging operator.
|
||||
|
@ -38,16 +38,6 @@ class MongoDBConnection(tests_db.TestBase):
|
||||
conn = impl_mongodb.Connection(url)
|
||||
self.assertTrue(conn.conn)
|
||||
|
||||
def test_recurse_sort_keys(self):
|
||||
sort_keys = ['k1', 'k2', 'k3']
|
||||
marker = {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
|
||||
flag = '$lt'
|
||||
ret = impl_mongodb.Connection._recurse_sort_keys(sort_keys=sort_keys,
|
||||
marker=marker,
|
||||
flag=flag)
|
||||
expect = {'k3': {'$lt': 'v3'}, 'k2': {'eq': 'v2'}, 'k1': {'eq': 'v1'}}
|
||||
self.assertEqual(expect, ret)
|
||||
|
||||
|
||||
@tests_db.run_with('mongodb')
|
||||
class IndexTest(tests_db.TestBase):
|
||||
|
Loading…
Reference in New Issue
Block a user