Skip to content

Commit

Permalink
Merge pull request #1121 from matthiask/mariadb
Browse files Browse the repository at this point in the history
Run tests with MariaDB
  • Loading branch information
matthiask authored Dec 3, 2018
2 parents e78ac8c + 48a0e2e commit a4a5393
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
19 changes: 11 additions & 8 deletions tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,26 @@ 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",
[connection.Database.Binary(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(
(
"<strong>SELECT</strong> * <strong>FROM</strong>"
" tests_binary <strong>WHERE</strong> field = "
)
)
)

@unittest.skipUnless(connection.vendor != "sqlite", "Test invalid for SQLite")
Expand Down
9 changes: 1 addition & 8 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +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",
"USER": "debug_toolbar",
}
"default": {"ENGINE": "django.db.backends.mysql", "NAME": "debug_toolbar"}
}
else:
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}
Expand Down
17 changes: 17 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ envlist =
py{35,36,37}-dj21
py{35,36,37}-djmaster
postgresql,
mariadb,
flake8,
style,
readme
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4a5393

Please sign in to comment.