Warning
This component is an alpha. Interfaces may change outside of the normal semver policy.
_testing Reference#
Functions#
- globus_sdk._testing.get_last_request(*, requests_mock=None)[source]#
Get the last request which was received, or None if there were no requests.
- Parameters:
requests_mock (RequestsMock | None) – A non-default
RequestsMock
object to use.- Return type:
PreparedRequest | None
- globus_sdk._testing.register_response_set(set_id, rset, metadata=None)[source]#
Register a new
ResponseSet
object.The response set may be specified as a dict or a ResponseSet object.
- Parameters:
set_id (Any) – The ID used to retrieve the response set later
rset (ResponseSet | dict[str, dict[str, Any]]) – The response set to register
metadata (dict[str, Any] | None) – Metadata dict to assign to the response set when it is specified as a dict. If the response set is an object, this argument is ignored.
- Return type:
- globus_sdk._testing.get_response_set(set_id)[source]#
Lookup a
ResponseSet
as inload_response_set
, but without activating it.- Parameters:
set_id (Any) – The ID used to retrieve the response set. Typically a string, but could be any key used to register a response set.
- Return type:
- globus_sdk._testing.load_response_set(set_id, *, requests_mock=None)[source]#
Optionally lookup a response set and activate all of its responses. If passed a
ResponseSet
, activate it, otherwise the first argument is an ID used for lookup.- Parameters:
set_id (Any) – The ID used to retrieve the response set. Typically a string, but could be any key used to register a response set.
requests_mock (RequestsMock | None) – A
responses
library mock to use for response mocking, defaults to theresponses
default
- Return type:
- globus_sdk._testing.load_response(set_id, *, case='default', requests_mock=None)[source]#
Optionally lookup and activate an individual response. If given a
RegisteredResponse
, activate it, otherwise the first argument is an ID of aResponseSet
used for lookup. By default, looks for the response registered undercase="default"
.- Parameters:
set_id (Any) – The ID used to retrieve the response set. Typically a string, but could be any key used to register a response set.
case (str) – The name of a case within the response set to load, ignoring all other registered mocks in the response set
requests_mock (RequestsMock | None) – A
responses
library mock to use for response mocking, defaults to theresponses
default
- Return type:
- globus_sdk._testing.construct_error(*, http_status: int, body: bytes | str | Dict[str, Any], method: str = 'GET', response_headers: Dict[str, str] | None = None, request_headers: Dict[str, str] | None = None, response_encoding: str = 'utf-8', url: str = 'https://bogus-url/') GlobusAPIError [source]#
- globus_sdk._testing.construct_error(*, http_status: int, error_class: type[E], body: bytes | str | Dict[str, Any], method: str = 'GET', response_headers: Dict[str, str] | None = None, request_headers: Dict[str, str] | None = None, response_encoding: str = 'utf-8', url: str = 'https://bogus-url/') E
Given parameters for an HTTP response, construct a GlobusAPIError and return it.
- Parameters:
error_class – The class of the error to construct. Defaults to GlobusAPIError.
http_status – The HTTP status code to use in the response.
body – The body of the response. If a dict, will be JSON-encoded.
method – The HTTP method to set on the underlying request.
response_headers – The headers of the response.
request_headers – The headers of the request.
response_encoding – The encoding to use for the response body.
url – The URL to set on the underlying request.
Classes#
- class globus_sdk._testing.RegisteredResponse(*, path, service=None, method='GET', headers=None, metadata=None, json=None, body=None, **kwargs)[source]#
A mock response along with descriptive metadata to let a fixture “pass data forward” to the consuming test cases. (e.g. a
GET Task
fixture which shares thetask_id
it uses with consumers via.metadata["task_id"]
)- add(*, requests_mock=None)[source]#
Activate the response, adding it to a mocked requests object.
- Parameters:
requests_mock (RequestsMock | None) – The mocked requests object to use. Defaults to the default provided by the
responses
library- Return type:
- replace(*, requests_mock=None)[source]#
Activate the response, adding it to a mocked requests object and replacing any existing response for the particular path and method.
- Parameters:
requests_mock (RequestsMock | None) – The mocked requests object to use. Defaults to the default provided by the
responses
library- Return type:
- class globus_sdk._testing.ResponseList(*data, metadata=None)[source]#
A series of unnamed responses, meant to be used and referred to as a single case within a ResponseSet.
This can be stored in a
ResponseSet
as a case, describing a series of responses registered to a specific name (e.g. to describe a paginated API).
- class globus_sdk._testing.ResponseSet(metadata=None, **kwargs)[source]#
A collection of mock responses, potentially all meant to be activated together (
.activate_all()
), or to be individually selected as options/alternatives (.activate("case_foo")
).On init, this implicitly sets the parent of any response objects to this response set. On register() it does not do so automatically.