@@ -759,6 +759,33 @@ def transform_incoming(self, thing, collection):
759759 out = db .test .find_one ()
760760 self .assertEqual ('value' , out .get ('value' ))
761761
762+ def test_son_manipulator_outgoing (self ):
763+ class Thing (object ):
764+ def __init__ (self , value ):
765+ self .value = value
766+
767+ class ThingTransformer (SONManipulator ):
768+ def transform_outgoing (self , doc , collection ):
769+ # We don't want this applied to the command return
770+ # value in pymongo.cursor.Cursor.
771+ if 'value' in doc :
772+ return Thing (doc ['value' ])
773+ return doc
774+
775+ db = self .client .foo
776+ db .add_son_manipulator (ThingTransformer ())
777+
778+ db .test .remove ()
779+ db .test .insert ({'value' : 'value' })
780+ out = db .test .find_one ()
781+ self .assertTrue (isinstance (out , Thing ))
782+ self .assertEqual ('value' , out .value )
783+
784+ if version .at_least (self .client , (2 , 6 )):
785+ out = db .test .aggregate ([], cursor = {}).next ()
786+ self .assertTrue (isinstance (out , Thing ))
787+ self .assertEqual ('value' , out .value )
788+
762789 def test_son_manipulator_inheritance (self ):
763790 class Thing (object ):
764791 def __init__ (self , value ):
0 commit comments