From c1df152d7b48f18f51cfca472a438aeea96869a5 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 5 Mar 2014 16:46:41 +1000 Subject: [PATCH] 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 --- keystoneclient/tests/v2_0/test_service_catalog.py | 13 ++++--------- keystoneclient/tests/v3/test_service_catalog.py | 14 +++++--------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/keystoneclient/tests/v2_0/test_service_catalog.py b/keystoneclient/tests/v2_0/test_service_catalog.py index e74904de7..7d05c8985 100644 --- a/keystoneclient/tests/v2_0/test_service_catalog.py +++ b/keystoneclient/tests/v2_0/test_service_catalog.py @@ -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', diff --git a/keystoneclient/tests/v3/test_service_catalog.py b/keystoneclient/tests/v3/test_service_catalog.py index 9a4cc5c28..504cbba8d 100644 --- a/keystoneclient/tests/v3/test_service_catalog.py +++ b/keystoneclient/tests/v3/test_service_catalog.py @@ -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',