Skip to content
Open
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
28 changes: 28 additions & 0 deletions tests/test_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,31 @@ def test_compress_file(httpbin_both):
'multipart/form-data; boundary=')
assert r.json['files'] == {}
assert FILE_CONTENT not in r


def test_compress_json_normal(httpbin_both):
# Test normal compression with one --compress flag where compression
# reduces size (should compress)
r = http(
'--compress',
httpbin_both + '/post',
'foo=bar',
)
assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new test conflicts with test_compress_skip_negative_ratio() earlier in the same file.

Both tests send the same small JSON payload (foo=bar) with a single --compress flag.

The existing test correctly expects no Content-Encoding header because compressing such a small payload increases its size. This new test expects deflate for the identical request, so the two assertions cannot both pass.

Could we use a larger, repetitive JSON payload here to make compression beneficial?

That would let this test cover the intended positive-compression case while preserving the existing negative-ratio behavior.

assert_decompressed_equal(r.json['data'], '{"foo": "bar"}')
assert r.json['json'] is None


def test_compress_raw_normal(httpbin_both):
# Test normal compression with one --compress flag where compression
# reduces size (should compress)
r = http(
'--raw',
FILE_CONTENT,
'--compress',
httpbin_both + '/post',
)
assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'
assert_decompressed_equal(r.json['data'], FILE_CONTENT.strip())
Loading