Stub HTTP response for client.get()/client.post()/patch()/delete() REST calls.
Source code in datarobot_genai/drmcp/test_utils/stubs/stub_rest_response.py
| class StubRestResponse:
"""Stub HTTP response for client.get()/client.post()/patch()/delete() REST calls."""
def __init__(
self,
data: dict[str, Any] | None = None,
*,
text: str | None = None,
content: bytes | None = None,
status_code: int = 200,
):
self._data = data or {}
self._text = text
self._content = content
self.status_code = status_code
def json(self) -> dict[str, Any]:
return self._data
@property
def text(self) -> str:
if self._text is not None:
return self._text
return ""
@property
def content(self) -> bytes:
if self._content is not None:
return self._content
if self._data:
import json
return json.dumps(self._data).encode()
return b""
|