You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Fix --offline --multipart
, add more tests
This commit is contained in:
@@ -10,7 +10,7 @@ from httpie.context import Environment
|
||||
from httpie.status import ExitStatus
|
||||
from httpie.cli.exceptions import ParseError
|
||||
from utils import MockEnvironment, StdinBytesIO, http, HTTP_OK
|
||||
from fixtures import FILE_PATH, FILE_CONTENT
|
||||
from fixtures import FILE_PATH, FILE_CONTENT, FILE_PATH_ARG
|
||||
|
||||
import httpie
|
||||
|
||||
@@ -193,6 +193,48 @@ def test_offline():
|
||||
assert 'GET /foo' in r
|
||||
|
||||
|
||||
def test_offline_form():
|
||||
r = http(
|
||||
'--offline',
|
||||
'--form',
|
||||
'https://this-should.never-resolve/foo',
|
||||
'foo=bar'
|
||||
)
|
||||
assert 'POST /foo' in r
|
||||
assert 'foo=bar' in r
|
||||
|
||||
|
||||
def test_offline_json():
|
||||
r = http(
|
||||
'--offline',
|
||||
'https://this-should.never-resolve/foo',
|
||||
'foo=bar'
|
||||
)
|
||||
assert 'POST /foo' in r
|
||||
assert r.json == {'foo': 'bar'}
|
||||
|
||||
|
||||
def test_offline_multipart():
|
||||
r = http(
|
||||
'--offline',
|
||||
'--multipart',
|
||||
'https://this-should.never-resolve/foo',
|
||||
'foo=bar'
|
||||
)
|
||||
assert 'POST /foo' in r
|
||||
assert 'name="foo"' in r
|
||||
|
||||
|
||||
def test_offline_from_file():
|
||||
r = http(
|
||||
'--offline',
|
||||
'https://this-should.never-resolve/foo',
|
||||
f'@{FILE_PATH_ARG}'
|
||||
)
|
||||
assert 'POST /foo' in r
|
||||
assert FILE_CONTENT in r
|
||||
|
||||
|
||||
def test_offline_download():
|
||||
"""Absence of response should be handled gracefully with --download"""
|
||||
r = http(
|
||||
|
@@ -170,7 +170,6 @@ class TestMultipartFormDataFileUpload:
|
||||
'--verbose',
|
||||
'--multipart',
|
||||
'--chunked',
|
||||
# '--offline',
|
||||
HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
||||
'AAA=AAA',
|
||||
)
|
||||
@@ -179,6 +178,25 @@ class TestMultipartFormDataFileUpload:
|
||||
assert 'name="AAA"' in r # in request
|
||||
assert '"AAA": "AAA"', r # in response
|
||||
|
||||
def test_multipart_preserve_order(self, httpbin):
|
||||
r = http(
|
||||
'--form',
|
||||
'--offline',
|
||||
httpbin + '/post',
|
||||
'text_field=foo',
|
||||
f'file_field@{FILE_PATH_ARG}',
|
||||
)
|
||||
assert r.index('text_field') < r.index('file_field')
|
||||
|
||||
r = http(
|
||||
'--form',
|
||||
'--offline',
|
||||
httpbin + '/post',
|
||||
f'file_field@{FILE_PATH_ARG}',
|
||||
'text_field=foo',
|
||||
)
|
||||
assert r.index('text_field') > r.index('file_field')
|
||||
|
||||
|
||||
class TestRequestBodyFromFilePath:
|
||||
"""
|
||||
|
@@ -144,10 +144,9 @@ class StrCLIResponse(str, BaseCLIResponse):
|
||||
elif self.strip().startswith('{'):
|
||||
# Looks like JSON body.
|
||||
self._json = json.loads(self)
|
||||
elif (self.count('Content-Type:') == 1
|
||||
and 'application/json' in self):
|
||||
# Looks like a whole JSON HTTP message,
|
||||
# try to extract its body.
|
||||
elif self.count('Content-Type:') == 1:
|
||||
# Looks like a HTTP message,
|
||||
# try to extract JSON from its body.
|
||||
try:
|
||||
j = self.strip()[self.strip().rindex('\r\n\r\n'):]
|
||||
except ValueError:
|
||||
|
Reference in New Issue
Block a user