Skip to content

Commit bf369c8

Browse files
Test suite improvements.
1 parent 2314e92 commit bf369c8

10 files changed

+430
-42
lines changed

tests/test_1100_connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ def test_1118(self):
326326
conn = test_env.get_connection()
327327
if test_env.get_client_version() >= (12, 1):
328328
self.assertEqual(conn.ltxid, b"")
329+
self.assertFalse(conn.autocommit)
330+
conn.autocommit = True
331+
self.assertTrue(conn.autocommit)
329332
self.assertIsNone(conn.current_schema)
330333
conn.current_schema = "test_schema"
331334
self.assertEqual(conn.current_schema, "test_schema")

tests/test_2400_pool.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def test_2400(self):
161161
pool = test_env.get_pool()
162162
self.assertEqual(pool.busy, 0)
163163
self.assertEqual(pool.dsn, test_env.get_connect_string())
164+
self.assertEqual(pool.tnsentry, pool.dsn)
164165
if test_env.get_client_version() >= (12, 2):
165166
self.assertEqual(pool.getmode, oracledb.POOL_GETMODE_WAIT)
166167
self.assertTrue(pool.homogeneous)
@@ -174,7 +175,9 @@ def test_2400(self):
174175
):
175176
self.assertEqual(pool.max_sessions_per_shard, 0)
176177
self.assertEqual(pool.min, 1)
177-
if not test_env.get_is_thin():
178+
if test_env.get_is_thin():
179+
self.assertIsNone(pool.name)
180+
else:
178181
self.assertRegex(pool.name, "^OCI:SP:.+")
179182
self.assertEqual(pool.ping_interval, 60)
180183
self.assertEqual(pool.stmtcachesize, oracledb.defaults.stmtcachesize)
@@ -826,7 +829,6 @@ def test_2431(self):
826829
def test_2432(self):
827830
"2432 - test creating a pool invalid params"
828831
with self.assertRaisesFullCode("DPY-2027"):
829-
830832
oracledb.create_pool(params="bad params")
831833

832834
def test_2433(self):
@@ -859,6 +861,13 @@ class MyPool(oracledb.ConnectionPool):
859861
pool = test_env.get_pool(pool_class=MyPool)
860862
self.assertIsInstance(pool, MyPool)
861863

864+
def test_2437(self):
865+
"2437 - test connectiontype with an invalid connection class"
866+
with self.assertRaisesFullCode("DPY-2023"):
867+
test_env.get_pool(connectiontype=oracledb.AsyncConnection)
868+
with self.assertRaisesFullCode("DPY-2023"):
869+
test_env.get_pool(connectiontype=int)
870+
862871

863872
if __name__ == "__main__":
864873
test_env.run_test_cases()

tests/test_3300_soda_database.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,115 @@ def test_3306(self):
154154
bytes_val = str_val.encode()
155155
self.__verify_doc(doc, bytes_val, str_val, val)
156156

157+
def test_3307(self):
158+
"3307 - test creating documents with int scalar value"
159+
soda_db = self.conn.getSodaDatabase()
160+
val = 144
161+
str_val = "144"
162+
bytes_val = b"144"
163+
key = "MyKey"
164+
media_type = "application/json"
165+
doc = soda_db.createDocument(val)
166+
self.__verify_doc(doc, bytes_val, str_val, val)
167+
doc = soda_db.createDocument(val, key)
168+
self.__verify_doc(doc, bytes_val, str_val, val, key)
169+
doc = soda_db.createDocument(val, key, media_type)
170+
self.__verify_doc(doc, bytes_val, str_val, val, key, media_type)
171+
172+
@unittest.skipIf(
173+
test_env.get_client_version() < (23, 4)
174+
and test_env.get_server_version() < (23, 4),
175+
"data types serialized differently",
176+
)
177+
def test_3308(self):
178+
"3308 - test creating documents with float scalar value"
179+
soda_db = self.conn.getSodaDatabase()
180+
val = 12.2
181+
str_val = "12.2"
182+
bytes_val = b"12.2"
183+
decimal_val = decimal.Decimal(str_val)
184+
key = "MyKey"
185+
media_type = "application/json"
186+
doc = soda_db.createDocument(val)
187+
self.__verify_doc(doc, bytes_val, str_val, decimal_val)
188+
doc = soda_db.createDocument(val, key)
189+
self.__verify_doc(doc, bytes_val, str_val, decimal_val, key)
190+
doc = soda_db.createDocument(val, key, media_type)
191+
self.__verify_doc(
192+
doc, bytes_val, str_val, decimal_val, key, media_type
193+
)
194+
195+
@unittest.skipIf(
196+
test_env.get_client_version() < (23, 4)
197+
and test_env.get_server_version() < (23, 4),
198+
"unsupported data types",
199+
)
200+
def test_3309(self):
201+
"3309 - test creating documents with a list"
202+
soda_db = self.conn.getSodaDatabase()
203+
val = [12, "str", b"bytes", [1], {"dict": "3"}]
204+
decimal_val = [
205+
decimal.Decimal("12"),
206+
"str",
207+
b"bytes",
208+
[decimal.Decimal("1")],
209+
{"dict": "3"},
210+
]
211+
str_val = (
212+
"[Decimal('12'), 'str', b'bytes', [Decimal('1')], {'dict': '3'}]"
213+
)
214+
bytes_val = (
215+
b"[Decimal('12'), 'str', b'bytes', [Decimal('1')], {'dict': '3'}]"
216+
)
217+
key = "MyKey"
218+
media_type = "application/json"
219+
doc = soda_db.createDocument(val)
220+
self.__verify_doc(doc, bytes_val, str_val, decimal_val)
221+
doc = soda_db.createDocument(val, key)
222+
self.__verify_doc(doc, bytes_val, str_val, decimal_val, key)
223+
doc = soda_db.createDocument(val, key, media_type)
224+
self.__verify_doc(
225+
doc, bytes_val, str_val, decimal_val, key, media_type
226+
)
227+
228+
@unittest.skipIf(
229+
test_env.get_client_version() < (23, 4)
230+
and test_env.get_server_version() < (23, 4),
231+
"data types serialized differently",
232+
)
233+
def test_3310(self):
234+
"3310 - test creating documents with a boolean scalar value"
235+
soda_db = self.conn.getSodaDatabase()
236+
test_values = [(True, "True", b"True"), (False, "False", b"False")]
237+
key = "MyKey"
238+
media_type = "application/json"
239+
for val, str_val, bytes_val in test_values:
240+
doc = soda_db.createDocument(val)
241+
self.__verify_doc(doc, bytes_val, str_val, val)
242+
doc = soda_db.createDocument(val, key)
243+
self.__verify_doc(doc, bytes_val, str_val, val, key)
244+
doc = soda_db.createDocument(val, key, media_type)
245+
self.__verify_doc(doc, bytes_val, str_val, val, key, media_type)
246+
247+
@unittest.skipIf(
248+
test_env.get_client_version() < (23, 4)
249+
and test_env.get_server_version() < (23, 4),
250+
"data types serialized differently",
251+
)
252+
def test_3311(self):
253+
"3311 - test creating documents with unsupported types"
254+
soda_db = self.conn.getSodaDatabase()
255+
values = [
256+
tuple([144, 2]),
257+
set("144"),
258+
bytearray("omg", "utf-8"),
259+
complex(2j),
260+
range(4),
261+
]
262+
for value in values:
263+
with self.assertRaisesFullCode("DPY-3003"):
264+
soda_db.createDocument(value)
265+
157266

158267
if __name__ == "__main__":
159268
test_env.run_test_cases()

tests/test_3400_soda_collection.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -824,23 +824,15 @@ def test_3438(self):
824824
client_version = test_env.get_client_version()
825825
server_version = test_env.get_server_version()
826826
if client_version >= (23, 4) and server_version >= (23, 4):
827-
id_metadata = {
828-
"type": "id",
829-
"o:length": 24,
830-
"o:preferred_column_name": "DATA$_id",
831-
}
832-
self.assertEqual(data_guide["properties"]["_id"], id_metadata)
827+
self.assertEqual(data_guide["properties"]["_id"]["type"], "id")
833828

834829
values = [
835-
("team", "string", 8),
836-
("created_in", "number", 4),
837-
("area", "string", 16),
830+
("team", "string"),
831+
("created_in", "number"),
832+
("area", "string"),
838833
]
839-
for name, typ, length in values:
834+
for name, typ in values:
840835
self.assertEqual(data_guide["properties"][name]["type"], typ)
841-
self.assertEqual(
842-
data_guide["properties"][name]["o:length"], length
843-
)
844836
self.assertRegex(
845837
data_guide["properties"][name]["o:preferred_column_name"],
846838
f"(JSON_DOCUMENT|DATA)\\${name}",

tests/test_3600_outputtypehandler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def type_handler(cursor, metadata):
4141
return cursor.var(output_type, arraysize=cursor.arraysize)
4242

4343
self.cursor.outputtypehandler = type_handler
44+
self.assertEqual(self.cursor.outputtypehandler, type_handler)
4445
var = self.cursor.var(input_type)
4546
var.setvalue(0, in_value)
4647
self.cursor.execute("select :1 from dual", [var])

tests/test_5500_pool_async.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ class MyPool(oracledb.AsyncConnectionPool):
455455
pool = test_env.get_pool_async(pool_class=MyPool)
456456
self.assertIsInstance(pool, MyPool)
457457

458+
async def test_5527(self):
459+
"5527 - test connectiontype with an invalid connection class"
460+
with self.assertRaisesFullCode("DPY-2023"):
461+
test_env.get_pool_async(connectiontype=oracledb.Connection)
462+
with self.assertRaisesFullCode("DPY-2023"):
463+
test_env.get_pool_async(connectiontype=int)
464+
458465

459466
if __name__ == "__main__":
460467
test_env.run_test_cases()

tests/test_6600_defaults.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def test_6607(self):
102102
params = oracledb.ConnectParams()
103103
self.assertEqual(params.config_dir, temp_dir)
104104

105+
def test_6608(self):
106+
"6608 - test setting defaults.stmtcachesize (ConnectParams)"
107+
with test_env.DefaultsContextManager("stmtcachesize", 50):
108+
params = oracledb.ConnectParams()
109+
self.assertEqual(
110+
params.stmtcachesize, oracledb.defaults.stmtcachesize
111+
)
112+
105113

106114
if __name__ == "__main__":
107115
test_env.run_test_cases()

tests/test_6900_oson.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import unittest
3030

31+
import oracledb
3132
import test_env
3233

3334

@@ -72,6 +73,47 @@ def test_6902(self):
7273
(oson_val,) = self.cursor.fetchone()
7374
self.assertEqual(oson_val, value)
7475

76+
def test_6903(self):
77+
"6903 - test encoding and decoding a value"
78+
value = dict(id=6903, value="string 6903")
79+
out_value = self.conn.decode_oson(self.conn.encode_oson(value))
80+
self.assertEqual(out_value, value)
81+
82+
def test_6904(self):
83+
"6904 - test decoding a non encoded value"
84+
value = b"{'not a previous encoded value': 3}"
85+
with self.assertRaisesFullCode("DPY-5004"):
86+
self.conn.decode_oson(value)
87+
88+
def test_6905(self):
89+
"6905 - test inserting oson inside a lob"
90+
value = dict(id=6905, value="string 6905")
91+
self.cursor.execute("delete from TestOsonCols")
92+
encoded_oson = self.conn.encode_oson(value)
93+
lob = self.conn.createlob(oracledb.DB_TYPE_BLOB, encoded_oson)
94+
self.cursor.execute(
95+
"insert into TestOsonCols values (1, :data)", [lob]
96+
)
97+
self.conn.commit()
98+
self.cursor.execute("select OsonCol from TestOsonCols")
99+
(oson_val,) = self.cursor.fetchone()
100+
self.assertEqual(oson_val, value)
101+
102+
def test_6906(self):
103+
"6906 - test inserting oson as json"
104+
self.cursor.execute("delete from TestOsonCols")
105+
value = dict(id=6906, value="string 6906")
106+
oson = self.conn.encode_oson(value)
107+
self.cursor.setinputsizes(oracledb.DB_TYPE_JSON)
108+
self.cursor.execute(
109+
"insert into TestOsonCols values (1, :data)", [oson]
110+
)
111+
self.conn.commit()
112+
self.cursor.execute("select OsonCol from TestOsonCols")
113+
(oson_val,) = self.cursor.fetchone()
114+
oson_val = self.conn.decode_oson(oson_val)
115+
self.assertEqual(oson_val, value)
116+
75117

76118
if __name__ == "__main__":
77119
test_env.run_test_cases()

0 commit comments

Comments
 (0)