@@ -757,6 +757,8 @@ def test_insert_bypass_document_validation(self):
757757 db = self .db
758758 db .test .drop ()
759759 db .create_collection ("test" , validator = {"a" : {"$exists" : True }})
760+ db_w0 = self .db .client .get_database (
761+ self .db .name , write_concern = WriteConcern (w = 0 ))
760762
761763 # Test insert_one
762764 self .assertRaises (OperationFailure , db .test .insert_one ,
@@ -769,6 +771,9 @@ def test_insert_bypass_document_validation(self):
769771 self .assertTrue (isinstance (result , InsertOneResult ))
770772 self .assertEqual (2 , result .inserted_id )
771773
774+ self .assertRaises (OperationFailure , db_w0 .test .insert_one ,
775+ {"x" : 1 }, bypass_document_validation = True )
776+
772777 # Test insert_many
773778 docs = [{"_id" : i , "x" : 100 - i } for i in range (3 , 100 )]
774779 self .assertRaises (OperationFailure , db .test .insert_many , docs )
@@ -792,12 +797,18 @@ def test_insert_bypass_document_validation(self):
792797 self .assertEqual (1 , db .test .count ({"a" : doc ["a" ]}))
793798 self .assertTrue (result .acknowledged )
794799
800+ self .assertRaises (OperationFailure , db_w0 .test .insert_many ,
801+ [{"x" : 1 }, {"x" : 2 }],
802+ bypass_document_validation = True )
803+
795804 @client_context .require_version_min (3 , 1 , 9 , - 1 )
796805 @client_context .require_no_auth
797806 def test_replace_bypass_document_validation (self ):
798807 db = self .db
799808 db .test .drop ()
800809 db .create_collection ("test" , validator = {"a" : {"$exists" : True }})
810+ db_w0 = self .db .client .get_database (
811+ self .db .name , write_concern = WriteConcern (w = 0 ))
801812
802813 # Test replace_one
803814 db .test .insert_one ({"a" : 101 })
@@ -828,6 +839,9 @@ def test_replace_bypass_document_validation(self):
828839 self .assertEqual (0 , db .test .count ({"x" : 101 }))
829840 self .assertEqual (1 , db .test .count ({"a" : 103 }))
830841
842+ self .assertRaises (OperationFailure , db_w0 .test .replace_one , {"y" : 1 },
843+ {"x" : 1 }, bypass_document_validation = True )
844+
831845 @client_context .require_version_min (3 , 1 , 9 , - 1 )
832846 @client_context .require_no_auth
833847 def test_update_bypass_document_validation (self ):
@@ -836,6 +850,8 @@ def test_update_bypass_document_validation(self):
836850 db .test .insert_one ({"z" : 5 })
837851 db .command (SON ([("collMod" , "test" ),
838852 ("validator" , {"z" : {"$gte" : 0 }})]))
853+ db_w0 = self .db .client .get_database (
854+ self .db .name , write_concern = WriteConcern (w = 0 ))
839855
840856 # Test update_one
841857 self .assertRaises (OperationFailure , db .test .update_one ,
@@ -866,6 +882,9 @@ def test_update_bypass_document_validation(self):
866882 self .assertEqual (0 , db .test .count ({"z" : - 9 }))
867883 self .assertEqual (1 , db .test .count ({"z" : 0 }))
868884
885+ self .assertRaises (OperationFailure , db_w0 .test .update_one , {"y" : 1 },
886+ {"$inc" : {"x" : 1 }}, bypass_document_validation = True )
887+
869888 # Test update_many
870889 db .test .insert_many ([{"z" : i } for i in range (3 , 101 )])
871890 db .test .insert_one ({"y" : 0 },
@@ -899,12 +918,18 @@ def test_update_bypass_document_validation(self):
899918 self .assertEqual (150 , db .test .count ({"z" : {"$gte" : 0 }}))
900919 self .assertEqual (0 , db .test .count ({"z" : {"$lt" : 0 }}))
901920
921+ self .assertRaises (OperationFailure , db_w0 .test .update_many , {"y" : 1 },
922+ {"$inc" : {"x" : 1 }}, bypass_document_validation = True )
923+
902924 @client_context .require_version_min (3 , 1 , 9 , - 1 )
903925 @client_context .require_no_auth
904926 def test_bypass_document_validation_bulk_write (self ):
905927 db = self .db
906928 db .test .drop ()
907929 db .create_collection ("test" , validator = {"a" : {"$gte" : 0 }})
930+ db_w0 = self .db .client .get_database (
931+ self .db .name , write_concern = WriteConcern (w = 0 ))
932+
908933 ops = [InsertOne ({"a" : - 10 }),
909934 InsertOne ({"a" : - 11 }),
910935 InsertOne ({"a" : - 12 }),
@@ -922,6 +947,9 @@ def test_bypass_document_validation_bulk_write(self):
922947 for op in ops :
923948 self .assertRaises (BulkWriteError , db .test .bulk_write , [op ])
924949
950+ self .assertRaises (OperationFailure , db_w0 .test .bulk_write , ops ,
951+ bypass_document_validation = True )
952+
925953 def test_find_by_default_dct (self ):
926954 db = self .db
927955 db .test .insert_one ({'foo' : 'bar' })
0 commit comments