Add remove_service to token fixtures

SDK is going to start using these Token fixtures to programmatically
create fake service catalogs in the test suite containing entries
for everything in service-types-authority.

In order to be able to test code paths where some service does not
exist, it would be good to be able to just remove a service from
the catalog, instead of needing to construct a full new one from
scratch.

Change-Id: I4b5469aefbe9b91c125da482509cdc627faa5525
This commit is contained in:
Monty Taylor 2019-08-07 14:25:28 -04:00 committed by Morgan Fainberg
parent bca9ee7d3c
commit 8e59fb20b3
3 changed files with 17 additions and 0 deletions

View File

@ -235,6 +235,11 @@ class Token(dict):
self.root.setdefault('serviceCatalog', []).append(service)
return service
def remove_service(self, type):
self.root['serviceCatalog'] = [
f for f in self.root.setdefault('serviceCatalog', [])
if f['type'] != type]
def set_scope(self, id=None, name=None):
self.tenant_id = id or uuid.uuid4().hex
self.tenant_name = name or uuid.uuid4().hex

View File

@ -434,6 +434,12 @@ class Token(dict):
self.root.setdefault('catalog', []).append(service)
return service
def remove_service(self, type):
self.root.setdefault('catalog', [])
self.root['catalog'] = [
f for f in self.root.setdefault('catalog', [])
if f['type'] != type]
def set_project_scope(self, id=None, name=None, domain_id=None,
domain_name=None, is_domain=None):
self.project_id = id or uuid.uuid4().hex

View File

@ -107,6 +107,9 @@ class V2TokenTests(utils.TestCase):
self.assertEqual(region, service['region'])
self.assertEqual(endpoint_id, service['id'])
token.remove_service(type=service_type)
self.assertEqual(0, len(token['access']['serviceCatalog']))
def test_token_bind(self):
name1 = uuid.uuid4().hex
data1 = uuid.uuid4().hex
@ -290,6 +293,9 @@ class V3TokenTests(utils.TestCase):
'region': region, 'region_id': region}
self.assertIn(endpoint, service['endpoints'])
token.remove_service(type=service_type)
self.assertEqual(0, len(token['token']['catalog']))
def test_empty_default_service_providers(self):
token = fixture.V3Token()
self.assertIsNone(token.service_providers)