From b5a25353269a163d56d1836d52933b17f8343509 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Fri, 10 Jun 2016 15:16:21 +1000 Subject: [PATCH] Add a fixture method to add your own token data The fixture has an add_token_data method which lets you provide common token information, however there is no way to do more adanced tokens through that interface or control the service catalog. Rather than overload the simple method add a more low level method that will let you add a token that you created using keystoneauth1 fixtures yourself. Change-Id: I6351b5980d7d87b00caed351987bf46e30cdf036 --- keystonemiddleware/fixture.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/keystonemiddleware/fixture.py b/keystonemiddleware/fixture.py index 037339db..737a810b 100644 --- a/keystonemiddleware/fixture.py +++ b/keystonemiddleware/fixture.py @@ -71,7 +71,23 @@ class AuthTokenFixture(fixtures.Fixture): project_domain_name=project_domain_name) for role in role_list: token.add_role(name=role) - self._token_data[token_id] = token + self.add_token(token, token_id=token_id) + + @positional() + def add_token(self, token_data, token_id=None): + """Add an existing token to the middleware. + + :param token_data: token data to add to the fixture + :type token_data: dict + :param token_id: the token ID to add this token as + :type token_id: str + :returns: The token_id that the token was added as. + :rtype: str + """ + if not token_id: + token_id = uuid.uuid4().hex + self._token_data[token_id] = token_data + return token_id def fetch_token(self, token): """Low level replacement of fetch_token for AuthProtocol."""