PYTHON-893 - Fix application of SON manipulators in CommandCursor.
This commit is contained in:
parent
eda1e771f6
commit
eaaa54b903
@ -169,7 +169,7 @@ class CommandCursor(object):
|
||||
"""
|
||||
if len(self.__data) or self._refresh():
|
||||
coll = self.__collection
|
||||
return coll.database._fix_incoming(self.__data.popleft(), coll)
|
||||
return coll.database._fix_outgoing(self.__data.popleft(), coll)
|
||||
else:
|
||||
raise StopIteration
|
||||
|
||||
|
||||
@ -759,6 +759,33 @@ class TestDatabase(unittest.TestCase):
|
||||
out = db.test.find_one()
|
||||
self.assertEqual('value', out.get('value'))
|
||||
|
||||
def test_son_manipulator_outgoing(self):
|
||||
class Thing(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
class ThingTransformer(SONManipulator):
|
||||
def transform_outgoing(self, doc, collection):
|
||||
# We don't want this applied to the command return
|
||||
# value in pymongo.cursor.Cursor.
|
||||
if 'value' in doc:
|
||||
return Thing(doc['value'])
|
||||
return doc
|
||||
|
||||
db = self.client.foo
|
||||
db.add_son_manipulator(ThingTransformer())
|
||||
|
||||
db.test.remove()
|
||||
db.test.insert({'value': 'value'})
|
||||
out = db.test.find_one()
|
||||
self.assertTrue(isinstance(out, Thing))
|
||||
self.assertEqual('value', out.value)
|
||||
|
||||
if version.at_least(self.client, (2, 6)):
|
||||
out = db.test.aggregate([], cursor={}).next()
|
||||
self.assertTrue(isinstance(out, Thing))
|
||||
self.assertEqual('value', out.value)
|
||||
|
||||
def test_son_manipulator_inheritance(self):
|
||||
class Thing(object):
|
||||
def __init__(self, value):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user