15
15
import string
16
16
import threading
17
17
import time
18
+ import unittest
18
19
19
20
import cx_Oracle as oracledb
20
21
import test_env
@@ -488,9 +489,6 @@ def test_1129_threading_single_connection(self):
488
489
def test_1130_cancel (self ):
489
490
"1130 - test connection cancel"
490
491
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"
494
492
def perform_cancel ():
495
493
time .sleep (0.1 )
496
494
conn .cancel ()
@@ -499,13 +497,97 @@ def perform_cancel():
499
497
try :
500
498
with conn .cursor () as cursor :
501
499
self .assertRaises (oracledb .OperationalError , cursor .callproc ,
502
- sleep_proc_name , [2 ])
500
+ test_env . get_sleep_proc_name () , [2 ])
503
501
finally :
504
502
thread .join ()
505
503
with conn .cursor () as cursor :
506
504
cursor .execute ("select user from dual" )
507
505
user , = cursor .fetchone ()
508
506
self .assertEqual (user , test_env .get_main_user ().upper ())
509
507
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
+
510
592
if __name__ == "__main__" :
511
593
test_env .run_test_cases ()
0 commit comments