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
RequestsMockobject to use.- Return type:
PreparedRequest | None
- globus_sdk.testing.register_response_set(set_id, rset, metadata=None)[source]¶
Register a new
ResponseSetobject.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
ResponseSetas 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
responseslibrary mock to use for response mocking, defaults to theresponsesdefault
- 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 aResponseSetused 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
responseslibrary mock to use for response mocking, defaults to theresponsesdefault
- 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', body=None, content_type=None, headers=None, json=None, status=200, stream=None, match=None, metadata=None)[source]¶
A mock response along with descriptive metadata to let a fixture “pass data forward” to the consuming test cases. (e.g. a
GET Taskfixture which shares thetask_idit uses with consumers via.metadata["task_id"])When initializing a
RegisteredResponse, you can usepathandserviceto describe a path on a Globus service rather than a full URL. Themetadatadata container is also globus-sdk specific. Most other parameters are wrappers overresponsesresponse characteristics.- Parameters:
path (str) – Path on the target service or full URL if service is null
service (t.Literal['auth', 'nexus', 'transfer', 'search', 'gcs', 'groups', 'timer', 'flows', 'compute'] | None) – A known service name like
"transfer"or"compute". This will be used to deduce the base URL onto whichpathshould be joinedmethod (t.Literal['GET', 'PUT', 'POST', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'CONNECT', 'TRACE']) – A string HTTP Method
headers (dict[str, str] | None) – HTTP headers for the response
json (None | list[t.Any] | dict[str, t.Any]) – A dict or list structure for a JSON response (mutex with
body)body (str | None) – A string response body (mutex with
json)status (int) – The HTTP status code for the response
content_type (str | None) – A Content-Type header value for the response
match (t.Sequence[t.Callable[..., tuple[bool, str]]] | None) – A tuple or list of
responsesmatchersmetadata (dict[str, t.Any] | None) – A dict of data to store on the response, which allows the usage site which declares the response to pass information forward to the site which activates and tests against the response.
- 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
responseslibrary- 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
responseslibrary- 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
ResponseSetas 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.