Skip to content

Commit e8b5e23

Browse files
Tweaks to ensure that test suite can run cleanly against cloud
databases.
1 parent 5aa7aa9 commit e8b5e23

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

tests/create_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@
4747
main_password=test_env.get_main_password(),
4848
proxy_user=test_env.get_proxy_user(),
4949
proxy_password=test_env.get_proxy_password())
50+
if test_env.is_on_oracle_cloud(conn):
51+
test_env.run_sql_script(conn, "create_schema_cloud",
52+
main_user=test_env.get_main_user())
5053
print("Done.")

tests/sql/create_schema_cloud.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*-----------------------------------------------------------------------------
2+
* Copyright (c) 2022, Oracle and/or its affiliates.
3+
*
4+
* This software is dual-licensed to you under the Universal Permissive License
5+
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
6+
* 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
* either license.*
8+
*
9+
* If you elect to accept the software under the Apache License, Version 2.0,
10+
* the following applies:
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* https://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*---------------------------------------------------------------------------*/
24+
25+
/*-----------------------------------------------------------------------------
26+
* create_schema_cloud.sql
27+
*
28+
* Performs the actual work of creating and populating the schemas with the
29+
* database objects used by the python-oracledb test suite. This script is
30+
* specific to Oracle Cloud and is only executed when being run against the
31+
* Oracle Cloud, after the main script (create_schema.sql) is run. It is
32+
* executed by the Python script create_schema.py.
33+
*---------------------------------------------------------------------------*/
34+
35+
grant select on v$session to &main_user
36+
/

tests/test_2700_aq.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ def test_2719_recipients_list(self):
469469

470470
def test_2720_aq_notification(self):
471471
"2720 - verify msgid of aq message which spawned notification "
472+
if self.is_on_oracle_cloud(self.connection):
473+
self.skipTest("AQ notification not supported on the cloud")
472474
queue = self.get_and_clear_queue(self.book_queue_name,
473475
self.book_type_name)
474476
condition = threading.Condition()

tests/test_env.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ def get_admin_connection():
104104
admin_user = get_value("ADMIN_USER", "Administrative user", "admin")
105105
admin_password = get_value("ADMIN_PASSWORD", f"Password for {admin_user}",
106106
password=True)
107-
return oracledb.connect(dsn=get_connect_string(),
108-
params=get_connect_params(),
107+
params = get_connect_params()
108+
if admin_user and admin_user.upper() == "SYS":
109+
params = params.copy()
110+
params.set(mode=oracledb.AUTH_MODE_SYSDBA)
111+
return oracledb.connect(dsn=get_connect_string(), params=params,
109112
user=admin_user, password=admin_password)
110113

111114
def get_charset_ratios():
@@ -217,6 +220,17 @@ def get_external_user():
217220
if not get_is_thin():
218221
return get_value("EXTERNAL_USER", "External User")
219222

223+
def is_on_oracle_cloud(connection):
224+
server = get_server_version()
225+
if server < (18, 0):
226+
return False
227+
cursor = connection.cursor()
228+
cursor.execute("""
229+
select sys_context('userenv', 'cloud_service')
230+
from dual""")
231+
service_name, = cursor.fetchone()
232+
return service_name is not None
233+
220234
def run_sql_script(conn, script_name, **kwargs):
221235
statement_parts = []
222236
cursor = conn.cursor()
@@ -377,17 +391,9 @@ def get_soda_database(self, minclient=(18, 3), minserver=(18, 0),
377391
return self.connection.getSodaDatabase()
378392

379393
def is_on_oracle_cloud(self, connection=None):
380-
server = get_server_version()
381-
if server < (18, 0):
382-
return False
383394
if connection is None:
384395
connection = self.connection
385-
cursor = connection.cursor()
386-
cursor.execute("""
387-
select sys_context('userenv', 'cloud_service')
388-
from dual""")
389-
service_name, = cursor.fetchone()
390-
return service_name is not None
396+
return is_on_oracle_cloud(connection)
391397

392398
def setUp(self):
393399
if self.requires_connection:

0 commit comments

Comments
 (0)