2014-04-26 15:06:51 +02:00
|
|
|
# coding=utf-8
|
|
|
|
"""
|
|
|
|
Various unicode handling related tests.
|
|
|
|
|
|
|
|
"""
|
2014-06-28 16:35:57 +02:00
|
|
|
from utils import http, HTTP_OK
|
2014-04-28 11:29:41 +02:00
|
|
|
from fixtures import UNICODE
|
2014-04-26 15:06:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestUnicode:
|
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_headers(self, httpbin):
|
2014-06-03 19:44:22 +02:00
|
|
|
# httpbin doesn't interpret utf8 headers
|
2014-06-28 16:35:57 +02:00
|
|
|
r = http(httpbin.url + '/headers', u'Test:%s' % UNICODE)
|
2014-04-26 18:23:13 +02:00
|
|
|
assert HTTP_OK in r
|
2014-04-26 15:06:51 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_headers_verbose(self, httpbin):
|
2014-06-03 19:44:22 +02:00
|
|
|
# httpbin doesn't interpret utf8 headers
|
2014-06-28 16:35:57 +02:00
|
|
|
r = http('--verbose', httpbin.url + '/headers', u'Test:%s' % UNICODE)
|
2014-04-26 20:10:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert UNICODE in r
|
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_form_item(self, httpbin):
|
|
|
|
r = http('--form', 'POST', httpbin.url + '/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}
|
2014-04-26 15:06:51 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_form_item_verbose(self, httpbin):
|
2014-04-26 20:10:15 +02:00
|
|
|
r = http('--verbose', '--form',
|
2014-06-28 16:35:57 +02:00
|
|
|
'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
2014-04-26 20:10:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert UNICODE in r
|
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_json_item(self, httpbin):
|
|
|
|
r = http('--json', 'POST', httpbin.url + '/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}
|
2014-04-26 15:06:51 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_json_item_verbose(self, httpbin):
|
2014-04-26 20:10:15 +02:00
|
|
|
r = http('--verbose', '--json',
|
2014-06-28 16:35:57 +02:00
|
|
|
'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
2014-04-26 20:10:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert UNICODE in r
|
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_raw_json_item(self, httpbin):
|
|
|
|
r = http('--json', 'POST', httpbin.url + '/post',
|
2014-04-26 20:10:15 +02:00
|
|
|
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
|
2014-04-28 23:33:30 +02:00
|
|
|
assert HTTP_OK in r
|
2014-04-26 20:14:46 +02:00
|
|
|
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
|
2014-04-26 20:10:15 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_raw_json_item_verbose(self, httpbin):
|
|
|
|
r = http('--json', 'POST', httpbin.url + '/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
|
2014-04-28 23:33:30 +02:00
|
|
|
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
|
2014-04-26 15:06:51 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_url_query_arg_item(self, httpbin):
|
|
|
|
r = http(httpbin.url + '/get', 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['args'] == {'test': UNICODE}, r
|
2014-04-26 18:23:13 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_url_query_arg_item_verbose(self, httpbin):
|
|
|
|
r = http('--verbose', httpbin.url + '/get', u'test==%s' % UNICODE)
|
2014-04-26 20:10:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert UNICODE in r
|
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_url(self, httpbin):
|
|
|
|
r = http(httpbin.url + 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}
|
2014-04-26 15:06:51 +02:00
|
|
|
|
2014-04-26 20:10:15 +02:00
|
|
|
# def test_unicode_url_verbose(self):
|
2014-06-28 16:35:57 +02:00
|
|
|
# r = http(httpbin.url + '--verbose', u'/get?test=' + UNICODE)
|
2014-04-26 20:10:15 +02:00
|
|
|
# assert HTTP_OK in r
|
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_basic_auth(self, httpbin):
|
2014-04-26 15:06:51 +02:00
|
|
|
# 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,
|
2014-06-28 16:35:57 +02:00
|
|
|
httpbin.url + u'/basic-auth/test/' + UNICODE)
|
2014-04-26 15:06:51 +02:00
|
|
|
|
2014-06-28 16:35:57 +02:00
|
|
|
def test_unicode_digest_auth(self, httpbin):
|
2014-04-26 15:06:51 +02:00
|
|
|
# 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,
|
2014-06-28 16:35:57 +02:00
|
|
|
httpbin.url + u'/digest-auth/auth/test/' + UNICODE)
|