MockGafaelfawr#

class rubin.gafaelfawr.MockGafaelfawr#

Bases: object

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

Methods Summary

create_token(username, *[, expires, 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_groups(groups)

Set the group information returned when listing all groups.

set_user_info(username, user_info)

Set the user information for a given user.

Methods Documentation

create_token(username, *, expires=None, 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.

  • expires (datetime | None, default: None) – If provided, sets the expiration time of the token.

  • scopes (Iterable[str] | None, 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:
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_groups(groups)#

Set the group information returned when listing all groups.

Parameters:

groups (GafaelfawrGroups) – Group information to return.

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 (GafaelfawrUserInfo | None) – User information to return for that user, or None to return a 404 error.

Return type:

None