added catalog tests

This commit is contained in:
termie 2011-11-03 14:48:50 -07:00
parent f86bf25f32
commit 344d21ca69
2 changed files with 28 additions and 2 deletions

View File

@ -96,8 +96,9 @@ class KvsCatalog(object):
# Public interface
def get_catalog(self, user_id, tenant_id, extras=None):
return self.db.get('catalog-%s' % tenant_id)
return self.db.get('catalog-%s-%s' % (tenant_id, user_id))
# Private interface
def _create_catalog(self, user_id, tenant_id, data):
self.db.set('catalog-%s' % tenant_id, data)
self.db.set('catalog-%s-%s' % (tenant_id, user_id), data)
return data

View File

@ -130,3 +130,28 @@ class KvsToken(test.TestCase):
self.token_api.delete_token(token_id)
deleted_data_ref = self.token_api.get_token(token_id)
self.assert_(deleted_data_ref is None)
class KvsCatalog(test.TestCase):
def setUp(self):
super(KvsCatalog, self).setUp()
options = self.appconfig('default')
self.catalog_api = kvs.KvsCatalog(options=options, db={})
self._load_fixtures()
def _load_fixtures(self):
self.catalog_foobar = self.catalog_api._create_catalog(
'foo', 'bar',
{'RegionFoo': {'service_bar': {'foo': 'bar'}}})
def test_get_catalog_bad_user(self):
catalog_ref = self.catalog_api.get_catalog('foo' + 'WRONG', 'bar')
self.assert_(catalog_ref is None)
def test_get_catalog_bad_tenant(self):
catalog_ref = self.catalog_api.get_catalog('foo', 'bar' + 'WRONG')
self.assert_(catalog_ref is None)
def test_get_catalog(self):
catalog_ref = self.catalog_api.get_catalog('foo', 'bar')
self.assertDictEquals(catalog_ref, self.catalog_foobar)