From e3c58c0325a10f8a4abde14833dab02672ea45ae Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Wed, 28 Jun 2017 15:11:44 -0700 Subject: [PATCH] PYTHON-1291 Skip *_with_invalid_keys tests against >= 3.5.8. --- test/test_collection.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_collection.py b/test/test_collection.py index 79e6c83db..02aa70ee4 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -1014,6 +1014,8 @@ class TestCollection(unittest.TestCase): {'_id': 'explicit_id', 'hello': 'world'}) def test_save_with_invalid_key(self): + if version.at_least(self.db.connection, (3, 5, 8)): + raise SkipTest("MongoDB >= 3.5.8 allows dotted fields in updates") self.db.drop_collection("test") self.assertTrue(self.db.test.insert({"hello": "world"})) doc = self.db.test.find_one() @@ -1307,6 +1309,8 @@ class TestCollection(unittest.TestCase): {"$inc": {"x": 2}})["n"]) def test_update_with_invalid_keys(self): + if version.at_least(self.db.connection, (3, 5, 8)): + raise SkipTest("MongoDB >= 3.5.8 allows dotted fields in updates") self.db.drop_collection("test") self.assertTrue(self.db.test.insert({"hello": "world"})) doc = self.db.test.find_one() @@ -1326,6 +1330,14 @@ class TestCollection(unittest.TestCase): # Check that the last two ops didn't actually modify anything self.assertTrue('a.b' not in self.db.test.find_one()) + def test_update_check_keys(self): + self.db.drop_collection("test") + self.assertTrue(self.db.test.insert({"hello": "world"})) + + expected = InvalidDocument + if version.at_least(self.client, (2, 5, 4, -1)): + expected = OperationFailure + # Modify shouldn't check keys... self.assertTrue(self.db.test.update({"hello": "world"}, {"$set": {"foo.bar": "baz"}}, @@ -2862,6 +2874,8 @@ class TestCollection(unittest.TestCase): def test_backport_update_with_invalid_keys(self): + if version.at_least(self.db.connection, (3, 5, 8)): + raise SkipTest("MongoDB >= 3.5.8 allows dotted fields in updates") self.db.drop_collection("test") self.assertTrue(self.db.test.insert_one({"hello": "world"})) doc = self.db.test.find_one() @@ -2881,6 +2895,13 @@ class TestCollection(unittest.TestCase): # Check that the last two ops didn't actually modify anything self.assertTrue('a.b' not in self.db.test.find_one()) + def test_backport_update_check_keys(self): + self.db.drop_collection("test") + self.assertTrue(self.db.test.insert_one({"hello": "world"})) + + expected = InvalidDocument + if version.at_least(self.client, (2, 5, 4, -1)): + expected = OperationFailure # Modify shouldn't check keys... self.assertTrue(self.db.test.update_one({"hello": "world"}, {"$set": {"foo.bar": "baz"}},