Skip to content

Commit 715fd1c

Browse files
committed
test: Size KVS file-like values above the compression threshold
1 parent 6717ac0 commit 715fd1c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tests/unit/test_key_value_store.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from werkzeug import Request, Response
1010

1111
from apify_client import ApifyClient, ApifyClientAsync
12+
from apify_client._consts import MIN_COMPRESSION_SIZE
1213

1314
if TYPE_CHECKING:
1415
from collections.abc import Callable
@@ -20,20 +21,25 @@
2021
_MOCKED_KVS_ID = 'test_kvs_id'
2122
_RECORD_PATH = f'/v2/key-value-stores/{_MOCKED_KVS_ID}/records/f'
2223

24+
# The client compresses only bodies of at least `MIN_COMPRESSION_SIZE` bytes, so the value is padded past that
25+
# to keep the compression axis meaningful. A shorter one would go out uncompressed under either algorithm.
26+
_TEXT_VALUE = 'buffer data' + '.' * MIN_COMPRESSION_SIZE
27+
_BYTES_VALUE = _TEXT_VALUE.encode('utf-8')
28+
2329

2430
class DuckTypedReader:
2531
"""A file-like object that is not an `io.IOBase`, so only duck-typed detection picks it up."""
2632

2733
def read(self) -> bytes:
28-
return b'buffer data'
34+
return _BYTES_VALUE
2935

3036

3137
# The values are built by a factory because reading consumes them, and each case runs once per compression
3238
# algorithm. Each case is (value factory, expected uploaded body, expected content type).
3339
_FILE_LIKE_VALUE_CASES = [
34-
pytest.param(lambda: io.BytesIO(b'buffer data'), b'buffer data', 'application/octet-stream', id='bytes io'),
35-
pytest.param(lambda: io.StringIO('buffer data'), b'buffer data', 'text/plain; charset=utf-8', id='string io'),
36-
pytest.param(DuckTypedReader, b'buffer data', 'application/octet-stream', id='duck-typed reader'),
40+
pytest.param(lambda: io.BytesIO(_BYTES_VALUE), _BYTES_VALUE, 'application/octet-stream', id='bytes io'),
41+
pytest.param(lambda: io.StringIO(_TEXT_VALUE), _BYTES_VALUE, 'text/plain; charset=utf-8', id='string io'),
42+
pytest.param(DuckTypedReader, _BYTES_VALUE, 'application/octet-stream', id='duck-typed reader'),
3743
]
3844

3945

0 commit comments

Comments
 (0)