Skip to content

Commit

Permalink
Test with a real BinaryField
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Nov 28, 2018
1 parent 2f3193e commit ad091e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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()
16 changes: 8 additions & 8 deletions tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
"<strong>SELECT</strong> * <strong>FROM</strong>"
" tests_binary <strong>WHERE</strong> field = "
)
)
)

@unittest.skipUnless(connection.vendor != "sqlite", "Test invalid for SQLite")
Expand Down

0 comments on commit ad091e6

Please sign in to comment.