Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with MariaDB #1121

Merged
merged 5 commits into from Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
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
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
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
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
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