From 762e5d9a980a7470b534e8f539b873f212c6e004 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 28 Nov 2018 15:09:42 +0100 Subject: [PATCH 1/5] Run tests with MariaDB too on Travis CI --- .travis.yml | 4 ++++ tox.ini | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/.travis.yml b/.travis.yml index 534fffdaf..4fe8630bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,10 @@ matrix: env: TOXENV=postgresql addons: postgresql: "9.5" + - python: 3.7 + env: TOXENV=mariadb + addons: + mariadb: "10.3" - env: TOXENV=flake8 - python: 3.7 env: TOXENV=style diff --git a/tox.ini b/tox.ini index b2c323e7d..d14b7f71a 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist = py{35,36,37}-dj21 py{35,36,37}-djmaster postgresql, + mariadb, flake8, style, readme @@ -42,6 +43,22 @@ whitelist_externals = make pip_pre = True commands = make coverage TEST_ARGS='{posargs:tests}' +[testenv:mariadb] +deps = + Django>=2.1,<2.2 + coverage + django_jinja + html5lib + mysqlclient + selenium<4.0 + sqlparse +setenv = + PYTHONPATH = {toxinidir} + DJANGO_DATABASE_ENGINE = mysql +whitelist_externals = make +pip_pre = True +commands = make coverage TEST_ARGS='{posargs:tests}' + [testenv:flake8] basepython = python3 commands = make flake8 From 2f3193ebd6c51b8761fa67bec6660d8632a8fce4 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 28 Nov 2018 15:19:34 +0100 Subject: [PATCH 2/5] Remove the MySQL USER --- tests/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/settings.py b/tests/settings.py index e4d865f03..ce8814d43 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -92,7 +92,6 @@ "default": { "ENGINE": "django.db.backends.mysql", "NAME": "debug_toolbar", - "USER": "debug_toolbar", } } else: From ad091e6715ba6f67acf51c707a497c3a2a5335e4 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 28 Nov 2018 15:35:17 +0100 Subject: [PATCH 3/5] Test with a real BinaryField --- tests/models.py | 5 +++++ tests/panels/test_sql.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/models.py b/tests/models.py index 93f860bb1..ed6dbc1bd 100644 --- a/tests/models.py +++ b/tests/models.py @@ -2,9 +2,14 @@ from __future__ import absolute_import, unicode_literals +from django.db import models from django.utils import six class NonAsciiRepr(object): def __repr__(self): return "nôt åscíì" if six.PY3 else "nôt åscíì".encode("utf-8") + + +class Binary(models.Model): + field = models.BinaryField() diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index 4092cfbc1..dae656630 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -113,23 +113,23 @@ def test_param_conversion(self): ('["Foo", true, false]', "[10, 1]", '["2017-12-22 16:07:01"]'), ) - @unittest.skipIf( - connection.vendor in ("sqlite", "postgresql"), - "Mixing bytestrings and text is not allowed on PostgreSQL and SQLite", - ) def test_binary_param_force_text(self): self.assertEqual(len(self.panel._queries), 0) with connection.cursor() as cursor: - cursor.execute("SELECT * FROM auth_user WHERE username = %s", [b"\xff"]) + cursor.execute("SELECT * FROM tests_binary WHERE field = %s", [b"\xff"]) self.panel.process_response(self.request, self.response) self.panel.generate_stats(self.request, self.response) self.assertEqual(len(self.panel._queries), 1) - self.assertEqual( - self.panel._queries[0][1]["sql"], - "SELECT * FROM auth_user WHERE username = '\ufffd'", + self.assertTrue( + self.panel._queries[0][1]["sql"].startswith( + ( + "SELECT * FROM" + " tests_binary WHERE field = " + ) + ) ) @unittest.skipUnless(connection.vendor != "sqlite", "Test invalid for SQLite") From 901aed74972cadfb6aa5834172e75bf96b28e7c6 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 28 Nov 2018 15:41:29 +0100 Subject: [PATCH 4/5] Mark binary payload as binary (same thing BinaryField.get_db_prep_value does) --- tests/panels/test_sql.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index dae656630..81fd94e61 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -117,7 +117,10 @@ def test_binary_param_force_text(self): self.assertEqual(len(self.panel._queries), 0) with connection.cursor() as cursor: - cursor.execute("SELECT * FROM tests_binary WHERE field = %s", [b"\xff"]) + cursor.execute( + "SELECT * FROM tests_binary WHERE field = %s", + [connection.Database.Binary(b"\xff")], + ) self.panel.process_response(self.request, self.response) self.panel.generate_stats(self.request, self.response) From 48a0e2e5f22cbeaba2c8d30b277ad06413e40a23 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 28 Nov 2018 15:42:28 +0100 Subject: [PATCH 5/5] Reformat settings using black --- tests/settings.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/settings.py b/tests/settings.py index ce8814d43..7bdc3ade8 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -85,14 +85,8 @@ "default": {"ENGINE": "django.db.backends.postgresql", "NAME": "debug-toolbar"} } elif os.environ.get("DJANGO_DATABASE_ENGINE") == "mysql": - # % mysql - # CREATE USER 'debug_toolbar'@'localhost' IDENTIFIED BY ''; - # GRANT ALL PRIVILEGES ON debug_toolbar.* TO 'test_debug_toolbar'@'localhost'; DATABASES = { - "default": { - "ENGINE": "django.db.backends.mysql", - "NAME": "debug_toolbar", - } + "default": {"ENGINE": "django.db.backends.mysql", "NAME": "debug_toolbar"} } else: DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}