mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2026-04-30 04:30:19 +00:00
Remove setup.sh in favor of skyvern CLI (#4737)
This commit is contained in:
parent
08d3b04d14
commit
155c07f8be
77 changed files with 12358 additions and 10 deletions
46
tests/unit/workflow/test_http_request_block.py
Normal file
46
tests/unit/workflow/test_http_request_block.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import json
|
||||
|
||||
|
||||
class TestJsonTextParsingEquivalence:
|
||||
"""Prove JSON/text parsing behavior matches aiohttp semantics.
|
||||
|
||||
The HttpRequestBlock parses responses using:
|
||||
try:
|
||||
response_body = json.loads(response_bytes.decode("utf-8"))
|
||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||
response_body = response_bytes.decode("utf-8", errors="replace")
|
||||
|
||||
This should behave equivalently to aiohttp's:
|
||||
try:
|
||||
response_body = await response.json()
|
||||
except (aiohttp.ContentTypeError, Exception):
|
||||
response_body = await response.text()
|
||||
"""
|
||||
|
||||
def _parse_response(self, response_bytes: bytes) -> str | dict | list:
|
||||
try:
|
||||
return json.loads(response_bytes.decode("utf-8"))
|
||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||
return response_bytes.decode("utf-8", errors="replace")
|
||||
|
||||
def test_valid_json_utf8(self) -> None:
|
||||
data = {"key": "value", "number": 42, "unicode": "日本語"}
|
||||
response_bytes = json.dumps(data).encode("utf-8")
|
||||
result = self._parse_response(response_bytes)
|
||||
assert result == data
|
||||
|
||||
def test_invalid_json_returns_text(self) -> None:
|
||||
response_bytes = b"not json, just text"
|
||||
result = self._parse_response(response_bytes)
|
||||
assert result == "not json, just text"
|
||||
|
||||
def test_non_utf8_bytes_handled_gracefully(self) -> None:
|
||||
response_bytes = "café".encode("latin-1") # b'caf\xe9'
|
||||
result = self._parse_response(response_bytes)
|
||||
assert "caf" in result
|
||||
assert isinstance(result, str)
|
||||
|
||||
def test_empty_response(self) -> None:
|
||||
response_bytes = b""
|
||||
result = self._parse_response(response_bytes)
|
||||
assert result == ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue