summaryrefslogtreecommitdiff
path: root/test/engine/test_parseconnect.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-09-08 22:25:12 +0200
committerFederico Caselli <cfederico87@gmail.com>2021-09-13 21:23:10 +0200
commit23b3375dcd89b0ad268f8c96a5782f45bf9a99af (patch)
tree430d19415d1b607be7ed3ee56a71534ac5d9fffa /test/engine/test_parseconnect.py
parent6dbcb792eb60d4e084f0d1252882a0cbad4bc673 (diff)
downloadsqlalchemy-23b3375dcd89b0ad268f8c96a5782f45bf9a99af.tar.gz
Ensure str is callect on the URL password.
Ensure that ``str()`` is called on the an ``URL.password`` argument, allowing usage of objects that implement the ``__str__()`` method as password attributes. Also clarified that one such object is not appropriate to dynamically change the password. Fixes: #6958 Change-Id: Id0690990a64b9e0935537b7b8f5a73efe6a9e3dc
Diffstat (limited to 'test/engine/test_parseconnect.py')
-rw-r--r--test/engine/test_parseconnect.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py
index 9acedaa85..136695279 100644
--- a/test/engine/test_parseconnect.py
+++ b/test/engine/test_parseconnect.py
@@ -367,6 +367,16 @@ class URLTest(fixtures.TestBase):
)
eq_(u1, url.make_url("somedriver://user@hostname:52"))
+ def test_deprecated_translate_connect_args_names(self):
+ u = url.make_url("somedriver://user@hostname:52")
+
+ with testing.expect_deprecated(
+ "The `URL.translate_connect_args.name`s parameter is "
+ ):
+ res = u.translate_connect_args(["foo"])
+ is_true("foo" in res)
+ eq_(res["foo"], u.host)
+
class DialectImportTest(fixtures.TestBase):
def test_import_base_dialects(self):
@@ -691,6 +701,43 @@ class CreateEngineTest(fixtures.TestBase):
_initialize=False,
)
+ @testing.combinations(True, False)
+ def test_password_object_str(self, creator):
+ class SecurePassword:
+ def __init__(self, value):
+ self.called = 0
+ self.value = value
+
+ def __str__(self):
+ self.called += 1
+ return self.value
+
+ sp = SecurePassword("secured_password")
+ u = url.URL.create(
+ "postgresql", username="x", password=sp, host="localhost"
+ )
+ if not creator:
+ dbapi = MockDBAPI(
+ user="x", password="secured_password", host="localhost"
+ )
+
+ e = create_engine(u, module=dbapi, _initialize=False)
+
+ else:
+ dbapi = MockDBAPI(foober=12, lala=18, fooz="somevalue")
+
+ def connect():
+ return dbapi.connect(foober=12, lala=18, fooz="somevalue")
+
+ e = create_engine(
+ u, creator=connect, module=dbapi, _initialize=False
+ )
+ e.connect()
+ e.connect()
+ e.connect()
+ e.connect()
+ eq_(sp.called, 1)
+
class TestRegNewDBAPI(fixtures.TestBase):
def test_register_base(self):