summaryrefslogtreecommitdiff
path: root/test/dialect/oracle
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-11-06 14:56:56 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-11-07 11:13:28 -0500
commit80be40300dfe33bdf75f61aaa0d5c48045886bb4 (patch)
treec8ec681e20d0967d434e511e737099f05ea6721a /test/dialect/oracle
parent8b9772de2dd9c9f1f01f96209d79ec1cd087b2fa (diff)
downloadsqlalchemy-80be40300dfe33bdf75f61aaa0d5c48045886bb4.tar.gz
Convert to autoload_with internally
Fixed bug where the now-deprecated ``autoload`` parameter was being called internally within the reflection routines when a related table were reflected. Fixes: #5684 Change-Id: I6ab439a2f49ff1ae2d3c7a15b531cbafbc3cf594
Diffstat (limited to 'test/dialect/oracle')
-rw-r--r--test/dialect/oracle/test_reflection.py100
-rw-r--r--test/dialect/oracle/test_types.py100
2 files changed, 108 insertions, 92 deletions
diff --git a/test/dialect/oracle/test_reflection.py b/test/dialect/oracle/test_reflection.py
index bd881ac1c..efa21fc1a 100644
--- a/test/dialect/oracle/test_reflection.py
+++ b/test/dialect/oracle/test_reflection.py
@@ -123,17 +123,18 @@ drop synonym %(test_schema)s.local_table;
Column("pid", Integer, ForeignKey("%s.parent.pid" % schema)),
schema=schema,
)
- meta.create_all()
- parent.insert().execute({"pid": 1})
- child.insert().execute({"cid": 1, "pid": 1})
- eq_(child.select().execute().fetchall(), [(1, 1)])
+ with testing.db.begin() as conn:
+ meta.create_all(conn)
+ conn.execute(parent.insert(), {"pid": 1})
+ conn.execute(child.insert(), {"cid": 1, "pid": 1})
+ eq_(conn.execute(child.select()).fetchall(), [(1, 1)])
def test_reflect_alt_table_owner_local_synonym(self):
- meta = MetaData(testing.db)
+ meta = MetaData()
parent = Table(
"%s_pt" % testing.config.test_schema,
meta,
- autoload=True,
+ autoload_with=testing.db,
oracle_resolve_synonyms=True,
)
self.assert_compile(
@@ -142,14 +143,13 @@ drop synonym %(test_schema)s.local_table;
"%(test_schema)s_pt.data FROM %(test_schema)s_pt"
% {"test_schema": testing.config.test_schema},
)
- select(parent).execute().fetchall()
def test_reflect_alt_synonym_owner_local_table(self):
- meta = MetaData(testing.db)
+ meta = MetaData()
parent = Table(
"local_table",
meta,
- autoload=True,
+ autoload_with=testing.db,
oracle_resolve_synonyms=True,
schema=testing.config.test_schema,
)
@@ -160,7 +160,6 @@ drop synonym %(test_schema)s.local_table;
"FROM %(test_schema)s.local_table"
% {"test_schema": testing.config.test_schema},
)
- select(parent).execute().fetchall()
@testing.provide_metadata
def test_create_same_names_implicit_schema(self):
@@ -180,12 +179,18 @@ drop synonym %(test_schema)s.local_table;
eq_(child.select().execute().fetchall(), [(1, 1)])
def test_reflect_alt_owner_explicit(self):
- meta = MetaData(testing.db)
+ meta = MetaData()
parent = Table(
- "parent", meta, autoload=True, schema=testing.config.test_schema
+ "parent",
+ meta,
+ autoload_with=testing.db,
+ schema=testing.config.test_schema,
)
child = Table(
- "child", meta, autoload=True, schema=testing.config.test_schema
+ "child",
+ meta,
+ autoload_with=testing.db,
+ schema=testing.config.test_schema,
)
self.assert_compile(
@@ -194,9 +199,10 @@ drop synonym %(test_schema)s.local_table;
"%(test_schema)s.parent.id = %(test_schema)s.child.parent_id"
% {"test_schema": testing.config.test_schema},
)
- select(parent, child).select_from(
- parent.join(child)
- ).execute().fetchall()
+ with testing.db.connect() as conn:
+ conn.execute(
+ select(parent, child).select_from(parent.join(child))
+ ).fetchall()
# check table comment (#5146)
eq_(parent.comment, "my table comment")
@@ -241,8 +247,8 @@ drop synonym %(test_schema)s.local_table;
% {"test_schema": testing.config.test_schema},
)
try:
- meta = MetaData(testing.db)
- lcl = Table("localtable", meta, autoload=True)
+ meta = MetaData()
+ lcl = Table("localtable", meta, autoload_with=testing.db)
parent = meta.tables["%s.parent" % testing.config.test_schema]
self.assert_compile(
parent.join(lcl),
@@ -251,19 +257,22 @@ drop synonym %(test_schema)s.local_table;
"localtable.parent_id"
% {"test_schema": testing.config.test_schema},
)
- select(parent, lcl).select_from(
- parent.join(lcl)
- ).execute().fetchall()
finally:
exec_sql(testing.db, "DROP TABLE localtable")
def test_reflect_alt_owner_implicit(self):
- meta = MetaData(testing.db)
+ meta = MetaData()
parent = Table(
- "parent", meta, autoload=True, schema=testing.config.test_schema
+ "parent",
+ meta,
+ autoload_with=testing.db,
+ schema=testing.config.test_schema,
)
child = Table(
- "child", meta, autoload=True, schema=testing.config.test_schema
+ "child",
+ meta,
+ autoload_with=testing.db,
+ schema=testing.config.test_schema,
)
self.assert_compile(
parent.join(child),
@@ -272,9 +281,10 @@ drop synonym %(test_schema)s.local_table;
"%(test_schema)s.child.parent_id"
% {"test_schema": testing.config.test_schema},
)
- select(parent, child).select_from(
- parent.join(child)
- ).execute().fetchall()
+ with testing.db.connect() as conn:
+ conn.execute(
+ select(parent, child).select_from(parent.join(child))
+ ).fetchall()
def test_reflect_alt_owner_synonyms(self):
exec_sql(
@@ -284,9 +294,12 @@ drop synonym %(test_schema)s.local_table;
"%s.ptable(id))" % testing.config.test_schema,
)
try:
- meta = MetaData(testing.db)
+ meta = MetaData()
lcl = Table(
- "localtable", meta, autoload=True, oracle_resolve_synonyms=True
+ "localtable",
+ meta,
+ autoload_with=testing.db,
+ oracle_resolve_synonyms=True,
)
parent = meta.tables["%s.ptable" % testing.config.test_schema]
self.assert_compile(
@@ -296,25 +309,26 @@ drop synonym %(test_schema)s.local_table;
"localtable.parent_id"
% {"test_schema": testing.config.test_schema},
)
- select(parent, lcl).select_from(
- parent.join(lcl)
- ).execute().fetchall()
+ with testing.db.connect() as conn:
+ conn.execute(
+ select(parent, lcl).select_from(parent.join(lcl))
+ ).fetchall()
finally:
exec_sql(testing.db, "DROP TABLE localtable")
def test_reflect_remote_synonyms(self):
- meta = MetaData(testing.db)
+ meta = MetaData()
parent = Table(
"ptable",
meta,
- autoload=True,
+ autoload_with=testing.db,
schema=testing.config.test_schema,
oracle_resolve_synonyms=True,
)
child = Table(
"ctable",
meta,
- autoload=True,
+ autoload_with=testing.db,
schema=testing.config.test_schema,
oracle_resolve_synonyms=True,
)
@@ -326,9 +340,6 @@ drop synonym %(test_schema)s.local_table;
"%(test_schema)s.ctable.parent_id"
% {"test_schema": testing.config.test_schema},
)
- select(parent, child).select_from(
- parent.join(child)
- ).execute().fetchall()
class ConstraintTest(fixtures.TablesTest):
@@ -488,9 +499,9 @@ class TableReflectionTest(fixtures.TestBase):
)
metadata.create_all()
- m2 = MetaData(testing.db)
+ m2 = MetaData()
- tbl = Table("test_compress", m2, autoload=True)
+ tbl = Table("test_compress", m2, autoload_with=testing.db)
# Don't hardcode the exact value, but it must be non-empty
assert tbl.dialect_options["oracle"]["compress"]
@@ -507,9 +518,9 @@ class TableReflectionTest(fixtures.TestBase):
)
metadata.create_all()
- m2 = MetaData(testing.db)
+ m2 = MetaData()
- tbl = Table("test_compress", m2, autoload=True)
+ tbl = Table("test_compress", m2, autoload_with=testing.db)
assert tbl.dialect_options["oracle"]["compress"] == "OLTP"
@@ -760,7 +771,6 @@ class DBLinkReflectionTest(fixtures.TestBase):
t = Table(
"test_table_syn",
m,
- autoload=True,
autoload_with=testing.db,
oracle_resolve_synonyms=True,
)
@@ -778,8 +788,8 @@ class TypeReflectionTest(fixtures.TestBase):
m = self.metadata
Table("oracle_types", m, *columns)
m.create_all()
- m2 = MetaData(testing.db)
- table = Table("oracle_types", m2, autoload=True)
+ m2 = MetaData()
+ table = Table("oracle_types", m2, autoload_with=testing.db)
for i, (reflected_col, spec) in enumerate(zip(table.c, specs)):
expected_spec = spec[1]
reflected_type = reflected_col.type
diff --git a/test/dialect/oracle/test_types.py b/test/dialect/oracle/test_types.py
index 0b000e89d..8fbf374ee 100644
--- a/test/dialect/oracle/test_types.py
+++ b/test/dialect/oracle/test_types.py
@@ -313,42 +313,47 @@ class TypesTest(fixtures.TestBase):
Column("numbercol2", oracle.NUMBER(9, 3)),
Column("numbercol3", oracle.NUMBER),
)
- t1.create()
- t1.insert().execute(
- intcol=1,
- numericcol=5.2,
- floatcol1=6.5,
- floatcol2=8.5,
- doubleprec=9.5,
- numbercol1=12,
- numbercol2=14.85,
- numbercol3=15.76,
- )
+ with testing.db.begin() as conn:
+ t1.create(conn)
+ conn.execute(
+ t1.insert(),
+ dict(
+ intcol=1,
+ numericcol=5.2,
+ floatcol1=6.5,
+ floatcol2=8.5,
+ doubleprec=9.5,
+ numbercol1=12,
+ numbercol2=14.85,
+ numbercol3=15.76,
+ ),
+ )
- m2 = MetaData(testing.db)
- t2 = Table("t1", m2, autoload=True)
+ m2 = MetaData()
+ t2 = Table("t1", m2, autoload_with=testing.db)
- for row in (
- t1.select().execute().first(),
- t2.select().execute().first(),
- ):
- for i, (val, type_) in enumerate(
- (
- (1, int),
- (decimal.Decimal("5.2"), decimal.Decimal),
- (6.5, float),
- (8.5, float),
- (9.5, float),
- (12, int),
- (decimal.Decimal("14.85"), decimal.Decimal),
- (15.76, float),
- )
+ with testing.db.connect() as conn:
+ for row in (
+ conn.execute(t1.select()).first(),
+ conn.execute(t2.select()).first(),
):
- eq_(row[i], val)
- assert isinstance(row[i], type_), "%r is not %r" % (
- row[i],
- type_,
- )
+ for i, (val, type_) in enumerate(
+ (
+ (1, int),
+ (decimal.Decimal("5.2"), decimal.Decimal),
+ (6.5, float),
+ (8.5, float),
+ (9.5, float),
+ (12, int),
+ (decimal.Decimal("14.85"), decimal.Decimal),
+ (15.76, float),
+ )
+ ):
+ eq_(row[i], val)
+ assert isinstance(row[i], type_), "%r is not %r" % (
+ row[i],
+ type_,
+ )
@testing.provide_metadata
def test_numeric_infinity_float(self, connection):
@@ -743,8 +748,8 @@ class TypesTest(fixtures.TestBase):
Column("d5", oracle.INTERVAL(second_precision=5)),
)
metadata.create_all()
- m = MetaData(testing.db)
- t1 = Table("date_types", m, autoload=True)
+ m = MetaData()
+ t1 = Table("date_types", m, autoload_with=testing.db)
assert isinstance(t1.c.d1.type, oracle.DATE)
assert isinstance(t1.c.d1.type, DateTime)
assert isinstance(t1.c.d2.type, oracle.DATE)
@@ -758,10 +763,10 @@ class TypesTest(fixtures.TestBase):
def _dont_test_reflect_all_types_schema(self):
types_table = Table(
"all_types",
- MetaData(testing.db),
+ MetaData(),
Column("owner", String(30), primary_key=True),
Column("type_name", String(30), primary_key=True),
- autoload=True,
+ autoload_with=testing.db,
oracle_resolve_synonyms=True,
)
for row in types_table.select().execute().fetchall():
@@ -790,8 +795,8 @@ class TypesTest(fixtures.TestBase):
Column("c_data", sqltypes.NCHAR(20)),
)
metadata.create_all()
- m2 = MetaData(testing.db)
- t2 = Table("tnv", m2, autoload=True)
+ m2 = MetaData()
+ t2 = Table("tnv", m2, autoload_with=testing.db)
assert isinstance(t2.c.nv_data.type, sqltypes.NVARCHAR)
assert isinstance(t2.c.c_data.type, sqltypes.NCHAR)
@@ -820,8 +825,8 @@ class TypesTest(fixtures.TestBase):
metadata = self.metadata
Table("tnv", metadata, Column("data", sqltypes.Unicode(255)))
metadata.create_all()
- m2 = MetaData(testing.db)
- t2 = Table("tnv", m2, autoload=True)
+ m2 = MetaData()
+ t2 = Table("tnv", m2, autoload_with=testing.db)
assert isinstance(t2.c.data.type, sqltypes.VARCHAR)
if testing.against("oracle+cx_oracle"):
@@ -831,10 +836,11 @@ class TypesTest(fixtures.TestBase):
)
data = u("m’a réveillé.")
- t2.insert().execute(data=data)
- res = t2.select().execute().first()["data"]
- eq_(res, data)
- assert isinstance(res, util.text_type)
+ with testing.db.begin() as conn:
+ conn.execute(t2.insert(), {"data": data})
+ res = conn.execute(t2.select()).first().data
+ eq_(res, data)
+ assert isinstance(res, util.text_type)
@testing.provide_metadata
def test_char_length(self):
@@ -848,8 +854,8 @@ class TypesTest(fixtures.TestBase):
Column("c4", NCHAR(180)),
)
t1.create()
- m2 = MetaData(testing.db)
- t2 = Table("t1", m2, autoload=True)
+ m2 = MetaData()
+ t2 = Table("t1", m2, autoload_with=testing.db)
eq_(t2.c.c1.type.length, 50)
eq_(t2.c.c2.type.length, 250)
eq_(t2.c.c3.type.length, 200)