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: RequestsMock | None = None) PreparedRequest | None[source]#

Get the last request which was received, or None if there were no requests.

Parameters:

requests_mock (responses.RequestsMock) – A non-default RequestsMock object to use.

globus_sdk._testing.register_response_set(set_id: Any, rset: ResponseSet | dict[str, dict[str, Any]], metadata: dict[str, Any] | None = None) ResponseSet[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 (dict or ResponseSet) – The response set to register

  • metadata (dict, optional) – 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.

globus_sdk._testing.get_response_set(set_id: Any) ResponseSet[source]#

Lookup a ResponseSet as in load_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.

globus_sdk._testing.load_response_set(set_id: Any, *, requests_mock: RequestsMock | None = None) ResponseSet[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 (responses.RequestsMock, optional) – A responses library mock to use for response mocking, defaults to the responses default

globus_sdk._testing.load_response(set_id: Any, *, case: str = 'default', requests_mock: RequestsMock | None = None) RegisteredResponse | ResponseList[source]#

Optionally lookup and activate an individual response. If given a RegisteredResponse, activate it, otherwise the first argument is an ID of a ResponseSet used for lookup. By default, looks for the response registered under case="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, optional) – The name of a case within the response set to load, ignoring all other registered mocks in the response set

  • requests_mock (responses.RequestsMock, optional) – A responses library mock to use for response mocking, defaults to the responses default

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 (type[GlobusAPIError]) – The class of the error to construct. Defaults to GlobusAPIError.

  • http_status (int) – The HTTP status code to use in the response.

  • body (bytes | str | dict) – The body of the response. If a dict, will be JSON-encoded.

  • method (str, optional) – The HTTP method to set on the underlying request.

  • response_headers (dict, optional) – The headers of the response.

  • request_headers (dict, optional) – The headers of the request.

  • response_encoding (str, optional) – The encoding to use for the response body.

  • url (str, optional) – The URL to set on the underlying request.

Classes#

class globus_sdk._testing.RegisteredResponse(*, path: str, service: str | None = None, method: str = 'GET', headers: dict[str, str] | None = None, metadata: dict[str, Any] | None = None, json: None | list[Any] | dict[str, Any] = None, body: str | None = None, **kwargs: Any)[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 the task_id it uses with consumers via .metadata["task_id"])

add(*, requests_mock: RequestsMock | None = None) RegisteredResponse[source]#

Activate the response, adding it to a mocked requests object.

Parameters:

requests_mock (responses.RequestsMock, optional) – The mocked requests object to use. Defaults to the default provided by the responses library

replace(*, requests_mock: RequestsMock | None = None) RegisteredResponse[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 (responses.RequestsMock, optional) – The mocked requests object to use. Defaults to the default provided by the responses library

class globus_sdk._testing.ResponseList(*data: RegisteredResponse, metadata: dict[str, Any] | None = 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: dict[str, Any] | None = None, **kwargs: RegisteredResponse | ResponseList)[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.