From: Mike Bayer Date: Thu, 10 Feb 2011 23:06:48 +0000 (-0500) Subject: - oursql dialect accepts the same "ssl" arguments in X-Git-Tag: rel_0_6_7~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4be34a26999bd54a9cbd2fc28512c18fb35ece64;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - oursql dialect accepts the same "ssl" arguments in create_engine() as that of MySQLdb. [ticket:2047] --- diff --git a/CHANGES b/CHANGES index 67b87b801f..d35ef809da 100644 --- a/CHANGES +++ b/CHANGES @@ -59,6 +59,10 @@ CHANGES exceptions, "could not receive data from server" [ticket:2044] +- mysql + - oursql dialect accepts the same "ssl" arguments in + create_engine() as that of MySQLdb. [ticket:2047] + 0.6.6 ===== - orm diff --git a/lib/sqlalchemy/dialects/mysql/oursql.py b/lib/sqlalchemy/dialects/mysql/oursql.py index d3ef839b14..001f8a0bbc 100644 --- a/lib/sqlalchemy/dialects/mysql/oursql.py +++ b/lib/sqlalchemy/dialects/mysql/oursql.py @@ -222,6 +222,16 @@ class MySQLDialect_oursql(MySQLDialect): # supports_sane_rowcount. opts.setdefault('found_rows', True) + ssl = {} + for key in ['ssl_ca', 'ssl_key', 'ssl_cert', + 'ssl_capath', 'ssl_cipher']: + if key in opts: + ssl[key[4:]] = opts[key] + util.coerce_kw_type(ssl, key[4:], str) + del opts[key] + if ssl: + opts['ssl'] = ssl + return [[], opts] def _get_server_version_info(self, connection): diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index 4eff0f98a3..e3168e2449 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -13,6 +13,32 @@ from sqlalchemy.test.testing import eq_ from sqlalchemy.test import * from sqlalchemy.test.engines import utf8_engine import datetime +from sqlalchemy.engine.url import make_url + +class DialectTest(TestBase): + __only_on__ = 'mysql' + + @testing.only_on(['mysql+mysqldb', 'mysql+oursql'], + 'requires particular SSL arguments') + def test_ssl_arguments(self): + dialect = testing.db.dialect + kwarg = dialect.create_connect_args( + make_url("mysql://scott:tiger@localhost:3306/test" + "?ssl_ca=/ca.pem&ssl_cert=/cert.pem&ssl_key=/key.pem") + )[1] + # args that differ among mysqldb and oursql + for k in ('use_unicode', 'found_rows', 'client_flag'): + kwarg.pop(k, None) + eq_( + kwarg, + { + 'passwd': 'tiger', 'db': 'test', + 'ssl': {'ca': '/ca.pem', 'cert': '/cert.pem', + 'key': '/key.pem'}, + 'host': 'localhost', 'user': 'scott', + 'port': 3306 + } + ) class TypesTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL): "Test MySQL column types"