- Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathtest_6800_error_async.py
226 lines (210 loc) · 8.17 KB
/
test_6800_error_async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# -----------------------------------------------------------------------------
# Copyright (c) 2023, 2025, Oracle and/or its affiliates.
#
# This software is dual-licensed to you under the Universal Permissive License
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
# 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
# either license.
#
# If you elect to accept the software under the Apache License, Version 2.0,
# the following applies:
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
"""
6800 - Module for testing error objects with asyncio
"""
importpickle
importunittest
importoracledb
importtest_env
@unittest.skipUnless(
test_env.get_is_thin(), "asyncio not supported in thick mode"
)
classTestCase(test_env.BaseAsyncTestCase):
asyncdeftest_6800(self):
"6800 - test parse error returns offset correctly"
withself.assertRaises(oracledb.Error) ascm:
awaitself.cursor.execute("begin t_Missing := 5; end;")
(error_obj,) =cm.exception.args
self.assertEqual(error_obj.full_code, "ORA-06550")
self.assertEqual(error_obj.offset, 6)
asyncdeftest_6801(self):
"6801 - test picking/unpickling an error object"
withself.assertRaises(oracledb.Error) ascm:
awaitself.cursor.execute(
"""
begin
raise_application_error(-20101, 'Test!');
end;
"""
)
(error_obj,) =cm.exception.args
self.assertIsInstance(error_obj, oracledb._Error)
self.assertIn("Test!", error_obj.message)
self.assertEqual(error_obj.code, 20101)
self.assertEqual(error_obj.offset, 0)
self.assertIsInstance(error_obj.isrecoverable, bool)
self.assertFalse(error_obj.isrecoverable)
new_error_obj=pickle.loads(pickle.dumps(error_obj))
self.assertIsInstance(new_error_obj, oracledb._Error)
self.assertEqual(new_error_obj.message, error_obj.message)
self.assertEqual(new_error_obj.code, error_obj.code)
self.assertEqual(new_error_obj.offset, error_obj.offset)
self.assertEqual(new_error_obj.context, error_obj.context)
self.assertEqual(new_error_obj.isrecoverable, error_obj.isrecoverable)
asyncdeftest_6802(self):
"6802 - test generation of full_code for ORA, DPI and DPY errors"
cursor=self.conn.cursor()
withself.assertRaises(oracledb.Error) ascm:
awaitcursor.execute(None)
(error_obj,) =cm.exception.args
self.assertEqual(error_obj.full_code, "DPY-2001")
asyncdeftest_6803(self):
"6803 - test generation of error help portal URL"
cursor=self.conn.cursor()
withself.assertRaises(oracledb.Error) ascm:
awaitcursor.execute("select 1 / 0 from dual")
(error_obj,) =cm.exception.args
to_check="Help: https://docs.oracle.com/error-help/db/ora-01476/"
self.assertIn(to_check, error_obj.message)
asyncdeftest_6804(self):
"6804 - verify warning is generated when creating a procedure"
proc_name="bad_proc_1704"
self.assertIsNone(self.cursor.warning)
awaitself.cursor.execute(
f"""
create or replace procedure {proc_name} as
begin
null
end;
"""
)
self.assertEqual(self.cursor.warning.full_code, "DPY-7000")
awaitself.cursor.execute(
f"""
create or replace procedure {proc_name} as
begin
null;
end;
"""
)
self.assertIsNone(self.cursor.warning)
awaitself.cursor.execute(f"drop procedure {proc_name}")
asyncdeftest_6805(self):
"6805 - verify warning is generated when creating a function"
func_name="bad_func_1705"
awaitself.cursor.execute(
f"""
create or replace function {func_name}
return number as
begin
return null
end;
"""
)
self.assertEqual(self.cursor.warning.full_code, "DPY-7000")
awaitself.cursor.execute(f"drop function {func_name}")
self.assertIsNone(self.cursor.warning)
asyncdeftest_6806(self):
"6806 - verify warning is generated when creating a type"
type_name="bad_type_1706"
awaitself.cursor.execute(
f"""
create or replace type {type_name} as object (
x bad_type
);
"""
)
self.assertEqual(self.cursor.warning.full_code, "DPY-7000")
awaitself.cursor.execute(f"drop type {type_name}")
self.assertIsNone(self.cursor.warning)
asyncdeftest_6807(self):
"6807 - verify warning is saved in a pipeline"
proc_name="bad_proc_1704"
func_name="bad_func_1705"
type_name="bad_type_1706"
pipeline=oracledb.create_pipeline()
pipeline.add_execute(
f"""
create or replace procedure {proc_name} as
begin
null
end;
"""
)
pipeline.add_execute(
f"""
create or replace procedure {proc_name} as
begin
null;
end;
"""
)
pipeline.add_execute(f"drop procedure {proc_name}")
pipeline.add_execute(
f"""
create or replace function {func_name}
return number as
begin
return null
end;
"""
)
pipeline.add_execute(f"drop function {func_name}")
pipeline.add_execute(
f"""
create or replace type {type_name} as object (
x bad_type
);
"""
)
pipeline.add_execute(f"drop type {type_name}")
results=awaitself.conn.run_pipeline(pipeline)
self.assertEqual(results[0].warning.full_code, "DPY-7000")
self.assertIsNone(results[1].warning)
self.assertIsNone(results[2].warning)
self.assertEqual(results[3].warning.full_code, "DPY-7000")
self.assertIsNone(results[4].warning)
self.assertEqual(results[5].warning.full_code, "DPY-7000")
self.assertIsNone(results[6].warning)
asyncdeftest_6808(self):
"6808 - verify warning is saved in a pipeline with a single operation"
proc_name="bad_proc_6808"
pipeline=oracledb.create_pipeline()
pipeline.add_execute(
f"""
create or replace procedure {proc_name} as
begin
null
end;
"""
)
(result,) =awaitself.conn.run_pipeline(pipeline)
self.assertEqual(result.warning.full_code, "DPY-7000")
awaitself.cursor.execute(f"drop procedure {proc_name}")
@unittest.skipIf(test_env.get_is_drcp(), "not supported with DRCP")
asyncdeftest_6809(self):
"6809 - error from killed connection is deemed recoverable"
admin_conn=awaittest_env.get_admin_connection_async()
conn=awaittest_env.get_connection_async()
sid, serial=awaitself.get_sid_serial(conn)
withadmin_conn.cursor() asadmin_cursor:
sql=f"alter system kill session '{sid},{serial}'"
awaitadmin_cursor.execute(sql)
withself.assertRaisesFullCode("DPY-4011") ascm:
withconn.cursor() ascursor:
awaitcursor.execute("select user from dual")
self.assertTrue(cm.error_obj.isrecoverable)
if__name__=="__main__":
test_env.run_test_cases()