Skip to content

Commit 7893795

Browse files
committed
Minor SQLAlchemy compatibility fixes
1) use URL.render_as_string(hide_password=False) for passing connection strings via environment variables. str(url) will hide the password value and replace it with `***` 2) Connection.execute() now expects a Query-like object rather than a a raw string. We can just wrap it in text()
1 parent f8aa85b commit 7893795

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/test_gabbits.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from cryptography.hazmat.primitives.asymmetric import rsa
2323
from gabbi.driver import test_pytest
2424
from gabbi.handlers import base
25+
from sqlalchemy import text
2526

2627

2728
XSNIPPET_API_HOST = "127.0.0.1"
@@ -83,26 +84,27 @@ def setup_db(self):
8384

8485
with self.management_db.connect() as conn:
8586
conn.execute(
86-
"CREATE DATABASE {database} OWNER {username};".format(
87-
**self.test_db_url.translate_connect_args()))
87+
text("CREATE DATABASE {database} OWNER {username};".format(
88+
**self.test_db_url.translate_connect_args())))
8889

8990
# apply schema migrations to the temporary database. Both
9091
# Alembic and XSnippet API expect the connection string to be
9192
# passed via the ROCKET_DATABASE_URL environment variable, so
9293
# we update the variable to point to the temporary database for
9394
# the duration of the test
94-
os.environ["ROCKET_DATABASE_URL"] = str(self.test_db_url)
95+
os.environ["ROCKET_DATABASE_URL"] = self.test_db_url.render_as_string(hide_password=False)
9596
alembic.config.main(["upgrade", "head"])
9697

9798
def teardown_db(self):
9899
"""Clean up the temporary database."""
99100

100101
with self.management_db.connect() as conn:
101-
conn.execute("DROP DATABASE IF EXISTS {};".format(self.test_db_url.database))
102+
conn.execute(
103+
text("DROP DATABASE IF EXISTS {};".format(self.test_db_url.database)))
102104

103105
# restore the original value of ROCKET_DATABASE_URL, so that
104106
# it can be used by the fixture to create new databases again
105-
os.environ["ROCKET_DATABASE_URL"] = str(self.management_db.url)
107+
os.environ["ROCKET_DATABASE_URL"] = self.management_db.url.render_as_string(hide_password=False)
106108

107109

108110
def start_server(self):

0 commit comments

Comments
 (0)