---
sidebar:
  label: roboto.testing.fake_http_response_factory
  order: 0
title: roboto.testing.fake_http_response_factory
---
## Module Contents

### FakeHttpResponseFactory

```python
class roboto.testing.fake_http_response_factory.FakeHttpResponseFactory(
    url: str = 'https://test.roboto.ai',
    response_data: Any = '{}',
    status_code: int = 200,
    headers: Optional[dict[str, str]] = None,
)
```

`from roboto.testing import FakeHttpResponseFactory`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/testing/fake_http_response_factory.py#L16-L64)

Builder of fake HTTP responses, for tests that mock [`HttpClient`](/docs/reference/python-sdk/roboto/http/http_client#roboto.http.http_client.HttpClient).

Calling an instance ignores the call's arguments and builds a new [`HttpResponse`](/docs/reference/python-sdk/roboto/http/response#roboto.http.response.HttpResponse) from the constructor's arguments, with its body not yet read. Set an instance as the `side_effect` of a mocked request method, as in `http_client.get.side_effect = FakeHttpResponseFactory(url, {"foo": "bar"})`, and every call of that method returns such a response. The response is returned whatever its status: nothing raises the [`ClientError`](/docs/reference/python-sdk/roboto/exceptions/http#roboto.exceptions.http.ClientError) or [`ServerError`](/docs/reference/python-sdk/roboto/exceptions/http#roboto.exceptions.http.ServerError) that `HttpClient` raises for an error status.

**Parameters**

- **url** (`str`): URL the response reports it came from.
- **response_data** (`Any`): Value the response body holds, encoded with `json.dumps`. Defaults to the string `"{}"`, which the body holds as a JSON string, not an empty object.
- **status_code** (`int`): HTTP status code of the response.
- **headers** (`Optional[dict[str, str]]`): Headers of the response. `None` gives it none.
