Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
- [Elena Lape](https://github.com/elenalape)
- [Rohit Sehgal](https://github.com/r0hi7)
- [Bartłomiej Jacak](https://github.com/bartekjacak)
- [Arif Uğur Çelik](https://github.com/augrclk)
18 changes: 18 additions & 0 deletions tests/test_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import base64
import zlib

import pytest

from .fixtures import FILE_PATH, FILE_CONTENT
from httpie.status import ExitStatus
from .utils import StdinBytesIO, http, HTTP_OK, MockEnvironment
Expand Down Expand Up @@ -53,6 +55,22 @@ def test_compress_skip_negative_ratio(httpbin_both):
assert r.json['json'] == {'foo': 'bar'}


@pytest.mark.parametrize('options, items, expected_body', [
([], ['foo=' + 'bar' * 1024], '{"foo": "' + 'bar' * 1024 + '"}'),
(['--raw', 'bar' * 1024], [], 'bar' * 1024),
], ids=['json', 'raw'])
def test_compress_positive_ratio(httpbin_both, options, items, expected_body):
r = http('--compress', *options, 'POST', httpbin_both + '/post', *items)

assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'
assert_decompressed_equal(r.json['data'], expected_body)

compressed_body = base64.b64decode(r.json['data'].split(',', 1)[1])
assert len(compressed_body) < len(expected_body.encode())
assert int(r.json['headers']['Content-Length']) == len(compressed_body)


def test_compress_force_with_negative_ratio(httpbin_both):
r = http(
'--compress',
Expand Down
Loading