Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.testing.fake_http_response_factory

Module Contents

FakeHttpResponseFactory

class roboto.testing.fake_http_response_factory.FakeHttpResponseFactory(url='https://test.roboto.ai', response_data='{}', status_code=200, headers=None)#View Source

A factory for creating fake HTTP responses, for use with the roboto.http.HttpClient.

Usage

import contextlib
import unittest.mock
from roboto.http import HttpClient, FakeHttpResponseFactory
mock_http_client = unittest.mock.create_autospec(HttpClient, instance=True)
with contextlib.ExitStack() as stack:
    http_get_mock = stack.enter_context(unittest.mock.patch.object(mock_http_client, "get"))
    http_get_mock.side_effect = FakeHttpResponseFactory(
        "https://example.com",
        {"foo": "bar"},
        status_code=200,
        headers={"Content-Type": "application/json"},
    )

Parameters

url str
response_data Any
status_code int
headers Optional[dict[str, str]]

Was this page helpful?