Skip to content

Commit 791c399

Browse files
Added more tests.
1 parent ae24313 commit 791c399

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

tests/test_1100_connection.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,31 @@ def test_1152(self):
890890
(fetched_value,) = cursor.fetchone()
891891
self.assertEqual(conn.serial_num, fetched_value)
892892

893+
@unittest.skipUnless(
894+
test_env.get_is_thin(),
895+
"thick mode doesn't support registered protocols",
896+
)
897+
def test_1153(self):
898+
"1153 - test passed params in hook with standalone connection"
899+
sdu = 4096
900+
params = test_env.get_connect_params()
901+
protocol = "proto-test"
902+
orig_connect_string = test_env.get_connect_string()
903+
connect_string = f"{protocol}://{orig_connect_string}"
904+
905+
def hook(passed_protocol, passed_protocol_arg, passed_params):
906+
self.assertEqual(passed_protocol, protocol)
907+
self.assertEqual(passed_protocol_arg, orig_connect_string)
908+
passed_params.parse_connect_string(passed_protocol_arg)
909+
passed_params.set(sdu=sdu)
910+
911+
try:
912+
oracledb.register_protocol(protocol, hook)
913+
oracledb.connect(dsn=connect_string, params=params)
914+
self.assertEqual(params.sdu, sdu)
915+
finally:
916+
oracledb.register_protocol(protocol, None)
917+
893918

894919
if __name__ == "__main__":
895920
test_env.run_test_cases()

tests/test_2400_pool.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,34 @@ def test_2446(self):
951951
)
952952
self.__verify_create_arg("driver_name", "newdriver", sql)
953953

954+
@unittest.skipUnless(
955+
test_env.get_is_thin(),
956+
"thick mode doesn't support registered protocols",
957+
)
958+
def test_2447(self):
959+
"2447 - test register_parameter with pooled connection"
960+
sdu = 4096
961+
params = test_env.get_pool_params()
962+
protocol = "proto-test"
963+
orig_connect_string = test_env.get_connect_string()
964+
connect_string = f"{protocol}://{orig_connect_string}"
965+
966+
def hook(passed_protocol, passed_protocol_arg, passed_params):
967+
self.assertEqual(passed_protocol, protocol)
968+
self.assertEqual(passed_protocol_arg, orig_connect_string)
969+
passed_params.parse_connect_string(passed_protocol_arg)
970+
passed_params.set(sdu=sdu)
971+
972+
try:
973+
oracledb.register_protocol(protocol, hook)
974+
pool = oracledb.create_pool(dsn=connect_string, params=params)
975+
self.assertEqual(params.sdu, sdu)
976+
with pool.acquire():
977+
pass
978+
pool.close()
979+
finally:
980+
oracledb.register_protocol(protocol, None)
981+
954982

955983
if __name__ == "__main__":
956984
test_env.run_test_cases()

tests/test_5300_connection_async.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,27 @@ async def test_5352(self):
669669
(fetched_value,) = await cursor.fetchone()
670670
self.assertEqual(conn.serial_num, fetched_value)
671671

672+
async def test_5353(self):
673+
"5353 - test passed params in hook with standalone connection"
674+
sdu = 4096
675+
params = test_env.get_connect_params()
676+
protocol = "proto-test"
677+
orig_connect_string = test_env.get_connect_string()
678+
connect_string = f"{protocol}://{orig_connect_string}"
679+
680+
def hook(passed_protocol, passed_protocol_arg, passed_params):
681+
self.assertEqual(passed_protocol, protocol)
682+
self.assertEqual(passed_protocol_arg, orig_connect_string)
683+
passed_params.parse_connect_string(passed_protocol_arg)
684+
passed_params.set(sdu=sdu)
685+
686+
try:
687+
oracledb.register_protocol(protocol, hook)
688+
await oracledb.connect_async(dsn=connect_string, params=params)
689+
self.assertEqual(params.sdu, sdu)
690+
finally:
691+
oracledb.register_protocol(protocol, None)
692+
672693

673694
if __name__ == "__main__":
674695
test_env.run_test_cases()

tests/test_5500_pool_async.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,32 @@ async def test_5534(self):
555555
)
556556
await self.__verify_create_arg("driver_name", "newdriver", sql)
557557

558+
async def test_5535(self):
559+
"5535 - test register_parameter with pooled connection"
560+
sdu = 4096
561+
params = test_env.get_pool_params()
562+
protocol = "proto-test"
563+
orig_connect_string = test_env.get_connect_string()
564+
connect_string = f"{protocol}://{orig_connect_string}"
565+
566+
def hook(passed_protocol, passed_protocol_arg, passed_params):
567+
self.assertEqual(passed_protocol, protocol)
568+
self.assertEqual(passed_protocol_arg, orig_connect_string)
569+
passed_params.parse_connect_string(passed_protocol_arg)
570+
passed_params.set(sdu=sdu)
571+
572+
try:
573+
oracledb.register_protocol(protocol, hook)
574+
pool = oracledb.create_pool_async(
575+
dsn=connect_string, params=params
576+
)
577+
self.assertEqual(params.sdu, sdu)
578+
async with pool.acquire():
579+
pass
580+
await pool.close()
581+
finally:
582+
oracledb.register_protocol(protocol, None)
583+
558584

559585
if __name__ == "__main__":
560586
test_env.run_test_cases()

0 commit comments

Comments
 (0)