@@ -752,6 +752,92 @@ def test_3432_drop_empty_mapped_collection(self):
752752 self .assertTrue (mapped_coll .drop ())
753753 self .assertFalse (original_coll .drop ())
754754
755+ def test_3433_replace_one_returns (self ):
756+ "3433 - test that replaceOne() returns a correct boolean"
757+ soda_db = self .get_soda_database ()
758+ coll = soda_db .createCollection ("TestReplaceDocReturns" )
759+ coll .find ().remove ()
760+ doc = coll .insertOneAndGet ({"address" : {"city" : "Sydney" }})
761+
762+ new_content = {"address" : {"city" : "Melbourne" }}
763+ self .assertTrue (coll .find ().key (doc .key ).replaceOne (new_content ))
764+
765+ unregistered_key = "DB4A2628F1E0985C891F3F4836"
766+ self .assertFalse (
767+ coll .find ().key (unregistered_key ).replaceOne (new_content )
768+ )
769+ self .conn .commit ()
770+ coll .drop ()
771+
772+ def test_3434_replace_one_and_get_negative (self ):
773+ "3434 - replaceOne() and replaceOneAndGet() with invalid scenarios"
774+ conn = test_env .get_connection ()
775+ soda_db = conn .getSodaDatabase ()
776+ coll = soda_db .createCollection ("TestReplaceOneNegative" )
777+ coll .find ().remove ()
778+ coll .insertMany ([{"Wisdom" : 1.7 } for d in range (2 )])
779+ keys = [d .key for d in coll .find ().getDocuments ()]
780+ self .assertRaisesRegex (
781+ oracledb .DatabaseError ,
782+ "^ORA-40734:" ,
783+ coll .find ().keys (keys ).replaceOne ,
784+ {"data" : "new" },
785+ )
786+ self .assertRaisesRegex (
787+ oracledb .DatabaseError ,
788+ "^ORA-40734:" ,
789+ coll .find ().keys (keys ).replaceOneAndGet ,
790+ {"data" : "new" },
791+ )
792+
793+ def test_3435_write_read_only_coll_negative (self ):
794+ "3435 - test writting a read-only collection"
795+ soda_db = self .get_soda_database ()
796+ metadata = {
797+ "readOnly" : True ,
798+ }
799+ coll = soda_db .createCollection ("TestCollReadOnly" , metadata )
800+
801+ methods = [
802+ coll .insertOne ,
803+ coll .insertOneAndGet ,
804+ coll .insertMany ,
805+ coll .insertManyAndGet ,
806+ coll .save ,
807+ coll .saveAndGet ,
808+ ]
809+ for method in methods :
810+ with self .subTest (method = method ):
811+ self .assertRaisesRegex (
812+ oracledb .DatabaseError ,
813+ "^ORA-40663:" ,
814+ method ,
815+ {"Song 1" : "No end" },
816+ )
817+
818+ def test_3436_create_collection_same_metadata (self ):
819+ "3436 - createCollection() with the same name and metadata"
820+ soda_db = self .get_soda_database ()
821+ coll_name = "TestCollSameMetadata"
822+ coll1 = soda_db .createCollection (coll_name , {"readOnly" : True })
823+ coll2 = soda_db .createCollection (coll_name , {"readOnly" : True })
824+ self .assertTrue (coll1 .drop ())
825+ self .assertFalse (coll2 .drop ())
826+
827+ def test_3437_create_collection_different_metadata (self ):
828+ "3437 - createCollection() with the same name but different metadata"
829+ soda_db = self .get_soda_database ()
830+ coll_name = "TestCollDifferentMetadata"
831+ coll = soda_db .createCollection (coll_name )
832+ with self .assertRaisesRegex (oracledb .DatabaseError , "^ORA-40669:" ):
833+ soda_db .createCollection (coll_name , {"readOnly" : False })
834+ coll .drop ()
835+
836+ coll = soda_db .createCollection (coll_name , {"readOnly" : True })
837+ with self .assertRaisesRegex (oracledb .DatabaseError , "^ORA-40669:" ):
838+ soda_db .createCollection (coll_name , {"readOnly" : False })
839+ coll .drop ()
840+
755841
756842if __name__ == "__main__" :
757843 test_env .run_test_cases ()
0 commit comments