Skip to content

Commit

Permalink
Fix BytesWarnings in tests
Browse files Browse the repository at this point in the history
Don't pass bytes objects as filter arguments for CharField fields.  They
get passed to str() internally within Django which results in a
BytesWaring.
  • Loading branch information
living180 authored and matthiask committed May 23, 2023
1 parent c335601 commit 476b5ce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
psycopg = None

from ..base import BaseMultiDBTestCase, BaseTestCase
from ..models import PostgresJSON
from ..models import Binary, PostgresJSON


def sql_call(use_iterator=False):
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_non_ascii_query(self):
self.assertEqual(len(self.panel._queries), 2)

# non-ASCII bytes parameters
list(User.objects.filter(username="café".encode()))
list(Binary.objects.filter(field__in=["café".encode()]))
self.assertEqual(len(self.panel._queries), 3)

response = self.panel.process_request(self.request)
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_insert_content(self):
Test that the panel only inserts content after generate_stats and
not the process_request.
"""
list(User.objects.filter(username="café".encode()))
list(User.objects.filter(username="café"))
response = self.panel.process_request(self.request)
# ensure the panel does not have content yet.
self.assertNotIn("café", self.panel.content)
Expand All @@ -351,7 +351,7 @@ def test_insert_locals(self):
Test that the panel inserts locals() content.
"""
local_var = "<script>alert('test');</script>" # noqa: F841
list(User.objects.filter(username="café".encode()))
list(User.objects.filter(username="café"))
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)
self.assertIn("local_var", self.panel.content)
Expand All @@ -365,7 +365,7 @@ def test_not_insert_locals(self):
"""
Test that the panel does not insert locals() content.
"""
list(User.objects.filter(username="café".encode()))
list(User.objects.filter(username="café"))
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)
self.assertNotIn("djdt-locals", self.panel.content)
Expand Down

0 comments on commit 476b5ce

Please sign in to comment.