Skip to content

Commit a64e371

Browse files
committed
Fix failing unittests
1 parent 1e8ccef commit a64e371

File tree

6 files changed

+45
-11
lines changed

6 files changed

+45
-11
lines changed

lib/mysql/connector/abstracts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def config(self, **kwargs):
281281
('username', 'user'),
282282
('passwd', 'password'),
283283
('connect_timeout', 'connection_timeout'),
284-
('read_default_file', 'option_files') ,
284+
('read_default_file', 'option_files'),
285285
]
286286
for compat, translate in compat_map:
287287
try:

lib/mysqlx/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ def hexlify(data):
8282
UNICODE_TYPES = (unicode,)
8383
STRING_TYPES = (str, unicode,)
8484
BYTE_TYPES = (bytearray,)
85-
MAX_INT = sys.maxint
85+
MAX_INT = sys.maxint # pylint: disable=E1101
8686
JSONDecodeError = ValueError

lib/mysqlx/connection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ def set_ssl(self, ssl_mode, ssl_ca, ssl_crl, ssl_cert, ssl_key):
203203
self.close()
204204
raise RuntimeError("Python installation has no SSL support")
205205

206-
protocol = ssl.PROTOCOL_TLS if hasattr(ssl, "PROTOCOL_TLS") \
207-
else ssl.PROTOCOL_TLSv1
206+
if hasattr(ssl, "PROTOCOL_TLS"):
207+
protocol = ssl.PROTOCOL_TLS # pylint: disable=E1101
208+
else:
209+
protocol = ssl.PROTOCOL_TLSv1
210+
208211
context = ssl.SSLContext(protocol)
209212
context.load_default_certs()
210213

src/mysql_capi.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -890,22 +890,49 @@ MySQL_autocommit(MySQL *self, PyObject *mode)
890890
PyObject*
891891
MySQL_change_user(MySQL *self, PyObject *args, PyObject *kwds)
892892
{
893-
char *user= NULL, *password= NULL, *database= NULL;
893+
char *user= NULL, *database= NULL;
894+
#ifdef PY3
895+
char *password = NULL;
896+
#else
897+
PyObject *password = NULL;
898+
#endif
894899
int res;
895900
static char *kwlist[]= {"user", "password", "database", NULL};
896901

897902
IS_CONNECTED(self);
898903

899-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sss", kwlist,
900-
&user, &password, &database))
904+
#ifdef PY3
905+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzz", kwlist,
906+
#else
907+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zOz", kwlist,
908+
#endif
909+
&user, &password, &database
910+
))
901911
{
902912
return NULL;
903913
}
904-
914+
#ifdef PY3
905915
Py_BEGIN_ALLOW_THREADS
906916
res= mysql_change_user(&self->session, user, password, database);
907917
Py_END_ALLOW_THREADS
908-
918+
#else
919+
{
920+
char* c_password;
921+
if (PyUnicode_Check(password))
922+
{
923+
PyObject* u_password= PyUnicode_AsUTF8String(password);
924+
c_password= PyString_AsString(u_password);
925+
Py_DECREF(u_password);
926+
}
927+
else
928+
{
929+
c_password= PyString_AsString(password);
930+
}
931+
Py_BEGIN_ALLOW_THREADS
932+
res= mysql_change_user(&self->session, user, c_password, database);
933+
Py_END_ALLOW_THREADS
934+
}
935+
#endif
909936
if (res)
910937
{
911938
raise_with_session(&self->session, NULL);

tests/test_abstracts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def test_cmd_init_db(self):
172172
@unittest.skipIf(tests.MYSQL_VERSION < (5, 7, 2),
173173
"reset command not available")
174174
@foreach_cnx()
175+
@unittest.skipIf(tests.MYSQL_VERSION < (8, 0),
176+
"Not working with cross version MySQL lib< 8.0.")
175177
def test_reset_session(self):
176178
exp = [True, u'STRICT_ALL_TABLES', u'-09:00', 33]
177179
self.cnx.autocommit = exp[0]

tests/test_bugs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ def test_reconnect(self):
771771
self.assertTrue('3 attempt(s)' in str(exc))
772772

773773

774+
@unittest.skipIf(sys.version_info < (3, 5), "Objects not collected by GC.")
774775
class BugOra13435186(tests.MySQLConnectorTests):
775776
def setUp(self):
776777
self.sample_size = 100
@@ -2341,8 +2342,9 @@ def test_ssl(self):
23412342
self.assertTrue(res != '')
23422343

23432344

2344-
@unittest.skipIf(tests.MYSQL_VERSION < (5, 6, 7),
2345-
"BugOra16217765 not tested with MySQL version < 5.6.7")
2345+
@unittest.skipIf(tests.MYSQL_VERSION < (8, 0),
2346+
"BugOra16217765 not tested with MySQL version < 5.6.7. "
2347+
"Not working with cross version MySQL lib< 8.0.")
23462348
class BugOra16217765(tests.MySQLConnectorTests):
23472349
"""BUG#16217765: Fix authentication plugin support
23482350
"""

0 commit comments

Comments
 (0)