mirror of
https://github.com/httpie/cli.git
synced 2025-03-31 21:55:16 +02:00
Added test case to verify unicode output
This commit is contained in:
parent
5a82c79fdf
commit
df79792fd9
@ -1,9 +1,12 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
import unittest
|
import unittest
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import json
|
||||||
from requests.compat import is_py26
|
from requests.compat import is_py26
|
||||||
|
from requests import Response
|
||||||
|
|
||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
@ -442,5 +445,51 @@ class ArgumentParserTestCase(unittest.TestCase):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class FakeResponse(Response):
|
||||||
|
|
||||||
|
class Mock(object):
|
||||||
|
|
||||||
|
def __getattr__(self, item):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return u'Mock string'
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
|
def __init__(self, content=None, encoding='utf-8'):
|
||||||
|
super(FakeResponse, self).__init__()
|
||||||
|
self.headers['Content-Type'] = 'application/json'
|
||||||
|
self.encoding = encoding
|
||||||
|
self._content = content.encode(encoding)
|
||||||
|
self.raw = self.Mock()
|
||||||
|
|
||||||
|
|
||||||
|
class UnicodeOutputTestCase(BaseTestCase):
|
||||||
|
|
||||||
|
def test_unicode_output(self):
|
||||||
|
# some cyrillic and simplified chinese symbols
|
||||||
|
response_dict = {u'Привет': u'Мир!',
|
||||||
|
u'Hello': u'世界'}
|
||||||
|
response_body = json.dumps(response_dict)
|
||||||
|
# emulate response
|
||||||
|
response = FakeResponse(response_body)
|
||||||
|
|
||||||
|
# emulate cli arguments
|
||||||
|
args = argparse.Namespace()
|
||||||
|
args.prettify = True
|
||||||
|
args.output_options = 'b'
|
||||||
|
args.forced_content_type = None
|
||||||
|
args.style = 'default'
|
||||||
|
|
||||||
|
# colorized output contains escape sequences
|
||||||
|
output = __main__._get_output(args, True, response)
|
||||||
|
|
||||||
|
for key, value in response_dict.iteritems():
|
||||||
|
self.assertIn(key, output)
|
||||||
|
self.assertIn(value, output)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user