8000 Helper for reading the entirety of a streamed request · stripe/stripe-python@d5d504d · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit d5d504d

Browse files
Helper for reading the entirety of a streamed request
1 parent c4bc5d2 commit d5d504d

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

stripe/_stripe_response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ def __init__(
6060

6161
def stream(self) -> AsyncIterable[bytes]:
6262
return self._stream
63+
64+
async def read(self) -> bytes:
65+
return b"".join([chunk async for chunk in self._stream])

tests/test_integration.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,8 @@ def do_request(self, n):
446446
self.setup_mock_server(MockServerRequestHandler)
447447
stripe.upload_api_base = "http://localhost:%s" % self.mock_server_port
448448

449-
chunks = []
450449
result = await stripe.Quote.pdf_async("qt_123")
451-
async for chunk in result.stream():
452-
chunks.append(str(chunk, "utf-8"))
453-
454-
MockServerRequestHandler.get_requests(1)
455-
456-
assert "".join(chunks) == "hello"
450+
assert str(await result.read(), "utf-8") == "hello"
457451

458452
@pytest.mark.anyio
459453
async def test_async_httpx_stream_error(self):

0 commit comments

Comments
 (0)
0