More unicode tests.

This commit is contained in:
Jakub Roztocil 2014-04-26 17:53:01 +02:00
parent 77dcd6e919
commit 3478cbd9ff
6 changed files with 8 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import os
from tests import TESTS_ROOT
from httpie.compat import bytes
def patharg(path):
@ -9,13 +10,11 @@ def patharg(path):
### Test files
FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file.txt')
FILE2_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file2.txt')
BIN_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file.bin')
FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'test.txt')
JSON_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'test.json')
BIN_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'test.bin')
FILE_PATH_ARG = patharg(FILE_PATH)
FILE2_PATH_ARG = patharg(FILE2_PATH)
BIN_FILE_PATH_ARG = patharg(BIN_FILE_PATH)
JSON_FILE_PATH_ARG = patharg(JSON_FILE_PATH)
@ -24,6 +23,9 @@ with open(FILE_PATH) as f:
# easily count occurrences also when embedded in JSON (where the new
# line would be escaped).
FILE_CONTENT = f.read().strip()
if isinstance(FILE_CONTENT, bytes):
# Python < 3.0
FILE_CONTENT = FILE_CONTENT.decode('utf8')
with open(BIN_FILE_PATH, 'rb') as f:
BIN_FILE_CONTENT = f.read()
with open(JSON_FILE_PATH, 'rb') as f:

View File

@ -1 +0,0 @@
__test_file_content__

View File

@ -1 +0,0 @@
__test_file_content__

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

1
tests/fixtures/test.txt vendored Normal file
View File

@ -0,0 +1 @@
some UTF8-encoded unicode text 太陽 by Jakub Roztočil

View File

@ -32,7 +32,7 @@ class TestRequestBodyFromFilePath:
def test_request_body_from_file_by_path(self):
r = http('--verbose', 'POST', httpbin('/post'), '@' + FILE_PATH_ARG)
assert HTTP_OK in r
assert FILE_CONTENT in r
assert FILE_CONTENT in r, r
assert '"Content-Type": "text/plain"' in r
def test_request_body_from_file_by_path_with_explicit_content_type(self):