Fix state modifying catalog tests

Some of the service catalog tests modify the global state. They should
take a copy of the dictionary before modifying it.

Change-Id: I5de52949d561322958f603022af893f087c55e03
This commit is contained in:
Jamie Lennox
2014-03-05 16:46:41 +10:00
parent 8246e65c02
commit c1df152d7b
2 changed files with 9 additions and 18 deletions

View File

@@ -21,7 +21,8 @@ from keystoneclient.tests.v2_0 import utils
class ServiceCatalogTest(utils.TestCase):
def setUp(self):
super(ServiceCatalogTest, self).setUp()
self.AUTH_RESPONSE_BODY = client_fixtures.AUTH_RESPONSE_BODY
self.AUTH_RESPONSE_BODY = copy.deepcopy(
client_fixtures.AUTH_RESPONSE_BODY)
def test_building_a_service_catalog(self):
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY)
@@ -63,14 +64,8 @@ class ServiceCatalogTest(utils.TestCase):
self.assertEqual(url, "https://image-internal.south.host/v1/")
def test_service_catalog_empty(self):
# We need to do a copy.deepcopy here since
# dict(self.AUTH_RESPONSE_BODY) or self.AUTH_RESPONSE_BODY.copy() will
# only do a shadowcopy and sc_empty['token']['catalog'] will still be a
# reference to self.AUTH_RESPONSE_BODY so setting it to empty will fail
# the other tests that needs a service catalog.
sc_empty = copy.deepcopy(self.AUTH_RESPONSE_BODY)
sc_empty['access']['serviceCatalog'] = []
auth_ref = access.AccessInfo.factory(None, sc_empty)
self.AUTH_RESPONSE_BODY['access']['serviceCatalog'] = []
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY)
self.assertRaises(exceptions.EmptyCatalog,
auth_ref.service_catalog.url_for,
service_type='image',

View File

@@ -21,7 +21,8 @@ from keystoneclient.tests.v3 import utils
class ServiceCatalogTest(utils.TestCase):
def setUp(self):
super(ServiceCatalogTest, self).setUp()
self.AUTH_RESPONSE_BODY = client_fixtures.AUTH_RESPONSE_BODY
self.AUTH_RESPONSE_BODY = copy.deepcopy(
client_fixtures.AUTH_RESPONSE_BODY)
self.RESPONSE = utils.TestResponse({
"headers": client_fixtures.AUTH_RESPONSE_HEADERS
})
@@ -82,14 +83,9 @@ class ServiceCatalogTest(utils.TestCase):
self.assertEqual(url, "http://glance.south.host/glanceapi/internal")
def test_service_catalog_empty(self):
# We need to do a copy.deepcopy here since
# dict(self.AUTH_RESPONSE_BODY) or self.AUTH_RESPONSE_BODY.copy() will
# only do a shadowcopy and sc_empty['token']['catalog'] will still be a
# reference to self.AUTH_RESPONSE_BODY so setting it to empty will fail
# the other tests that needs a service catalog.
sc_empty = copy.deepcopy(self.AUTH_RESPONSE_BODY)
sc_empty['token']['catalog'] = []
auth_ref = access.AccessInfo.factory(self.RESPONSE, sc_empty)
self.AUTH_RESPONSE_BODY['token']['catalog'] = []
auth_ref = access.AccessInfo.factory(self.RESPONSE,
self.AUTH_RESPONSE_BODY)
self.assertRaises(exceptions.EmptyCatalog,
auth_ref.service_catalog.url_for,
service_type='image',