Skip to content

Commit ad091e6

Browse files
committed
Test with a real BinaryField
1 parent 2f3193e commit ad091e6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

tests/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
from __future__ import absolute_import, unicode_literals
44

5+
from django.db import models
56
from django.utils import six
67

78

89
class NonAsciiRepr(object):
910
def __repr__(self):
1011
return "nôt åscíì" if six.PY3 else "nôt åscíì".encode("utf-8")
12+
13+
14+
class Binary(models.Model):
15+
field = models.BinaryField()

tests/panels/test_sql.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ def test_param_conversion(self):
113113
('["Foo", true, false]', "[10, 1]", '["2017-12-22 16:07:01"]'),
114114
)
115115

116-
@unittest.skipIf(
117-
connection.vendor in ("sqlite", "postgresql"),
118-
"Mixing bytestrings and text is not allowed on PostgreSQL and SQLite",
119-
)
120116
def test_binary_param_force_text(self):
121117
self.assertEqual(len(self.panel._queries), 0)
122118

123119
with connection.cursor() as cursor:
124-
cursor.execute("SELECT * FROM auth_user WHERE username = %s", [b"\xff"])
120+
cursor.execute("SELECT * FROM tests_binary WHERE field = %s", [b"\xff"])
125121

126122
self.panel.process_response(self.request, self.response)
127123
self.panel.generate_stats(self.request, self.response)
128124

129125
self.assertEqual(len(self.panel._queries), 1)
130-
self.assertEqual(
131-
self.panel._queries[0][1]["sql"],
132-
"SELECT * FROM auth_user WHERE username = '\ufffd'",
126+
self.assertTrue(
127+
self.panel._queries[0][1]["sql"].startswith(
128+
(
129+
"<strong>SELECT</strong> * <strong>FROM</strong>"
130+
" tests_binary <strong>WHERE</strong> field = "
131+
)
132+
)
133133
)
134134

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

0 commit comments

Comments
 (0)