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

roboto.testing.stub_roboto_client

Module Contents

RequestBodyMatcher

roboto.testing.stub_roboto_client.RequestBodyMatcher#View Source

StubResponse

roboto.testing.stub_roboto_client.StubResponse#View Source

StubRobotoClient

class roboto.testing.stub_roboto_client.StubRobotoClient#View Source

Bases: roboto.http.RobotoClient

A stub RobotoClient for unit testing that returns pre-configured responses for expected requests.

Pass caller_org_id to any expect_* method, or owner_org_id to expect_get, to match only requests that pass the same org ID for that argument. Left as None, an expectation matches whatever org ID the request passes, including none.

Usage

from roboto.testing import StubRobotoClient
from roboto.domain.datasets import Dataset, DatasetRecord
from roboto.time import utcnow

client = StubRobotoClient()
client.expect_get(
    "/v1/datasets/ds_123",
    response=DatasetRecord(
        dataset_id="ds_123",
        created=utcnow(),
        created_by="test@example.com",
        modified=utcnow(),
        modified_by="test@example.com",
        org_id="og_test",
    ),
)

dataset = Dataset.from_id("ds_123", roboto_client=client)
assert dataset.dataset_id == "ds_123"

StubRobotoClient.delete()

delete(path, caller_org_id=None, data=None, headers=None, idempotent=True, owner_org_id=None, query=None, retry_wait_fn=None, timeout=None)#View Source

Parameters

path collections.abc.Sequence[str] | str
caller_org_id Optional[str]
data Any
headers Optional[dict[str, str]]
idempotent bool
owner_org_id Optional[str]
query Optional[dict[str, Any]]
retry_wait_fn Optional[Any]
timeout Any

StubRobotoClient.expect_delete()

expect_delete(path, response, query=None, request_body_matcher=None, caller_org_id=None)#View Source

Parameters

path str
response StubResponse
query Optional[dict[str, Any]]
request_body_matcher Optional[RequestBodyMatcher]
caller_org_id Optional[str]

Return type

StubRobotoClient.expect_get()

expect_get(path, response, query=None, owner_org_id=None, caller_org_id=None)#View Source

Parameters

path str
response StubResponse
query Optional[dict[str, Any]]
owner_org_id Optional[str]
caller_org_id Optional[str]

Return type

StubRobotoClient.expect_patch()

expect_patch(path, response, query=None, request_body_matcher=None, caller_org_id=None)#View Source

Parameters

path str
response StubResponse
query Optional[dict[str, Any]]
request_body_matcher Optional[RequestBodyMatcher]
caller_org_id Optional[str]

Return type

StubRobotoClient.expect_post()

expect_post(path, response, query=None, request_body_matcher=None, caller_org_id=None)#View Source

Parameters

path str
response StubResponse
query Optional[dict[str, Any]]
request_body_matcher Optional[RequestBodyMatcher]
caller_org_id Optional[str]

Return type

StubRobotoClient.expect_put()

expect_put(path, response, query=None, request_body_matcher=None, caller_org_id=None)#View Source

Parameters

path str
response StubResponse
query Optional[dict[str, Any]]
request_body_matcher Optional[RequestBodyMatcher]
caller_org_id Optional[str]

Return type

StubRobotoClient.get()

get(path, caller_org_id=None, headers=None, idempotent=True, owner_org_id=None, query=None, retry_wait_fn=None, timeout=None)#View Source

Parameters

path collections.abc.Sequence[str] | str
caller_org_id Optional[str]
headers Optional[dict[str, str]]
idempotent bool
owner_org_id Optional[str]
query Optional[dict[str, Any]]
retry_wait_fn Optional[Any]
timeout Any

StubRobotoClient.patch()

patch(path, caller_org_id=None, data=None, headers=None, idempotent=True, owner_org_id=None, query=None, retry_wait_fn=None, timeout=None)#View Source

Parameters

path collections.abc.Sequence[str] | str
caller_org_id Optional[str]
data Any
headers Optional[dict[str, str]]
idempotent bool
owner_org_id Optional[str]
query Optional[dict[str, Any]]
retry_wait_fn Optional[Any]
timeout Any

StubRobotoClient.post()

post(path, caller_org_id=None, data=None, headers=None, idempotent=True, owner_org_id=None, query=None, retry_wait_fn=None, timeout=None)#View Source

Parameters

path collections.abc.Sequence[str] | str
caller_org_id Optional[str]
data Any
headers Optional[dict[str, str]]
idempotent bool
owner_org_id Optional[str]
query Optional[dict[str, Any]]
retry_wait_fn Optional[Any]
timeout Any

StubRobotoClient.put()

put(path, caller_org_id=None, data=None, headers=None, idempotent=True, owner_org_id=None, query=None, retry_wait_fn=None, timeout=None)#View Source

Parameters

path collections.abc.Sequence[str] | str
caller_org_id Optional[str]
data Any
headers Optional[dict[str, str]]
idempotent bool
owner_org_id Optional[str]
query Optional[dict[str, Any]]
retry_wait_fn Optional[Any]
timeout Any

StubRobotoClient.verify_no_pending_expectations()

verify_no_pending_expectations()#View Source

Verify that all registered expectations have been consumed.

Raises

AssertionError

If there are any pending expectations that were not consumed.

Return type

None

Was this page helpful?