Exemplo n.º 1
0
 def test_1122_connection_attributes(self):
     "1122 - test connection attribute values"
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string(),
                                   encoding="ASCII")
     self.assertEqual(connection.maxBytesPerCharacter, 1)
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string(),
                                   encoding="UTF-8")
     self.assertEqual(connection.maxBytesPerCharacter, 4)
     if base.get_client_version() >= (12, 1):
         self.assertEqual(connection.ltxid, b'')
     self.assertEqual(connection.current_schema, None)
     connection.current_schema = "test_schema"
     self.assertEqual(connection.current_schema, "test_schema")
     self.assertEqual(connection.edition, None)
     connection.external_name = "test_external"
     self.assertEqual(connection.external_name, "test_external")
     connection.internal_name = "test_internal"
     self.assertEqual(connection.internal_name, "test_internal")
     connection.stmtcachesize = 30
     self.assertEqual(connection.stmtcachesize, 30)
     self.assertRaises(TypeError, connection.stmtcachesize, 20.5)
     self.assertRaises(TypeError, connection.stmtcachesize, "value")
Exemplo n.º 2
0
 def test_1107_change_password(self):
     "1107 - test changing password"
     connection = base.get_connection()
     if self.is_on_oracle_cloud(connection):
         self.skipTest("passwords on Oracle Cloud are strictly controlled")
     sys_random = random.SystemRandom()
     new_password = "".join(sys_random.choice(string.ascii_letters) \
                    for i in range(20))
     connection.changepassword(base.get_main_password(), new_password)
     cconnection = oracledb.connect(base.get_main_user(), new_password,
                                    base.get_connect_string())
     connection.changepassword(new_password, base.get_main_password())
 def test_2408_heterogenous_without_user(self):
     "2408 - test heterogeneous pool without user and password specified"
     pool = base.get_pool(user="", password="", min=2, max=8, increment=3,
                          getmode=oracledb.SPOOL_ATTRVAL_WAIT,
                          homogeneous=False)
     self.__verify_connection(pool.acquire(base.get_main_user(),
                              base.get_main_password()),
                              base.get_main_user())
     self.__verify_connection(pool.acquire(base.get_proxy_user(),
                              base.get_proxy_password()),
                              base.get_proxy_user())
     user_str = "%s[%s]" % (base.get_main_user(), base.get_proxy_user())
     self.__verify_connection(pool.acquire(user_str,
                              base.get_main_password()),
                              base.get_proxy_user(), base.get_main_user())
 def test_2407_heterogeneous(self):
     "2407 - test heterogeneous pool with user and password specified"
     pool = base.get_pool(min=2, max=8, increment=3, homogeneous=False,
                          getmode=oracledb.SPOOL_ATTRVAL_WAIT)
     self.assertEqual(pool.homogeneous, 0)
     self.__verify_connection(pool.acquire(), base.get_main_user())
     self.__verify_connection(pool.acquire(base.get_main_user(),
                              base.get_main_password()),
                              base.get_main_user())
     self.__verify_connection(pool.acquire(base.get_proxy_user(),
                              base.get_proxy_password()),
                              base.get_proxy_user())
     user_str = "%s[%s]" % (base.get_main_user(), base.get_proxy_user())
     self.__verify_connection(pool.acquire(user_str,
                              base.get_main_password()),
                              base.get_proxy_user(), base.get_main_user())
Exemplo n.º 5
0
 def test_1109_parse_password(self):
     "1109 - test connecting with password containing / and @ symbols"
     connection = base.get_connection()
     if self.is_on_oracle_cloud(connection):
         self.skipTest("passwords on Oracle Cloud are strictly controlled")
     sys_random = random.SystemRandom()
     chars = list(sys_random.choice(string.ascii_letters) for i in range(20))
     chars[4] = "/"
     chars[8] = "@"
     new_password = "".join(chars)
     connection.changepassword(base.get_main_password(), new_password)
     try:
         arg = "%s/%s@%s" % (base.get_main_user(), new_password,
                             base.get_connect_string())
         oracledb.connect(arg)
     finally:
         connection.changepassword(new_password, base.get_main_password())
Exemplo n.º 6
0
 def test_1108_change_password_negative(self):
     "1108 - test changing password to an invalid value"
     connection = base.get_connection()
     if self.is_on_oracle_cloud(connection):
         self.skipTest("passwords on Oracle Cloud are strictly controlled")
     new_password = "******" * 150
     self.assertRaises(oracledb.DatabaseError, connection.changepassword,
             base.get_main_password(), new_password)
Exemplo n.º 7
0
 def test_1110_encodings(self):
     "1110 - connection with only encoding/nencoding specified should work"
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string())
     encoding = connection.encoding
     nencoding = connection.nencoding
     alt_encoding = "ISO-8859-1"
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string(),
                                   encoding=alt_encoding)
     self.assertEqual(connection.encoding, alt_encoding)
     self.assertEqual(connection.nencoding, nencoding)
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string(),
                                   nencoding=alt_encoding)
     self.assertEqual(connection.encoding, encoding)
     self.assertEqual(connection.nencoding, alt_encoding)
Exemplo n.º 8
0
 def test_1105_bad_connect_string(self):
     "1105 - connection to database with bad connect string"
     self.assertRaises(oracledb.DatabaseError, oracledb.connect,
                       base.get_main_user())
     self.assertRaises(oracledb.DatabaseError, oracledb.connect,
                       base.get_main_user() + "@" + \
                       base.get_connect_string())
     self.assertRaises(oracledb.DatabaseError, oracledb.connect,
                       base.get_main_user() + "@" + \
                       base.get_connect_string() + "/" + \
                       base.get_main_password())
Exemplo n.º 9
0
 def test_1111_different_encodings(self):
     "1111 - different encodings can be specified for encoding/nencoding"
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string(),
                                   encoding="UTF-8", nencoding="UTF-16")
     value = "\u03b4\u4e2a"
     cursor = connection.cursor()
     nchar_var = cursor.var(oracledb.DB_TYPE_NVARCHAR, 100)
     nchar_var.setvalue(0, value)
     cursor.execute("select :value from dual", value=nchar_var)
     result, = cursor.fetchone()
     self.assertEqual(result, value)
Exemplo n.º 10
0
 def test_1915_nclob_different_encodings(self):
     "1915 - test binding and fetching NCLOB data (different encodings)"
     connection = oracledb.connect(base.get_main_user(),
                                   base.get_main_password(),
                                   base.get_connect_string(),
                                   encoding="UTF-8", nencoding="UTF-16")
     value = "\u03b4\u4e2a"
     cursor = connection.cursor()
     cursor.execute("truncate table TestNCLOBs")
     cursor.setinputsizes(val=oracledb.DB_TYPE_NVARCHAR)
     cursor.execute("insert into TestNCLOBs values (1, :val)", val=value)
     cursor.execute("select NCLOBCol from TestNCLOBs")
     nclob, = cursor.fetchone()
     cursor.setinputsizes(val=oracledb.DB_TYPE_NVARCHAR)
     cursor.execute("update TestNCLOBs set NCLOBCol = :val",
                    val=nclob.read() + value)
     cursor.execute("select NCLOBCol from TestNCLOBs")
     nclob, = cursor.fetchone()
     self.assertEqual(nclob.read(), value + value)
Exemplo n.º 11
0
 def test_1102_app_context_negative(self):
     "1102 - test invalid use of application context"
     self.assertRaises(TypeError, oracledb.connect, base.get_main_user(),
                       base.get_main_password(), base.get_connect_string(),
                       appcontext=[('userenv', 'action')])
Exemplo n.º 12
0
 def test_1115_single_arg(self):
     "1115 - connection to database with user, password, DSN together"
     arg = "%s/%s@%s" % (base.get_main_user(), base.get_main_password(),
                         base.get_connect_string())
     connection = oracledb.connect(arg)
     self.__verify_args(connection)
Exemplo n.º 13
0
 def test_1106_bad_password(self):
     "1106 - connection to database with bad password"
     self.assertRaises(oracledb.DatabaseError, oracledb.connect,
                       base.get_main_user(), base.get_main_password() + "X",
                       base.get_connect_string())
Exemplo n.º 14
0
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# SetupTest.py
#
# Creates users and populates their schemas with the tables and packages
# necessary for the cx_Oracle test suite.
#------------------------------------------------------------------------------

import cx_Oracle

import base
import DropTest

# connect as administrative user (usually SYSTEM or ADMIN)
conn = cx_Oracle.connect(base.get_admin_connect_string())

# drop existing users and editions, if applicable
DropTest.drop_tests(conn)

# create test schemas
print("Creating test schemas...")
base.run_sql_script(conn,
                    "SetupTest",
                    main_user=base.get_main_user(),
                    main_password=base.get_main_password(),
                    proxy_user=base.get_proxy_user(),
                    proxy_password=base.get_proxy_password())
print("Done.")