httpie-cli/tests/test_unicode.py

87 lines
2.9 KiB
Python
Raw Normal View History

# coding=utf-8
"""
Various unicode handling related tests.
"""
2014-04-26 18:23:13 +02:00
from tests import http, httpbin, HTTP_OK
2014-04-26 19:47:14 +02:00
from tests.fixtures import UNICODE
class TestUnicode:
def test_unicode_headers(self):
r = http('--verbose', httpbin('/headers'), u'Test:%s' % UNICODE)
2014-04-26 18:23:13 +02:00
assert HTTP_OK in r
2014-04-26 17:16:11 +02:00
assert r.json['headers']['Test'] == UNICODE
def test_unicode_headers_verbose(self):
r = http('--verbose', httpbin('/headers'), u'Test:%s' % UNICODE)
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_form_item(self):
2014-04-26 17:16:11 +02:00
r = http('--form', 'POST', httpbin('/post'), u'test=%s' % UNICODE)
2014-04-26 18:23:13 +02:00
assert HTTP_OK in r
2014-04-26 19:32:08 +02:00
assert r.json['form'] == {'test': UNICODE}
def test_unicode_form_item_verbose(self):
r = http('--verbose', '--form',
'POST', httpbin('/post'), u'test=%s' % UNICODE)
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_json_item(self):
2014-04-26 17:16:11 +02:00
r = http('--json', 'POST', httpbin('/post'), u'test=%s' % UNICODE)
2014-04-26 18:23:13 +02:00
assert HTTP_OK in r
2014-04-26 19:32:08 +02:00
assert r.json['json'] == {'test': UNICODE}
def test_unicode_json_item_verbose(self):
r = http('--verbose', '--json',
'POST', httpbin('/post'), u'test=%s' % UNICODE)
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_raw_json_item(self):
r = http('--verbose',
'--json', 'POST', httpbin('/post'),
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
def test_unicode_raw_json_item_verbose(self):
r = http('--verbose',
'--json', 'POST', httpbin('/post'),
2014-04-26 19:32:08 +02:00
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
2014-04-26 18:23:13 +02:00
assert HTTP_OK in r
assert UNICODE in r
2014-04-26 18:23:13 +02:00
def test_unicode_url_query_arg_item(self):
r = http(httpbin('/get'), u'test==%s' % UNICODE)
assert HTTP_OK in r
2014-04-26 19:32:08 +02:00
assert r.json['args'] == {'test': UNICODE}, r
2014-04-26 18:23:13 +02:00
def test_unicode_url_query_arg_item_verbose(self):
r = http('--verbose', httpbin('/get'), u'test==%s' % UNICODE)
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_url(self):
2014-04-26 17:16:11 +02:00
r = http(httpbin(u'/get?test=' + UNICODE))
2014-04-26 18:23:13 +02:00
assert HTTP_OK in r
2014-04-26 19:32:08 +02:00
assert r.json['args'] == {'test': UNICODE}
# def test_unicode_url_verbose(self):
# r = http(httpbin('--verbose', u'/get?test=' + UNICODE))
# assert HTTP_OK in r
def test_unicode_basic_auth(self):
# it doesn't really authenticate us because httpbin
# doesn't interpret the utf8-encoded auth
2014-04-26 17:16:11 +02:00
http('--verbose', '--auth', u'test:%s' % UNICODE,
httpbin(u'/basic-auth/test/' + UNICODE))
def test_unicode_digest_auth(self):
# it doesn't really authenticate us because httpbin
# doesn't interpret the utf8-encoded auth
http('--auth-type=digest',
2014-04-26 17:16:11 +02:00
'--auth', u'test:%s' % UNICODE,
httpbin(u'/digest-auth/auth/test/' + UNICODE))