Skip to content

Commit 062cbde

Browse files
committed
BUG19660283: Fix failing unit tests with MySQL server 5.7.5
MySQL server 5.7.5 creates no user while bootstrapping a server. We add extra DML to create the root@ocalhost user, making sure unit test can run.
1 parent 6514365 commit 062cbde

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

tests/mysqld.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ def bootstrap(self):
419419
"CREATE DATABASE myconnpy;"
420420
]
421421

422+
if self._version[0:3] >= (5, 7, 5):
423+
# MySQL 5.7.5 creates no user while bootstrapping
424+
extra_sql.append(
425+
"INSERT INTO mysql.user VALUES ('localhost','root','',"
426+
"'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',"
427+
"'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',"
428+
"'Y','Y','Y','Y','Y','','','','',0,0,0,0,"
429+
"@@default_authentication_plugin,'','N',"
430+
"CURRENT_TIMESTAMP,NULL);"
431+
)
422432
if self._version[0:3] >= (5, 7, 4):
423433
# MySQL 5.7.4 only creates root@localhost
424434
extra_sql.append(

tests/test_bugs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,9 @@ def test_parameters(self):
23052305
err)
23062306

23072307

2308+
@unittest.skipIf(tests.MYSQL_VERSION >= (5, 7, 5),
2309+
"MySQL {0} does not support old password auth".format(
2310+
tests.MYSQL_VERSION_TXT))
23082311
class BugOra18415927(tests.MySQLConnectorTests):
23092312
"""BUG#18415927: AUTH_RESPONSE VARIABLE INCREMENTED WITHOUT BEING DEFINED
23102313
"""

tests/test_mysql_datatypes.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import time
2929
import datetime
3030

31-
from mysql.connector import connection
31+
from mysql.connector import connection, errors
3232
import tests
3333

3434

@@ -339,18 +339,23 @@ def test_temporal_datetime(self):
339339

340340
# Testing YEAR(2), which is now obsolete since MySQL 5.6.6
341341
tblname = self.tables['temporal_year']
342-
cur.execute(
342+
stmt = (
343343
"CREATE TABLE {table} ("
344344
"`id` int NOT NULL AUTO_INCREMENT KEY, "
345345
"`t_year_2` YEAR(2))".format(table=tblname)
346-
)
347-
cur.execute(_get_insert_stmt(tblname, ['t_year_2']), (10,))
348-
cur.execute(_get_select_stmt(tblname, ['t_year_2']))
349-
row = cur.fetchone()
350-
351-
if tests.MYSQL_VERSION >= (5, 6, 6):
352-
self.assertEqual(2010, row[0])
346+
)
347+
if tests.MYSQL_VERSION >= (5, 7, 5):
348+
# Support for YEAR(2) removed in MySQL 5.7.5
349+
self.assertRaises(errors.DatabaseError, cur.execute, stmt)
353350
else:
354-
self.assertEqual(10, row[0])
351+
cur.execute(stmt)
352+
cur.execute(_get_insert_stmt(tblname, ['t_year_2']), (10,))
353+
cur.execute(_get_select_stmt(tblname, ['t_year_2']))
354+
row = cur.fetchone()
355+
356+
if tests.MYSQL_VERSION >= (5, 6, 6):
357+
self.assertEqual(2010, row[0])
358+
else:
359+
self.assertEqual(10, row[0])
355360

356361
cur.close()

0 commit comments

Comments
 (0)