Skip to content

Commit 7a9059c

Browse files
Various test improvements.
1 parent 151f352 commit 7a9059c

14 files changed

+253
-211
lines changed

tests/sql/create_schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ grant
5656
create view,
5757
select any dictionary,
5858
change notification,
59-
unlimited tablespace
59+
unlimited tablespace,
60+
ctxapp
6061
to &main_user
6162
/
6263

tests/test_1000_module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828

2929
import datetime
30+
import unittest
3031

3132
import oracledb
3233
import test_env
@@ -187,6 +188,12 @@ def test_1006(self):
187188
)
188189
self.assertIs(oracledb.version, oracledb.__version__)
189190

191+
@unittest.skipUnless(test_env.get_is_thin(), "not relevant for thick mode")
192+
def test_1007(self):
193+
"1007 - test clientversion() fails without init_oracle_client()"
194+
with self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2021:"):
195+
oracledb.clientversion()
196+
190197

191198
if __name__ == "__main__":
192199
test_env.run_test_cases()

tests/test_2300_object_var.py

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -430,25 +430,17 @@ def test_2307(self):
430430
def test_2308(self):
431431
"2308 - test trying to find an object type that does not exist"
432432
self.assertRaises(TypeError, self.conn.gettype, 2)
433-
self.assertRaisesRegex(
434-
oracledb.DatabaseError,
435-
"^DPY-2035:",
436-
self.conn.gettype,
437-
"A TYPE THAT DOES NOT EXIST",
438-
)
433+
with self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-2035:"):
434+
self.conn.gettype("A TYPE THAT DOES NOT EXIST")
439435

440436
def test_2309(self):
441437
"2309 - test appending an object of the wrong type to a collection"
442438
collection_obj_type = self.conn.gettype("UDT_OBJECTARRAY")
443439
collection_obj = collection_obj_type.newobject()
444440
array_obj_type = self.conn.gettype("UDT_ARRAY")
445441
array_obj = array_obj_type.newobject()
446-
self.assertRaisesRegex(
447-
oracledb.DatabaseError,
448-
"^DPY-2008:",
449-
collection_obj.append,
450-
array_obj,
451-
)
442+
with self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-2008:"):
443+
collection_obj.append(array_obj)
452444

453445
def test_2310(self):
454446
"2310 - test that referencing a sub object affects the parent object"
@@ -487,14 +479,8 @@ def test_2312(self):
487479
obj = obj_type.newobject()
488480
wrong_obj_type = self.conn.gettype("UDT_OBJECTARRAY")
489481
wrong_obj = wrong_obj_type.newobject()
490-
self.assertRaisesRegex(
491-
oracledb.DatabaseError,
492-
"^DPY-2008:",
493-
setattr,
494-
obj,
495-
"SUBOBJECTVALUE",
496-
wrong_obj,
497-
)
482+
with self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-2008:"):
483+
setattr(obj, "SUBOBJECTVALUE", wrong_obj)
498484

499485
def test_2313(self):
500486
"2313 - test setting value of object variable to wrong object type"
@@ -569,12 +555,8 @@ def test_2317(self):
569555

570556
def test_2318(self):
571557
"2318 - test creating an object variable without a type name"
572-
self.assertRaisesRegex(
573-
oracledb.DatabaseError,
574-
"^DPY-2037:",
575-
self.cursor.var,
576-
oracledb.DB_TYPE_OBJECT,
577-
)
558+
with self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-2037:"):
559+
self.cursor.var(oracledb.DB_TYPE_OBJECT)
578560

579561
def test_2319(self):
580562
"2319 - test getting an empty collection as a dictionary"
@@ -711,21 +693,20 @@ def test_2330(self):
711693
expected_str = f"^<oracledb.DbObject {fqn} at 0x.+>$"
712694
self.assertRegex(repr(obj), expected_str)
713695

696+
# object of a package
697+
typ = self.conn.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
698+
obj = typ.newobject()
699+
fqn = f"{typ.schema}.{typ.package_name}.{typ.name}"
700+
expected_str = f"^<oracledb.DbObject {fqn} at 0x.+>$"
701+
self.assertRegex(repr(obj), expected_str)
702+
714703
def test_2331(self):
715704
"2331 - test creating an object with invalid data type"
716705
type_obj = self.conn.gettype("UDT_ARRAY")
717-
self.assertRaisesRegex(
718-
oracledb.NotSupportedError,
719-
"^DPY-3013:",
720-
type_obj.newobject,
721-
[490, "not a number"],
722-
)
723-
self.assertRaisesRegex(
724-
oracledb.NotSupportedError,
725-
"^DPY-3013:",
726-
type_obj,
727-
[71, "not a number"],
728-
)
706+
with self.assertRaisesRegex(oracledb.NotSupportedError, "^DPY-3013:"):
707+
type_obj.newobject([490, "not a number"])
708+
with self.assertRaisesRegex(oracledb.NotSupportedError, "^DPY-3013:"):
709+
type_obj([71, "not a number"])
729710

730711
def test_2332(self):
731712
"2332 - test getting an invalid attribute name from an object"
@@ -749,14 +730,10 @@ def test_2333(self):
749730
value = "A" * max_size
750731
setattr(obj, attr_name, value)
751732
value += "X"
752-
self.assertRaisesRegex(
753-
oracledb.ProgrammingError,
754-
"^DPY-2043:",
755-
setattr,
756-
obj,
757-
attr_name,
758-
value,
759-
)
733+
with self.assertRaisesRegex(
734+
oracledb.ProgrammingError, "^DPY-2043:"
735+
):
736+
setattr(obj, attr_name, value)
760737

761738
def test_2334(self):
762739
"2334 - test validating a string element value"
@@ -767,20 +744,23 @@ def test_2334(self):
767744
oracledb.ProgrammingError, "^DPY-2044:", obj.append, "A" * 101
768745
)
769746
obj.append("B" * 100)
770-
self.assertRaisesRegex(
771-
oracledb.ProgrammingError,
772-
"^DPY-2044:",
773-
obj.setelement,
774-
2,
775-
"C" * 101,
776-
)
747+
with self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2044:"):
748+
obj.setelement(2, "C" * 101)
777749

778750
def test_2335(self):
779751
"2335 - test validating a string attribute with null value"
780752
typ = self.conn.gettype("UDT_OBJECT")
781753
obj = typ.newobject()
782754
obj.STRINGVALUE = None
783755

756+
def test_2336(self):
757+
"2336 - test initializing (with a sequence) a non collection obj"
758+
obj_type = self.conn.gettype("UDT_OBJECT")
759+
with self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2036:"):
760+
obj_type.newobject([1, 2])
761+
with self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2036:"):
762+
obj_type([3, 4])
763+
784764

785765
if __name__ == "__main__":
786766
test_env.run_test_cases()

tests/test_2400_pool.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,15 @@ class MyConnection(oracledb.Connection):
879879
with pool.acquire() as conn:
880880
self.assertIsInstance(conn, MyConnection)
881881

882+
def test_2436(self):
883+
"2436 - test creating a pool with a subclassed pool type"
884+
885+
class MyPool(oracledb.ConnectionPool):
886+
pass
887+
888+
pool = test_env.get_pool(pool_class=MyPool)
889+
self.assertIsInstance(pool, MyPool)
890+
882891

883892
if __name__ == "__main__":
884893
test_env.run_test_cases()

tests/test_2700_aq.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def test_2714(self):
394394
queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE
395395
transformation_str = f"{self.conn.username}.transform2"
396396
queue.deqoptions.transformation = transformation_str
397-
self.assertEqual(queue.deqOptions.transformation, transformation_str)
397+
self.assertEqual(queue.deqoptions.transformation, transformation_str)
398398
queue.deqoptions.wait = oracledb.DEQ_NO_WAIT
399399
props = queue.deqone()
400400
self.assertEqual(props.payload.PRICE, expected_price)
@@ -722,6 +722,20 @@ def test_2733(self):
722722
queue = self.conn.queue("TEST_RAW_QUEUE")
723723
self.assertIsNone(queue.payload_type)
724724

725+
def test_2734(self):
726+
"2734 - test deprecated attributes (enqOptions, deqOptions)"
727+
queue = self.get_and_clear_queue("TEST_RAW_QUEUE")
728+
self.assertEqual(queue.enqOptions, queue.enqoptions)
729+
self.assertEqual(queue.deqOptions, queue.deqoptions)
730+
731+
def test_2735(self):
732+
"2735 - test deprecated AQ methods (enqOne, deqOne)"
733+
value = b"Test 2734"
734+
queue = self.get_and_clear_queue("TEST_RAW_QUEUE")
735+
queue.enqOne(self.conn.msgproperties(value))
736+
props = queue.deqOne()
737+
self.assertEqual(props.payload, value)
738+
725739

726740
if __name__ == "__main__":
727741
test_env.run_test_cases()

tests/test_2800_bulk_aq.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ def test_2809(self):
213213
self.assertRaises(TypeError, queue.enqmany, ["Not", "msgproperties"])
214214
self.assertRaises(TypeError, queue.deqmany, "5")
215215

216+
def test_2810(self):
217+
"2810 - test deprecated AQ methods (enqMany, deqMany)"
218+
queue = self.get_and_clear_queue(RAW_QUEUE_NAME)
219+
data = [b"labrador", b"schnauzer", b"shih tzu"]
220+
queue.enqMany([self.conn.msgproperties(d) for d in data])
221+
props = queue.deqMany(len(data) + 1)
222+
dequeued_data = [p.payload for p in props]
223+
self.assertEqual(dequeued_data, data)
224+
216225

217226
if __name__ == "__main__":
218227
test_env.run_test_cases()

tests/test_3300_soda_database.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
test_env.skip_soda_tests(), "unsupported client/server combination"
3838
)
3939
class TestCase(test_env.BaseTestCase):
40-
def __drop_existing_collections(self, soda_db):
41-
for name in soda_db.getCollectionNames():
42-
soda_db.openCollection(name).drop()
43-
4440
def __verify_doc(
4541
self,
4642
doc,
@@ -63,7 +59,7 @@ def __verify_doc(
6359

6460
def test_3300(self):
6561
"3300 - test creating documents with JSON data"
66-
soda_db = self.conn.getSodaDatabase()
62+
soda_db = self.get_soda_database()
6763
val = {"testKey1": "testValue1", "testKey2": "testValue2"}
6864
str_val = json.dumps(val)
6965
bytes_val = str_val.encode()
@@ -78,7 +74,7 @@ def test_3300(self):
7874

7975
def test_3301(self):
8076
"3301 - test creating documents with raw data"
81-
soda_db = self.conn.getSodaDatabase()
77+
soda_db = self.get_soda_database()
8278
val = b"<html/>"
8379
key = "MyRawKey"
8480
media_type = "text/html"
@@ -91,8 +87,7 @@ def test_3301(self):
9187

9288
def test_3302(self):
9389
"3302 - test getting collection names from the database"
94-
soda_db = self.conn.getSodaDatabase()
95-
self.__drop_existing_collections(soda_db)
90+
soda_db = self.get_soda_database()
9691
self.assertEqual(soda_db.getCollectionNames(), [])
9792
names = ["zCol", "dCol", "sCol", "aCol", "gCol"]
9893
sorted_names = list(sorted(names))
@@ -109,25 +104,26 @@ def test_3302(self):
109104

110105
def test_3303(self):
111106
"3303 - test opening a collection"
112-
soda_db = self.conn.getSodaDatabase()
113-
self.__drop_existing_collections(soda_db)
107+
soda_db = self.get_soda_database()
114108
coll = soda_db.openCollection("CollectionThatDoesNotExist")
115109
self.assertIsNone(coll)
116110
created_coll = soda_db.createCollection("TestOpenCollection")
117111
coll = soda_db.openCollection(created_coll.name)
118112
self.assertEqual(coll.name, created_coll.name)
119-
coll.drop()
120113

121114
def test_3304(self):
122115
"3304 - test SodaDatabase repr() and str()"
123-
conn = test_env.get_connection()
124-
soda_db = conn.getSodaDatabase()
125-
self.assertEqual(repr(soda_db), f"<oracledb.SodaDatabase on {conn}>")
126-
self.assertEqual(str(soda_db), f"<oracledb.SodaDatabase on {conn}>")
116+
soda_db = self.get_soda_database()
117+
self.assertEqual(
118+
repr(soda_db), f"<oracledb.SodaDatabase on {self.conn}>"
119+
)
120+
self.assertEqual(
121+
str(soda_db), f"<oracledb.SodaDatabase on {self.conn}>"
122+
)
127123

128124
def test_3305(self):
129125
"3305 - test negative cases for SODA database methods"
130-
soda_db = self.conn.getSodaDatabase()
126+
soda_db = self.get_soda_database()
131127
self.assertRaises(TypeError, soda_db.createCollection)
132128
self.assertRaises(TypeError, soda_db.createCollection, 1)
133129
self.assertRaisesRegex(

0 commit comments

Comments
 (0)