You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-12-26 00:31:53 +02:00
Fix encoding error with non-prettified encoded responses
Removed `--format-option response.as` an promote `--response-as`: using the format option would be misleading as it is now also used by non-prettified responses.
This commit is contained in:
@@ -377,9 +377,6 @@ class TestFormatOptions:
|
||||
'indent': 10,
|
||||
'format': True
|
||||
},
|
||||
'response': {
|
||||
'as': "''",
|
||||
},
|
||||
'xml': {
|
||||
'format': True,
|
||||
'indent': 2,
|
||||
@@ -399,9 +396,6 @@ class TestFormatOptions:
|
||||
'indent': 4,
|
||||
'format': True
|
||||
},
|
||||
'response': {
|
||||
'as': "''",
|
||||
},
|
||||
'xml': {
|
||||
'format': True,
|
||||
'indent': 2,
|
||||
@@ -423,9 +417,6 @@ class TestFormatOptions:
|
||||
'indent': 4,
|
||||
'format': True
|
||||
},
|
||||
'response': {
|
||||
'as': "''",
|
||||
},
|
||||
'xml': {
|
||||
'format': True,
|
||||
'indent': 2,
|
||||
@@ -444,7 +435,6 @@ class TestFormatOptions:
|
||||
(
|
||||
[
|
||||
'--format-options=json.indent:2',
|
||||
'--format-options=response.as:application/xml; charset=utf-8',
|
||||
'--format-options=xml.format:false',
|
||||
'--format-options=xml.indent:4',
|
||||
'--unsorted',
|
||||
@@ -459,9 +449,6 @@ class TestFormatOptions:
|
||||
'indent': 2,
|
||||
'format': True
|
||||
},
|
||||
'response': {
|
||||
'as': 'application/xml; charset=utf-8',
|
||||
},
|
||||
'xml': {
|
||||
'format': False,
|
||||
'indent': 4,
|
||||
@@ -483,9 +470,6 @@ class TestFormatOptions:
|
||||
'indent': 2,
|
||||
'format': True
|
||||
},
|
||||
'response': {
|
||||
'as': "''",
|
||||
},
|
||||
'xml': {
|
||||
'format': True,
|
||||
'indent': 2,
|
||||
@@ -508,9 +492,6 @@ class TestFormatOptions:
|
||||
'indent': 2,
|
||||
'format': True
|
||||
},
|
||||
'response': {
|
||||
'as': "''",
|
||||
},
|
||||
'xml': {
|
||||
'format': True,
|
||||
'indent': 2,
|
||||
|
||||
@@ -142,31 +142,29 @@ def test_GET_encoding_detection_from_content(encoding):
|
||||
assert 'Financiën' in r
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pretty', PRETTY_MAP.keys())
|
||||
@responses.activate
|
||||
def test_GET_encoding_provided_by_format_options():
|
||||
def test_GET_encoding_provided_by_option(pretty):
|
||||
responses.add(responses.GET,
|
||||
URL_EXAMPLE,
|
||||
body='▒▒▒'.encode('johab'),
|
||||
content_type='text/plain')
|
||||
r = http('--format-options', 'response.as:text/plain; charset=johab',
|
||||
'GET', URL_EXAMPLE)
|
||||
assert '▒▒▒' in r
|
||||
body='卷首'.encode('big5'),
|
||||
content_type='text/plain; charset=utf-8')
|
||||
args = ('--pretty=' + pretty, 'GET', URL_EXAMPLE)
|
||||
|
||||
# Encoding provided by Content-Type is incorrect, thus it should print something unreadable.
|
||||
r = http(*args)
|
||||
assert '卷首' not in r
|
||||
|
||||
@responses.activate
|
||||
def test_GET_encoding_provided_by_shortcut_option():
|
||||
responses.add(responses.GET,
|
||||
URL_EXAMPLE,
|
||||
body='▒▒▒'.encode('johab'),
|
||||
content_type='text/plain')
|
||||
r = http('--response-as', 'text/plain; charset=johab',
|
||||
'GET', URL_EXAMPLE)
|
||||
assert '▒▒▒' in r
|
||||
# Specifying the correct encoding, both in short & long versions, should fix it.
|
||||
r = http('--response-as', 'charset=big5', *args)
|
||||
assert '卷首' in r
|
||||
r = http('--response-as', 'text/plain; charset=big5', *args)
|
||||
assert '卷首' in r
|
||||
|
||||
|
||||
@pytest.mark.parametrize('encoding', ENCODINGS)
|
||||
@responses.activate
|
||||
def test_GET_encoding_provided_by_empty_shortcut_option_should_use_content_detection(encoding):
|
||||
def test_GET_encoding_provided_by_empty_option_should_use_content_detection(encoding):
|
||||
body = f'<?xml version="1.0" encoding="{encoding.upper()}"?>\n<c>Financiën</c>'
|
||||
responses.add(responses.GET,
|
||||
URL_EXAMPLE,
|
||||
|
||||
@@ -87,29 +87,9 @@ def test_invalid_xml(file):
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_content_type_from_format_options_argument():
|
||||
def test_content_type_from_option():
|
||||
"""Test XML response with a incorrect Content-Type header.
|
||||
Using the --format-options to force the good one.
|
||||
"""
|
||||
responses.add(responses.GET, URL_EXAMPLE, body=XML_DATA_RAW,
|
||||
content_type='plain/text')
|
||||
args = ('--format-options', 'response.as:application/xml',
|
||||
URL_EXAMPLE)
|
||||
|
||||
# Ensure the option is taken into account only for responses.
|
||||
# Request
|
||||
r = http('--offline', '--raw', XML_DATA_RAW, *args)
|
||||
assert XML_DATA_RAW in r
|
||||
|
||||
# Response
|
||||
r = http(*args)
|
||||
assert XML_DATA_FORMATTED in r
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_content_type_from_shortcut_argument():
|
||||
"""Test XML response with a incorrect Content-Type header.
|
||||
Using the --format-options shortcut to force the good one.
|
||||
Using the --response-as option to force the good one.
|
||||
"""
|
||||
responses.add(responses.GET, URL_EXAMPLE, body=XML_DATA_RAW,
|
||||
content_type='text/plain')
|
||||
@@ -126,9 +106,9 @@ def test_content_type_from_shortcut_argument():
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_content_type_from_incomplete_format_options_argument():
|
||||
def test_content_type_from_option_incomplete():
|
||||
"""Test XML response with a incorrect Content-Type header.
|
||||
Using the --format-options to use a partial Content-Type without mime type.
|
||||
Using the --response-as option to set a partial Content-Type without mime type.
|
||||
"""
|
||||
responses.add(responses.GET, URL_EXAMPLE, body=XML_DATA_RAW,
|
||||
content_type='text/plain')
|
||||
|
||||
Reference in New Issue
Block a user