diff --git a/test/test_collection.py b/test/test_collection.py index 5916ee60e..9ef3c2678 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -1460,12 +1460,9 @@ class TestCollection(unittest.TestCase): pipeline = {"$project": {"_id": False, "foo": True}} for result in [ - db.test.aggregate(pipeline), - db.test.aggregate([pipeline]), - db.test.aggregate((pipeline,))]: - - self.assertEqual(1.0, result['ok']) - self.assertEqual([{'foo': [1, 2]}], result['result']) + (db.test.aggregate(pl, cursor={})).next() + for pl in (pipeline, [pipeline], (pipeline,))]: + self.assertEqual({'foo': [1, 2]}, result) def test_aggregate_with_compile_re(self): # See SERVER-6470. @@ -1478,10 +1475,10 @@ class TestCollection(unittest.TestCase): db.test.drop() db.test.insert({'r': re.compile('.*')}) - result = db.test.aggregate([]) - self.assertTrue(isinstance(result['result'][0]['r'], RE_TYPE)) - result = db.test.aggregate([], compile_re=False) - self.assertTrue(isinstance(result['result'][0]['r'], Regex)) + result = db.test.aggregate([], cursor={}).next() + self.assertTrue(isinstance(result['r'], RE_TYPE)) + result = db.test.aggregate([], cursor={}, compile_re=False).next() + self.assertTrue(isinstance(result['r'], Regex)) def test_aggregation_cursor_validation(self): # Regardless of version, should return CommandCursor when given @@ -1491,10 +1488,11 @@ class TestCollection(unittest.TestCase): cursor = db.test.aggregate(projection, cursor={}) self.assertTrue(isinstance(cursor, CommandCursor)) - db = self.db - projection = {'$project': {'_id': '$_id'}} - cursor = db.test.aggregate(projection) - self.assertFalse(isinstance(cursor, CommandCursor)) + if not version.at_least(self.db.connection, (3, 5, 1)): + db = self.db + projection = {'$project': {'_id': '$_id'}} + cursor = db.test.aggregate(projection) + self.assertFalse(isinstance(cursor, CommandCursor)) def test_aggregation_cursor(self): db = self.db diff --git a/test/test_database.py b/test/test_database.py index ec4e895f5..90233d037 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -345,6 +345,8 @@ class TestDatabase(unittest.TestCase): raise SkipTest( "Retrieving a regex with aggregation requires " "MongoDB >= 2.3.2") + if version.at_least(self.client, (3, 5, 1)): + raise SkipTest("SERVER-24623") db = self.client.pymongo_test db.test.drop() @@ -736,12 +738,18 @@ class TestDatabase(unittest.TestCase): 'count', 'test', maxTimeMS=1) pipeline = [{'$project': {'name': 1, 'count': 1}}] # Database command helper. - db.command('aggregate', 'test', pipeline=pipeline) - self.assertRaises(ExecutionTimeout, db.command, - 'aggregate', 'test', - pipeline=pipeline, maxTimeMS=1) + if not version.at_least(self.client, (3, 5, 1)): + db.command('aggregate', 'test', pipeline=pipeline) + self.assertRaises(ExecutionTimeout, db.command, + 'aggregate', 'test', + pipeline=pipeline, maxTimeMS=1) + else: + db.command('aggregate', 'test', pipeline=pipeline, cursor={}) + self.assertRaises(ExecutionTimeout, db.command, + 'aggregate', 'test', + pipeline=pipeline, cursor={}, maxTimeMS=1) # Collection helper. - db.test.aggregate(pipeline=pipeline) + db.test.aggregate(pipeline=pipeline, cursor={}) self.assertRaises(ExecutionTimeout, db.test.aggregate, pipeline, maxTimeMS=1) finally: diff --git a/test/test_read_preferences.py b/test/test_read_preferences.py index d193d029e..b4f947bbf 100644 --- a/test/test_read_preferences.py +++ b/test/test_read_preferences.py @@ -523,7 +523,8 @@ class TestCommandAndReadPreference(TestReplicaSetClientBase): ('geoSearch', 'test'), ('near', [33, 33]), ('maxDistance', 6), ('search', {'type': 'restaurant'}), ('limit', 30)]))) - if version.at_least(self.c, (2, 1, 0)): + if (version.at_least(self.c, (2, 1, 0)) and + not version.at_least(self.c, (3, 5, 1))): self._test_fn( True, lambda: self.c.pymongo_test.command(SON([ ('aggregate', 'test'), @@ -568,8 +569,8 @@ class TestCommandAndReadPreference(TestReplicaSetClientBase): ]))) def test_aggregate_command_with_out(self): - if not version.at_least(self.c, (2, 5, 2)): - raise SkipTest("Aggregation with $out requires MongoDB >= 2.5.2") + if not version.at_least(self.c, (2, 6, 0)): + raise SkipTest("Aggregation with $out requires MongoDB >= 2.6.0") # Tests aggregate command when pipeline contains $out. self.c.pymongo_test.test.insert({"x": 1, "y": 1}, w=self.w) @@ -584,12 +585,14 @@ class TestCommandAndReadPreference(TestReplicaSetClientBase): warnings.simplefilter("ignore", UserWarning) self._test_fn(False, lambda: self.c.pymongo_test.command( "aggregate", "test", - pipeline=[{"$match": {"x": 1}}, {"$out": "agg_out"}] + pipeline=[{"$match": {"x": 1}}, {"$out": "agg_out"}], + cursor={} )) # Test aggregate when sent through the collection aggregate function. self._test_fn(False, lambda: self.c.pymongo_test.test.aggregate( - [{"$match": {"x": 2}}, {"$out": "agg_out"}] + [{"$match": {"x": 2}}, {"$out": "agg_out"}], + cursor={} )) finally: ctx.exit() @@ -662,7 +665,9 @@ class TestCommandAndReadPreference(TestReplicaSetClientBase): def test_aggregate(self): if version.at_least(self.c, (2, 1, 0)): - self._test_fn(True, lambda: self.c.pymongo_test.test.aggregate([])) + self._test_fn( + True, + lambda: self.c.pymongo_test.test.aggregate([], cursor={})) class TestMovingAverage(unittest.TestCase):