Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca397a7

Browse files
committed
Encode UTF text only if in Python 2
1 parent 2b14022 commit ca397a7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/test_json_model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ def test_json_build_query(self):
121121

122122
query_dict = parse_qs(query[1:])
123123
self.assertEqual(query_dict['foo'], ['1'])
124-
self.assertEqual(query_dict['bar'], [u'\N{COMET}'.encode('utf-8')])
124+
if six.PY3:
125+
# Python 3, no need to encode
126+
self.assertEqual(query_dict['bar'], [u'\N{COMET}'])
127+
else:
128+
# Python 2, encode string
129+
self.assertEqual(query_dict['bar'], [u'\N{COMET}'.encode('utf-8')])
125130
self.assertEqual(query_dict['baz'], ['fe', 'fi', 'fo', 'fum'])
126131
self.assertTrue('qux' not in query_dict)
127132
self.assertEqual(body, '{}')

0 commit comments

Comments
 (0)