From 1d5e530e9a47c38bbe18c5ae8565bcef89055d7c Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Mon, 12 Aug 2013 18:52:50 +0200 Subject: [PATCH] Add unittests for exceptions.EmptyCatalog Change-Id: I6cff9501883ba2237e3112a53e01f994f170aadf --- tests/v2_0/test_service_catalog.py | 16 ++++++++++++++++ tests/v3/test_service_catalog.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/tests/v2_0/test_service_catalog.py b/tests/v2_0/test_service_catalog.py index 15838b9e6..529cff22f 100644 --- a/tests/v2_0/test_service_catalog.py +++ b/tests/v2_0/test_service_catalog.py @@ -1,3 +1,5 @@ +import copy + from keystoneclient import access from keystoneclient import exceptions @@ -48,3 +50,17 @@ class ServiceCatalogTest(utils.TestCase): url = sc.url_for(service_type='image', endpoint_type='internalURL') self.assertEquals(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.assertRaises(exceptions.EmptyCatalog, + auth_ref.service_catalog.url_for, + service_type='image', + endpoint_type='internalURL') diff --git a/tests/v3/test_service_catalog.py b/tests/v3/test_service_catalog.py index d0dac3ad4..96680b27f 100644 --- a/tests/v3/test_service_catalog.py +++ b/tests/v3/test_service_catalog.py @@ -1,3 +1,5 @@ +import copy + from keystoneclient import access from keystoneclient import exceptions @@ -53,3 +55,17 @@ class ServiceCatalogTest(utils.TestCase): sc = auth_ref.service_catalog url = sc.url_for(service_type='image', endpoint_type='internal') self.assertEquals(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.assertRaises(exceptions.EmptyCatalog, + auth_ref.service_catalog.url_for, + service_type='image', + endpoint_type='internalURL')