Skip to content

Commit 07b057b

Browse files
James Gututim-schilling
authored andcommitted
added tests
1 parent 67bd449 commit 07b057b

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

debug_toolbar/panels/sql/tracking.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ def _decode(self, param):
128128

129129
# make sure datetime, date and time are converted to string by force_str
130130
CONVERT_TYPES = (datetime.datetime, datetime.date, datetime.time)
131-
try:
132-
return force_str(param, strings_only=not isinstance(param, CONVERT_TYPES))
133-
except UnicodeDecodeError:
134-
return "(encoded string)"
131+
return force_str(param, strings_only=not isinstance(param, CONVERT_TYPES))
132+
135133

136134
def _last_executed_query(self, sql, params):
137135
"""Get the last executed query from the connection."""

debug_toolbar/sanitize.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
from django.utils.encoding import DjangoUnicodeDecodeError, force_str as force_string
22

33

4-
def force_str(value):
4+
# def force_str(s, encoding="utf-8", strings_only=False, errors="strict"):
5+
# try:
6+
# return force_string(s, encoding, strings_only, errors)
7+
# except DjangoUnicodeDecodeError:
8+
# return "Django Debug Toolbar was unable to parse value."
9+
10+
def force_str(s, *args, **kwargs):
511
try:
6-
return force_string(value)
12+
return force_string(s, *args, **kwargs)
713
except DjangoUnicodeDecodeError:
814
return "Django Debug Toolbar was unable to parse value."

tests/test_sanitize.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
3+
from debug_toolbar.sanitize import force_str
4+
5+
6+
class ForceStrTestCase(unittest.TestCase):
7+
def test_success_convert(self):
8+
input = 0
9+
10+
self.assertEqual(
11+
force_str(input),
12+
"0"
13+
)
14+
15+
def test_failed_convert(self):
16+
input = bytes.fromhex("a3f2b8c14e972d5a8fb3c7291a64e0859c472bf63d18a0945e73b2c84f917ae2")
17+
self.assertEqual(
18+
force_str(input),
19+
"Django Debug Toolbar was unable to parse value."
20+
)

0 commit comments

Comments
 (0)