Skip to content

Commit 6499604

Browse files
committed
Test for ProtobufPayload
1 parent 79ed7f8 commit 6499604

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from io import BytesIO
2+
from unittest import mock
3+
4+
from neptune_api.proto.neptune_pb.api.v1.model.requests_pb2 import ProtoGetTimeseriesBucketsRequest
5+
from neptune_query.internal.retrieval.util import ProtobufPayload
6+
from neptune_query.types import File
7+
8+
9+
@mock.patch("neptune_query.internal.retrieval.util.BytesIO", wraps=BytesIO)
10+
def test_bytesio_recreation_on_retry(mock_bytesio):
11+
"""Test that BytesIO instance is recreated when the API call is retried."""
12+
13+
file = ProtobufPayload(ProtoGetTimeseriesBucketsRequest())
14+
15+
# Verify file is File as expected
16+
assert isinstance(file, File)
17+
18+
# Read file's payload two times to simulate two API calls:
19+
read1 = file.payload.read()
20+
read2 = file.payload.read()
21+
22+
# Verify that both reads return the same content
23+
# If the same BytesIO instance was used, the second read would return b''
24+
assert read1 == read2
25+
assert read2 != b''
26+
27+
# Verify BytesIO was called twice
28+
assert mock_bytesio.call_count == 2

0 commit comments

Comments
 (0)