Skip to content

Commit 05a9097

Browse files
Add more tests.
1 parent 438c885 commit 05a9097

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed

test/test_1100_connection.py

+86-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import string
1616
import threading
1717
import time
18+
import unittest
1819

1920
import cx_Oracle as oracledb
2021
import test_env
@@ -488,9 +489,6 @@ def test_1129_threading_single_connection(self):
488489
def test_1130_cancel(self):
489490
"1130 - test connection cancel"
490491
conn = test_env.get_connection()
491-
sleep_proc_name = "dbms_session.sleep" \
492-
if int(conn.version.split(".")[0]) >= 18 \
493-
else "dbms_lock.sleep"
494492
def perform_cancel():
495493
time.sleep(0.1)
496494
conn.cancel()
@@ -499,13 +497,97 @@ def perform_cancel():
499497
try:
500498
with conn.cursor() as cursor:
501499
self.assertRaises(oracledb.OperationalError, cursor.callproc,
502-
sleep_proc_name, [2])
500+
test_env.get_sleep_proc_name(), [2])
503501
finally:
504502
thread.join()
505503
with conn.cursor() as cursor:
506504
cursor.execute("select user from dual")
507505
user, = cursor.fetchone()
508506
self.assertEqual(user, test_env.get_main_user().upper())
509507

508+
def test_1131_change_password_during_connect(self):
509+
"1131 - test changing password during connect"
510+
connection = test_env.get_connection()
511+
if self.is_on_oracle_cloud(connection):
512+
self.skipTest("passwords on Oracle Cloud are strictly controlled")
513+
sys_random = random.SystemRandom()
514+
new_password = "".join(sys_random.choice(string.ascii_letters) \
515+
for i in range(20))
516+
connection = oracledb.connect(dsn=test_env.get_connect_string(),
517+
user=test_env.get_main_user(),
518+
password=test_env.get_main_password(),
519+
newpassword=new_password)
520+
connection = oracledb.connect(dsn=test_env.get_connect_string(),
521+
user=test_env.get_main_user(),
522+
password=new_password)
523+
connection.changepassword(new_password, test_env.get_main_password())
524+
525+
def test_1132_autocommit_during_reexecute(self):
526+
"1132 - test use of autocommit during reexecute"
527+
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
528+
data_to_insert = [
529+
(1, "Test String #1"),
530+
(2, "Test String #2")
531+
]
532+
connection = test_env.get_connection()
533+
cursor = connection.cursor()
534+
other_connection = test_env.get_connection()
535+
other_cursor = other_connection.cursor()
536+
cursor.execute("truncate table TestTempTable")
537+
cursor.execute(sql, data_to_insert[0])
538+
other_cursor.execute("select IntCol, StringCol from TestTempTable")
539+
rows = other_cursor.fetchall()
540+
self.assertEqual(rows, [])
541+
connection.autocommit = True
542+
cursor.execute(sql, data_to_insert[1])
543+
other_cursor.execute("select IntCol, StringCol from TestTempTable")
544+
rows = other_cursor.fetchall()
545+
self.assertEqual(rows, data_to_insert)
546+
547+
def test_1133_current_schema(self):
548+
"1133 - test current_schame is set properly"
549+
conn = test_env.get_connection()
550+
self.assertEqual(conn.current_schema, None)
551+
552+
user = test_env.get_main_user().upper()
553+
proxy_user = test_env.get_proxy_user().upper()
554+
cursor = conn.cursor()
555+
cursor.execute(f'alter session set current_schema={proxy_user}')
556+
self.assertEqual(conn.current_schema, proxy_user)
557+
558+
conn.current_schema = user
559+
self.assertEqual(conn.current_schema, user)
560+
561+
cursor.execute("""
562+
select sys_context('userenv', 'current_schema')
563+
from dual""")
564+
result, = cursor.fetchone()
565+
self.assertEqual(result, user)
566+
567+
def test_1134_dbms_output(self):
568+
"1134 - test dbms_output package"
569+
conn = test_env.get_connection()
570+
cursor = conn.cursor()
571+
test_string = "Testing DBMS_OUTPUT package"
572+
cursor.callproc("dbms_output.enable")
573+
cursor.execute("""
574+
begin
575+
dbms_output.put_line(:val);
576+
end; """, val=test_string)
577+
string_var = cursor.var(str)
578+
number_var = cursor.var(int)
579+
cursor.callproc("dbms_output.get_line", (string_var, number_var))
580+
self.assertEqual(string_var.getvalue(), test_string)
581+
582+
@unittest.skipIf(test_env.get_client_version() < (18, 1),
583+
"unsupported client")
584+
def test_1135_calltimeout(self):
585+
"1135 - test connection call_timeout"
586+
conn = test_env.get_connection()
587+
conn.call_timeout = 500 # milliseconds
588+
self.assertEqual(conn.call_timeout, 500)
589+
self.assertRaises(oracledb.DatabaseError, conn.cursor().callproc,
590+
test_env.get_sleep_proc_name(), [2])
591+
510592
if __name__ == "__main__":
511593
test_env.run_test_cases()

test/test_3400_soda_collection.py

+34
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,39 @@ def test_3413_soda_truncate(self):
301301
self.assertEqual(coll.find().count(), 0)
302302
coll.drop()
303303

304+
def test_3414_soda_hint(self):
305+
"3414 - verify hints are reflected in the executed SQL statement"
306+
soda_db = self.connection.getSodaDatabase()
307+
cursor = self.connection.cursor()
308+
statement = """
309+
SELECT
310+
( SELECT t2.sql_fulltext
311+
FROM v$sql t2
312+
WHERE t2.sql_id = t1.prev_sql_id
313+
AND t2.child_number = t1.prev_child_number
314+
)
315+
FROM v$session t1
316+
WHERE t1.audsid = sys_context('userenv', 'sessionid')"""
317+
coll = soda_db.createCollection("cxoSodaHint")
318+
coll.find().remove()
319+
values_to_insert = [
320+
{"name": "George", "age": 47},
321+
{"name": "Susan", "age": 39},
322+
]
323+
coll.insertOneAndGet(values_to_insert[0], hint="MONITOR")
324+
cursor.execute(statement)
325+
result, = cursor.fetchone()
326+
self.assertTrue('MONITOR' in result.read())
327+
328+
coll.find().hint("MONITOR").getOne().getContent()
329+
cursor.execute(statement)
330+
result, = cursor.fetchone()
331+
self.assertTrue('MONITOR' in result.read())
332+
333+
coll.insertOneAndGet(values_to_insert[1], hint="NO_MONITOR")
334+
cursor.execute(statement)
335+
result, = cursor.fetchone()
336+
self.assertTrue('NO_MONITOR' in result.read())
337+
304338
if __name__ == "__main__":
305339
test_env.run_test_cases()

test/test_env.py

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ def get_proxy_password():
137137
def get_proxy_user():
138138
return get_value("PROXY_USER", "Proxy User Name", DEFAULT_PROXY_USER)
139139

140+
def get_sleep_proc_name():
141+
server_version = get_server_version()
142+
return "dbms_session.sleep" if server_version[0] >= 18 \
143+
else "dbms_lock.sleep"
144+
140145
def get_server_version():
141146
name = "SERVER_VERSION"
142147
value = PARAMETERS.get(name)

0 commit comments

Comments
 (0)