MockGafaelfawr#

class rubin.gafaelfawr.MockGafaelfawr#

Bases: object

Mock for the parts of the Gafaelfawr API used by the client.

Methods Summary

create_token(username, *[, scopes])

Create a token for the given username.

fail_on(username, actions)

Configure the API to fail on requests for the given user.

install_routes(respx_mock, base_url)

Install the mock routes for the Gafaelfawr API.

set_user_info(username, user_info)

Set the user information for a given user.

Methods Documentation

create_token(username, *, scopes=None)#

Create a token for the given username.

This token will only be recognized by the same instance of the Gafaelfawr mock.

Parameters:
  • username (str) – Username the token is for.

  • scopes (Optional[Iterable[str]], default: None) – If provided, list of scopes to assign to the token. This is primarily needed if the client will call a privileged API endpoint.

Returns:

New Gafaelfawr token.

Return type:

str

fail_on(username, actions)#

Configure the API to fail on requests for the given user.

This can be used by test suites to test handling of Gafaelfawr failures.

Parameters:
  • username (str) – Username for which operations should fail.

  • actions (Union[MockGafaelfawrAction, Iterable[MockGafaelfawrAction]]) – An action or iterable of actions that should fail. Pass in the empty list to restore regular operations for this user.

Return type:

None

install_routes(respx_mock, base_url)#

Install the mock routes for the Gafaelfawr API.

Parameters:
  • respx_mock (Router) – Mock router to use to install routes.

  • base_url (str) – Base URL for the mock routes.

Return type:

None

set_user_info(username, user_info)#

Set the user information for a given user.

Parameters:
  • username (str) – Username for which to set a quota.

  • user_info (Optional[GafaelfawrUserInfo]) – User information to return for that user, or None to return a 404 error.

Return type:

None