# keystoneauth1.fixture.plugin module

class keystoneauth1.fixture.plugin.LoadingFixture(token=None, endpoint=None, user_id=None, project_id=None)

  Bases: `Fixture`

  A fixture that will stub out all plugin loading calls.

  When using keystoneauth plugins loaded from config, CLI or elsewhere it is often difficult to handle the plugin parts in tests because we don’t have a reasonable default.

  This fixture will create a `TestPlugin` that will be returned for all calls to plugin loading so you can simply bypass the authentication steps and return something well known.

  Parameters:

    - token (str) – The token to include in authenticated requests.

    - endpoint (str) – The endpoint to respond to service lookups with.

    - user_id (str) – The user_id to report for the authenticated user.

    - project_id (str) – The project_id to report for the authenticated user.

  MOCK_POINT = 'keystoneauth1.loading.base.get_plugin_loader'
  __annotations_cache__ = {}
  __doc__ = "A fixture that will stub out all plugin loading calls.\n\nWhen using keystoneauth plugins loaded from config, CLI or elsewhere it is\noften difficult to handle the plugin parts in tests because we don't have a\nreasonable default.\n\nThis fixture will create a :py:class:`TestPlugin` that will be\nreturned for all calls to plugin loading so you can simply bypass the\nauthentication steps and return something well known.\n\n:param str token: The token to include in authenticated requests.\n:param str endpoint: The endpoint to respond to service lookups with.\n:param str user_id: The user_id to report for the authenticated user.\n:param str project_id: The project_id to report for the authenticated user.\n"
  __firstlineno__ = 110
  __init__(token=None, endpoint=None, user_id=None, project_id=None)
  __module__ = 'keystoneauth1.fixture.plugin'
  __static_attributes__ = ('endpoint', 'project_id', 'token', 'user_id')
  create_plugin()
  get_endpoint(path=None, **kwargs)

    Utility function to get the endpoint the plugin would return.

    This function is provided as a convenience so you can do comparisons in your tests. Overriding it will not affect the endpoint returned by the plugin.

    Parameters:

      path (str) – The path to append to the plugin endpoint.

  get_plugin_loader(auth_type)
  setUp()

    Prepare the Fixture for use.

    This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.

    After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).

    Raises:

      MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.

    Returns:

      None.

    Changed in 1.3:

      The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.

    Changed in 1.3.1:

      BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.

class keystoneauth1.fixture.plugin.TestPlugin(token=None, endpoint=None, user_id=None, project_id=None)

  Bases: `BaseAuthPlugin`

  A simple plugin that returns what you gave it for testing.

  When testing services that use authentication plugins you often want to stub out the authentication calls and focus on the important part of your service. This plugin acts like a real keystoneauth plugin and returns known standard values without having to stub out real keystone responses.

  Note that this plugin is a BaseAuthPlugin and not a BaseIdentityPlugin. This means it implements the basic plugin interface that services should be using but does not implement get_auth_ref. get_auth_ref should not be relied upon by services because a user could always configure the service to use a non-keystone auth.

  Parameters:

    - token (str) – The token to include in authenticated requests.

    - endpoint (str) – The endpoint to respond to service lookups with.

    - user_id (str) – The user_id to report for the authenticated user.

    - project_id (str) – The project_id to report for the authenticated user.

  __annotations_cache__ = {'_discovery_cache': 'dict[str, discover.Discover]'}
  __doc__ = 'A simple plugin that returns what you gave it for testing.\n\nWhen testing services that use authentication plugins you often want to\nstub out the authentication calls and focus on the important part of your\nservice. This plugin acts like a real keystoneauth plugin and returns known\nstandard values without having to stub out real keystone responses.\n\nNote that this plugin is a BaseAuthPlugin and not a BaseIdentityPlugin.\nThis means it implements the basic plugin interface that services should be\nusing but does not implement get_auth_ref. get_auth_ref should not be\nrelied upon by services because a user could always configure the service\nto use a non-keystone auth.\n\n:param str token: The token to include in authenticated requests.\n:param str endpoint: The endpoint to respond to service lookups with.\n:param str user_id: The user_id to report for the authenticated user.\n:param str project_id: The project_id to report for the authenticated user.\n'
  __firstlineno__ = 40
  __init__(token=None, endpoint=None, user_id=None, project_id=None)
  __module__ = 'keystoneauth1.fixture.plugin'
  __static_attributes__ = ('endpoint', 'project_id', 'token', 'user_id')
  _discovery_cache: dict[str, Discover]
  auth_type = 'test_plugin'
  get_endpoint(session, **kwargs)

    Return an endpoint for the client.

    There are no required keyword arguments to `get_endpoint` as a plugin implementation should use best effort with the information available to determine the endpoint. However there are certain standard options that will be generated by the clients and should be used by plugins:

    - `service_type`: what sort of service is required.

    - `service_name`: the name of the service in the catalog.

    - `interface`: what visibility the endpoint should have.

    - `region_name`: the region the endpoint exists in.

    Parameters:

      - session (keystoneauth1.session.Session) – The session object that the auth_plugin belongs to.

      - kwargs – Ignored.

    Returns:

      The base URL that will be used to talk to the required service or None if not available.

    Return type:

      string

  get_project_id(session)

    Return the project id that we are authenticated to.

    Wherever possible the project id should be inferred from the token however there are certain URLs and other places that require access to the currently authenticated project id.

    Parameters:

      session (keystoneauth1.session.Session) – A session object so the plugin can make HTTP calls.

    Returns:

      A project identifier or None if one is not available.

    Return type:

      str

  get_token(session)

    Obtain a token.

    How the token is obtained is up to the plugin. If it is still valid it may be re-used, retrieved from cache or invoke an authentication request against a server.

    Returning None will indicate that no token was able to be retrieved.

    This function is misplaced as it should only be required for auth plugins that use the ‘X-Auth-Token’ header. However due to the way plugins evolved this method is required and often called to trigger an authentication request on a new plugin.

    When implementing a new plugin it is advised that you implement this method, however if you don’t require the ‘X-Auth-Token’ header override the get_headers method instead.

    Parameters:

      session (keystoneauth1.session.Session) – A session object so the plugin can make HTTP calls.

    Returns:

      A token to use.

    Return type:

      string

  get_user_id(session)

    Return a unique user identifier of the plugin.

    Wherever possible the user id should be inferred from the token however there are certain URLs and other places that require access to the currently authenticated user id.

    Parameters:

      session (keystoneauth1.session.Session) – A session object so the plugin can make HTTP calls.

    Returns:

      A user identifier or None if one is not available.

    Return type:

      str

  invalidate()

    Invalidate the current authentication data.

    This should result in fetching a new token on next call.

    A plugin may be invalidated if an Unauthorized HTTP response is returned to indicate that the token may have been revoked or is otherwise now invalid.

    Returns:

      True if there was something that the plugin did to invalidate. This means that it makes sense to try again. If nothing happens returns False to indicate give up.

    Return type:

      bool

class keystoneauth1.fixture.plugin._TestPluginLoader(plugin)

  Bases: `BaseLoader`[`TestPlugin`]

  __abstractmethods__ = frozenset({})
  __annotate_func__ = None
  __annotations_cache__ = {}
  __doc__ = None
  __firstlineno__ = 98
  __init__(plugin)
  __module__ = 'keystoneauth1.fixture.plugin'
  __orig_bases__ = (keystoneauth1.loading.base.BaseLoader[keystoneauth1.fixture.plugin.TestPlugin],)
  __parameters__ = ()
  __static_attributes__ = ('_plugin',)
  _abc_impl = <_abc._abc_data object>
  create_plugin(**kwargs)

    Create a plugin from the options available for the loader.

    Given the options that were specified by the loader create an appropriate plugin. You can override this function in your loader.

    This used to be specified by providing the plugin_class property and this is still supported, however specifying a property didn’t let you choose a plugin type based upon the options that were presented.

    Override this function if you wish to return different plugins based on the options presented, otherwise you can simply provide the plugin_class property.

    Added 2.9

  get_options()

    Return the list of parameters associated with the auth plugin.

    This list may be used to generate CLI or config arguments.

    Returns:

      A list of Param objects describing available plugin parameters.

    Return type:

      list

keystoneauth1.fixture.plugin._format_endpoint(endpoint, **kwargs)

this page last updated: 2026-03-25 21:01:07

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug