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")