Skip to content

Commit

Permalink
Helper for reading the entirety of a streamed request
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Feb 14, 2024
1 parent c4bc5d2 commit d5d504d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 3 additions & 0 deletions stripe/_stripe_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ def __init__(

def stream(self) -> AsyncIterable[bytes]:
return self._stream

async def read(self) -> bytes:
return b"".join([chunk async for chunk in self._stream])
8 changes: 1 addition & 7 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,8 @@ def do_request(self, n):
self.setup_mock_server(MockServerRequestHandler)
stripe.upload_api_base = "http://localhost:%s" % self.mock_server_port

chunks = []
result = await stripe.Quote.pdf_async("qt_123")
async for chunk in result.stream():
chunks.append(str(chunk, "utf-8"))

MockServerRequestHandler.get_requests(1)

assert "".join(chunks) == "hello"
assert str(await result.read(), "utf-8") == "hello"

@pytest.mark.anyio
async def test_async_httpx_stream_error(self):
Expand Down

0 comments on commit d5d504d

Please sign in to comment.