diff options
author | Jeremy Stanley <fungi@yuggoth.org> | 2015-05-20 01:04:01 +0000 |
---|---|---|
committer | Victor Sergeyev <vsergeyev@mirantis.com> | 2015-06-18 15:42:23 +0300 |
commit | 9b552046f55e56d45a9e7274e62ebb372c112c36 (patch) | |
tree | c63bb59d025b07e0abec72876374672135412379 /oslo_db/tests/sqlalchemy/test_utils.py | |
parent | 910d40aa399874fcb36576de4d7d06d38f61cd50 (diff) | |
download | oslo-db-9b552046f55e56d45a9e7274e62ebb372c112c36.tar.gz |
Switch from MySQL-python to PyMySQL
As discussed in the Liberty Design Summit "Moving apps to Python 3"
cross-project workshop, the way forward in the near future is to
switch to the pure-python PyMySQL library as a default.
Added a special test environment to keep MySQL-python support.
Documentation modified.
https://etherpad.openstack.org/p/liberty-cross-project-python3
Change-Id: I12b32dc097a121bd43991bc38dd4d289b65e86c1
Diffstat (limited to 'oslo_db/tests/sqlalchemy/test_utils.py')
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_utils.py | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py index 6719d0f..054f99d 100644 --- a/oslo_db/tests/sqlalchemy/test_utils.py +++ b/oslo_db/tests/sqlalchemy/test_utils.py @@ -912,8 +912,10 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): dispatcher = orig = utils.dispatch_for_dialect("*")( callable_fn.default) dispatcher = dispatcher.dispatch_for("sqlite")(callable_fn.sqlite) - dispatcher = dispatcher.dispatch_for("mysql+mysqldb")( - callable_fn.mysql_mysqldb) + dispatcher = dispatcher.dispatch_for("mysql+pymysql")( + callable_fn.mysql_pymysql) + dispatcher = dispatcher.dispatch_for("mysql")( + callable_fn.mysql) dispatcher = dispatcher.dispatch_for("postgresql")( callable_fn.postgresql) @@ -927,7 +929,8 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): for targ in [ callable_fn.default, callable_fn.sqlite, - callable_fn.mysql_mysqldb, + callable_fn.mysql, + callable_fn.mysql_pymysql, callable_fn.postgresql, callable_fn.postgresql_psycopg2, callable_fn.pyodbc @@ -937,8 +940,10 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): dispatcher = orig = utils.dispatch_for_dialect("*", multiple=True)( callable_fn.default) dispatcher = dispatcher.dispatch_for("sqlite")(callable_fn.sqlite) - dispatcher = dispatcher.dispatch_for("mysql+mysqldb")( - callable_fn.mysql_mysqldb) + dispatcher = dispatcher.dispatch_for("mysql+pymysql")( + callable_fn.mysql_pymysql) + dispatcher = dispatcher.dispatch_for("mysql")( + callable_fn.mysql) dispatcher = dispatcher.dispatch_for("postgresql+*")( callable_fn.postgresql) dispatcher = dispatcher.dispatch_for("postgresql+psycopg2")( @@ -955,15 +960,17 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): dispatcher, callable_fn = self._single_fixture() dispatcher("sqlite://", 1) dispatcher("postgresql+psycopg2://u:p@h/t", 2) - dispatcher("mysql://u:p@h/t", 3) - dispatcher("mysql+mysqlconnector://u:p@h/t", 4) + dispatcher("mysql+pymysql://u:p@h/t", 3) + dispatcher("mysql://u:p@h/t", 4) + dispatcher("mysql+mysqlconnector://u:p@h/t", 5) self.assertEqual( [ mock.call.sqlite('sqlite://', 1), mock.call.postgresql("postgresql+psycopg2://u:p@h/t", 2), - mock.call.mysql_mysqldb("mysql://u:p@h/t", 3), - mock.call.default("mysql+mysqlconnector://u:p@h/t", 4) + mock.call.mysql_pymysql("mysql+pymysql://u:p@h/t", 3), + mock.call.mysql("mysql://u:p@h/t", 4), + mock.call.mysql("mysql+mysqlconnector://u:p@h/t", 5), ], callable_fn.mock_calls) @@ -1081,10 +1088,10 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): def test_single_retval(self): dispatcher, callable_fn = self._single_fixture() - callable_fn.mysql_mysqldb.return_value = 5 + callable_fn.mysql_pymysql.return_value = 5 self.assertEqual( - dispatcher("mysql://u:p@h/t", 3), 5 + dispatcher("mysql+pymysql://u:p@h/t", 3), 5 ) def test_engine(self): @@ -1097,14 +1104,25 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): callable_fn.mock_calls ) - def test_url(self): + def test_url_pymysql(self): url = sqlalchemy.engine.url.make_url( - "mysql+mysqldb://scott:tiger@localhost/test") + "mysql+pymysql://scott:tiger@localhost/test") dispatcher, callable_fn = self._single_fixture() dispatcher(url, 15) self.assertEqual( - [mock.call.mysql_mysqldb(url, 15)], + [mock.call.mysql_pymysql(url, 15)], + callable_fn.mock_calls + ) + + def test_url_mysql_generic(self): + url = sqlalchemy.engine.url.make_url( + "mysql://scott:tiger@localhost/test") + dispatcher, callable_fn = self._single_fixture() + + dispatcher(url, 15) + self.assertEqual( + [mock.call.mysql(url, 15)], callable_fn.mock_calls ) @@ -1149,9 +1167,10 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): dispatcher, callable_fn = self._multiple_fixture() dispatcher("postgresql+pyodbc://", 1) - dispatcher("mysql://", 2) + dispatcher("mysql+pymysql://", 2) dispatcher("ibm_db_sa+db2://", 3) dispatcher("postgresql+psycopg2://", 4) + dispatcher("postgresql://", 5) # TODO(zzzeek): there is a deterministic order here, but we might # want to tweak it, or maybe provide options. default first? @@ -1161,12 +1180,18 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase): mock.call.postgresql('postgresql+pyodbc://', 1), mock.call.pyodbc('postgresql+pyodbc://', 1), mock.call.default('postgresql+pyodbc://', 1), - mock.call.mysql_mysqldb('mysql://', 2), - mock.call.default('mysql://', 2), + mock.call.mysql_pymysql('mysql+pymysql://', 2), + mock.call.mysql('mysql+pymysql://', 2), + mock.call.default('mysql+pymysql://', 2), mock.call.default('ibm_db_sa+db2://', 3), mock.call.postgresql_psycopg2('postgresql+psycopg2://', 4), mock.call.postgresql('postgresql+psycopg2://', 4), mock.call.default('postgresql+psycopg2://', 4), + # note this is called because we resolve the default + # DBAPI for the url + mock.call.postgresql_psycopg2('postgresql://', 5), + mock.call.postgresql('postgresql://', 5), + mock.call.default('postgresql://', 5), ], callable_fn.mock_calls ) |