Return None for missing trust_id in fixture

If the trust_id is unset it raises a KeyError. This is unusual from a
python perspective (if nothing else it should be AttributeError) and
different to all the other attributes of the fixture.

Return None if no trust_id is set on the fixture.

Change-Id: I15d33d77027a188fa47df18387c4610908f8e2d2
This commit is contained in:
Jamie Lennox
2015-03-24 21:29:36 +11:00
parent 26230c5a7e
commit 161c869c6c
2 changed files with 3 additions and 1 deletions

View File

@@ -166,7 +166,7 @@ class Token(dict):
@property
def trust_id(self):
return self.root.setdefault('trust', {})['id']
return self.root.setdefault('trust', {}).get('id')
@trust_id.setter
def trust_id(self, value):

View File

@@ -35,6 +35,7 @@ class V2TokenTests(utils.TestCase):
self.assertEqual(user_id, token['access']['user']['id'])
self.assertEqual(user_name, token.user_name)
self.assertEqual(user_name, token['access']['user']['name'])
self.assertIsNone(token.trust_id)
def test_tenant_scoped(self):
tenant_id = uuid.uuid4().hex
@@ -48,6 +49,7 @@ class V2TokenTests(utils.TestCase):
self.assertEqual(tenant_name, token.tenant_name)
tn = token['access']['token']['tenant']['name']
self.assertEqual(tenant_name, tn)
self.assertIsNone(token.trust_id)
def test_trust_scoped(self):
trust_id = uuid.uuid4().hex