-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steve Bunting
committed
Jul 9, 2024
1 parent
6b0f48d
commit aa703ae
Showing
4 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import httpx | ||
from pytest_httpserver import HTTPServer | ||
|
||
from supergood.api import Api | ||
|
||
|
||
class TestHttpx: | ||
def test_httpx_streaming(self, httpserver: HTTPServer, supergood_client): | ||
raw_response = 'data: {"valid": "json"}\n\ndata: [DONE]\n\n' | ||
httpserver.expect_request("/stream").respond_with_data( | ||
response_data=raw_response | ||
) | ||
resp = b"" | ||
with httpx.stream("GET", httpserver.url_for("/stream")) as s: | ||
for data in s.iter_bytes(chunk_size=1): | ||
resp += data | ||
assert resp.decode("utf-8") == raw_response | ||
supergood_client.flush_cache() | ||
args = Api.post_events.call_args[0][0] | ||
# verify 2 entries, one each for each response field | ||
assert len(args[0]["response"]["body"]) == 2 | ||
# verifies valid JSON is indexible | ||
assert args[0]["response"]["body"][0]["data"][0]["valid"] == "json" | ||
supergood_client.kill() |