summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2020-03-22 15:04:59 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2020-03-22 15:04:59 +0000
commit7ff3e3f2e73e7f17c0a352dacf5c0ccfa2ef7be9 (patch)
tree553fd8f751a75dc5d614c32065817f8da6206968 /test/dialect/postgresql
parentf2a817dd7cde50988839750b9c2464675fb4f069 (diff)
parent9ec75882203b2c01aa1d362f939e21ebcd188e8d (diff)
downloadsqlalchemy-7ff3e3f2e73e7f17c0a352dacf5c0ccfa2ef7be9.tar.gz
Merge "Deprecate plain string in execute and introduce `exec_driver_sql`"
Diffstat (limited to 'test/dialect/postgresql')
-rw-r--r--test/dialect/postgresql/test_dialect.py24
-rw-r--r--test/dialect/postgresql/test_reflection.py111
2 files changed, 70 insertions, 65 deletions
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py
index e36b69802..03e91482d 100644
--- a/test/dialect/postgresql/test_dialect.py
+++ b/test/dialect/postgresql/test_dialect.py
@@ -56,7 +56,7 @@ class DialectTest(fixtures.TestBase):
def test_version_parsing(self):
def mock_conn(res):
return mock.Mock(
- execute=mock.Mock(
+ exec_driver_sql=mock.Mock(
return_value=mock.Mock(scalar=mock.Mock(return_value=res))
)
)
@@ -615,7 +615,7 @@ class MiscBackendTest(
conn = testing.db.connect()
trans = conn.begin()
try:
- conn.execute(
+ conn.exec_driver_sql(
"""
CREATE OR REPLACE FUNCTION note(message varchar) RETURNS integer AS $$
BEGIN
@@ -625,8 +625,8 @@ END;
$$ LANGUAGE plpgsql;
"""
)
- conn.execute("SELECT note('hi there')")
- conn.execute("SELECT note('another note')")
+ conn.exec_driver_sql("SELECT note('hi there')")
+ conn.exec_driver_sql("SELECT note('another note')")
finally:
trans.rollback()
finally:
@@ -643,7 +643,9 @@ $$ LANGUAGE plpgsql;
@engines.close_open_connections
def test_client_encoding(self):
c = testing.db.connect()
- current_encoding = c.execute("show client_encoding").fetchone()[0]
+ current_encoding = c.exec_driver_sql(
+ "show client_encoding"
+ ).fetchone()[0]
c.close()
# attempt to use an encoding that's not
@@ -655,7 +657,7 @@ $$ LANGUAGE plpgsql;
e = engines.testing_engine(options={"client_encoding": test_encoding})
c = e.connect()
- new_encoding = c.execute("show client_encoding").fetchone()[0]
+ new_encoding = c.exec_driver_sql("show client_encoding").fetchone()[0]
eq_(new_encoding, test_encoding)
@testing.requires.psycopg2_or_pg8000_compatibility
@@ -671,7 +673,7 @@ $$ LANGUAGE plpgsql;
assert_raises_message(
exc.ProgrammingError,
'prepared transaction with identifier "gilberte" does not exist',
- c.execute,
+ c.exec_driver_sql,
"commit prepared 'gilberte'",
)
@@ -697,7 +699,7 @@ $$ LANGUAGE plpgsql;
seq = Sequence("fooseq")
t = Table("mytable", meta1, Column("col1", Integer, seq))
seq.drop()
- testing.db.execute("CREATE SEQUENCE fooseq")
+ testing.db.execute(text("CREATE SEQUENCE fooseq"))
t.create(checkfirst=True)
@testing.provide_metadata
@@ -766,7 +768,8 @@ $$ LANGUAGE plpgsql;
try:
meta = MetaData(testing.db)
testing.db.execute(
- """
+ text(
+ """
CREATE TABLE speedy_users
(
speedy_user_id SERIAL PRIMARY KEY,
@@ -775,6 +778,7 @@ $$ LANGUAGE plpgsql;
user_password VARCHAR NOT NULL
);
"""
+ )
)
t = Table("speedy_users", meta, autoload=True)
r = t.insert().execute(user_name="user", user_password="lala")
@@ -782,7 +786,7 @@ $$ LANGUAGE plpgsql;
result = t.select().execute().fetchall()
assert result == [(1, "user", "lala")]
finally:
- testing.db.execute("drop table speedy_users")
+ testing.db.execute(text("drop table speedy_users"))
@testing.requires.psycopg2_or_pg8000_compatibility
def test_numeric_raise(self):
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py
index 8e26d5a83..89d4ae081 100644
--- a/test/dialect/postgresql/test_reflection.py
+++ b/test/dialect/postgresql/test_reflection.py
@@ -277,28 +277,32 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
'CREATE DOMAIN "SomeSchema"."Quoted.Domain" INTEGER DEFAULT 0',
]:
try:
- con.execute(ddl)
+ con.exec_driver_sql(ddl)
except exc.DBAPIError as e:
if "already exists" not in str(e):
raise e
- con.execute(
+ con.exec_driver_sql(
"CREATE TABLE testtable (question integer, answer " "testdomain)"
)
- con.execute(
+ con.exec_driver_sql(
"CREATE TABLE test_schema.testtable(question "
"integer, answer test_schema.testdomain, anything "
"integer)"
)
- con.execute(
+ con.exec_driver_sql(
"CREATE TABLE crosschema (question integer, answer "
"test_schema.testdomain)"
)
- con.execute("CREATE TABLE enum_test (id integer, data enumdomain)")
+ con.exec_driver_sql(
+ "CREATE TABLE enum_test (id integer, data enumdomain)"
+ )
- con.execute("CREATE TABLE array_test (id integer, data arraydomain)")
+ con.exec_driver_sql(
+ "CREATE TABLE array_test (id integer, data arraydomain)"
+ )
- con.execute(
+ con.exec_driver_sql(
"CREATE TABLE quote_test "
'(id integer, data "SomeSchema"."Quoted.Domain")'
)
@@ -306,19 +310,19 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
@classmethod
def teardown_class(cls):
con = testing.db.connect()
- con.execute("DROP TABLE testtable")
- con.execute("DROP TABLE test_schema.testtable")
- con.execute("DROP TABLE crosschema")
- con.execute("DROP TABLE quote_test")
- con.execute("DROP DOMAIN testdomain")
- con.execute("DROP DOMAIN test_schema.testdomain")
- con.execute("DROP TABLE enum_test")
- con.execute("DROP DOMAIN enumdomain")
- con.execute("DROP TYPE testtype")
- con.execute("DROP TABLE array_test")
- con.execute("DROP DOMAIN arraydomain")
- con.execute('DROP DOMAIN "SomeSchema"."Quoted.Domain"')
- con.execute('DROP SCHEMA "SomeSchema"')
+ con.exec_driver_sql("DROP TABLE testtable")
+ con.exec_driver_sql("DROP TABLE test_schema.testtable")
+ con.exec_driver_sql("DROP TABLE crosschema")
+ con.exec_driver_sql("DROP TABLE quote_test")
+ con.exec_driver_sql("DROP DOMAIN testdomain")
+ con.exec_driver_sql("DROP DOMAIN test_schema.testdomain")
+ con.exec_driver_sql("DROP TABLE enum_test")
+ con.exec_driver_sql("DROP DOMAIN enumdomain")
+ con.exec_driver_sql("DROP TYPE testtype")
+ con.exec_driver_sql("DROP TABLE array_test")
+ con.exec_driver_sql("DROP DOMAIN arraydomain")
+ con.exec_driver_sql('DROP DOMAIN "SomeSchema"."Quoted.Domain"')
+ con.exec_driver_sql('DROP SCHEMA "SomeSchema"')
def test_table_is_reflected(self):
metadata = MetaData(testing.db)
@@ -485,9 +489,9 @@ class ReflectionTest(fixtures.TestBase):
eq_(t2.c.id.server_default.arg.text, "nextval('t_id_seq'::regclass)")
r = t2.insert().execute()
eq_(r.inserted_primary_key, [1])
- testing.db.connect().execution_options(autocommit=True).execute(
- "alter table t_id_seq rename to foobar_id_seq"
- )
+ testing.db.connect().execution_options(
+ autocommit=True
+ ).exec_driver_sql("alter table t_id_seq rename to foobar_id_seq")
m3 = MetaData(testing.db)
t3 = Table("t", m3, autoload=True, implicit_returning=False)
eq_(
@@ -507,9 +511,9 @@ class ReflectionTest(fixtures.TestBase):
Column("x", Integer),
)
metadata.create_all()
- testing.db.connect().execution_options(autocommit=True).execute(
- "alter table t alter column id type varchar(50)"
- )
+ testing.db.connect().execution_options(
+ autocommit=True
+ ).exec_driver_sql("alter table t alter column id type varchar(50)")
m2 = MetaData(testing.db)
t2 = Table("t", m2, autoload=True)
eq_(t2.c.id.autoincrement, False)
@@ -520,9 +524,9 @@ class ReflectionTest(fixtures.TestBase):
metadata = self.metadata
Table("t", metadata, Column("id", Integer, primary_key=True))
metadata.create_all()
- testing.db.connect().execution_options(autocommit=True).execute(
- "alter table t rename id to t_id"
- )
+ testing.db.connect().execution_options(
+ autocommit=True
+ ).exec_driver_sql("alter table t rename id to t_id")
m2 = MetaData(testing.db)
t2 = Table("t", m2, autoload=True)
eq_([c.name for c in t2.primary_key], ["t_id"])
@@ -642,7 +646,7 @@ class ReflectionTest(fixtures.TestBase):
conn = testing.db.connect()
conn.detach()
- conn.execute("SET search_path TO test_schema, test_schema_2")
+ conn.exec_driver_sql("SET search_path TO test_schema, test_schema_2")
meta2 = MetaData(bind=conn)
subject = Table(
"subject",
@@ -727,7 +731,7 @@ class ReflectionTest(fixtures.TestBase):
with testing.db.connect() as conn:
conn.detach()
- conn.execute(
+ conn.exec_driver_sql(
"set search_path to test_schema_2, test_schema, public"
)
@@ -792,7 +796,7 @@ class ReflectionTest(fixtures.TestBase):
with testing.db.connect() as conn:
conn.detach()
- conn.execute(
+ conn.exec_driver_sql(
"set search_path to test_schema_2, test_schema, public"
)
meta2 = MetaData(conn)
@@ -889,22 +893,17 @@ class ReflectionTest(fixtures.TestBase):
Column("aname", String(20)),
)
metadata.create_all()
- testing.db.execute(
- """
- create index idx1 on party ((id || name))
- """
- )
- testing.db.execute(
- """
- create unique index idx2 on party (id) where name = 'test'
- """
- )
- testing.db.execute(
- """
- create index idx3 on party using btree
- (lower(name::text), lower(aname::text))
- """
- )
+ with testing.db.connect() as c:
+ c.exec_driver_sql("create index idx1 on party ((id || name))")
+ c.exec_driver_sql(
+ "create unique index idx2 on party (id) where name = 'test'"
+ )
+ c.exec_driver_sql(
+ """
+ create index idx3 on party using btree
+ (lower(name::text), lower(aname::text))
+ """
+ )
def go():
m2 = MetaData(testing.db)
@@ -951,7 +950,7 @@ class ReflectionTest(fixtures.TestBase):
t1.create(conn)
# check ASC, DESC options alone
- conn.execute(
+ conn.exec_driver_sql(
"""
create index idx1 on party
(id, name ASC, aname DESC)
@@ -959,7 +958,7 @@ class ReflectionTest(fixtures.TestBase):
)
# check DESC w/ NULLS options
- conn.execute(
+ conn.exec_driver_sql(
"""
create index idx2 on party
(name DESC NULLS FIRST, aname DESC NULLS LAST)
@@ -967,7 +966,7 @@ class ReflectionTest(fixtures.TestBase):
)
# check ASC w/ NULLS options
- conn.execute(
+ conn.exec_driver_sql(
"""
create index idx3 on party
(name ASC NULLS FIRST, aname ASC NULLS LAST)
@@ -1028,8 +1027,8 @@ class ReflectionTest(fixtures.TestBase):
)
metadata.create_all()
conn = testing.db.connect().execution_options(autocommit=True)
- conn.execute("CREATE INDEX idx1 ON t (x)")
- conn.execute("ALTER TABLE t RENAME COLUMN x to y")
+ conn.exec_driver_sql("CREATE INDEX idx1 ON t (x)")
+ conn.exec_driver_sql("ALTER TABLE t RENAME COLUMN x to y")
ind = testing.db.dialect.get_indexes(conn, "t", None)
eq_(ind, [{"unique": False, "column_names": ["y"], "name": "idx1"}])
@@ -1051,7 +1050,9 @@ class ReflectionTest(fixtures.TestBase):
metadata.create_all()
with testing.db.connect().execution_options(autocommit=True) as conn:
- conn.execute("CREATE INDEX idx1 ON t (x) WITH (fillfactor = 50)")
+ conn.exec_driver_sql(
+ "CREATE INDEX idx1 ON t (x) WITH (fillfactor = 50)"
+ )
ind = testing.db.dialect.get_indexes(conn, "t", None)
eq_(
@@ -1089,7 +1090,7 @@ class ReflectionTest(fixtures.TestBase):
)
metadata.create_all()
with testing.db.connect().execution_options(autocommit=True) as conn:
- conn.execute("CREATE INDEX idx1 ON t USING gin (x)")
+ conn.exec_driver_sql("CREATE INDEX idx1 ON t USING gin (x)")
ind = testing.db.dialect.get_indexes(conn, "t", None)
eq_(