Add unit test case for Keystone client plug-in for group
Adds required unit test cases for the keystone group in the keystone client plug-in Closes-Bug: #1463267 Change-Id: I5e09e2c797701483d0a85d33fad37f8481458f8c
This commit is contained in:
parent
d821a9f9ba
commit
030d1ae654
|
@ -441,3 +441,79 @@ class KeystoneClientPluginDomainTest(common.HeatTestCase):
|
|||
self.sample_name)
|
||||
self._client.client.domains.list.assert_called_once_with(
|
||||
name=self.sample_name)
|
||||
|
||||
|
||||
class KeystoneClientPluginGroupTest(common.HeatTestCase):
|
||||
|
||||
sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
|
||||
sample_name = 'sample_group'
|
||||
|
||||
def _get_mock_group(self):
|
||||
group = mock.MagicMock()
|
||||
group.id = self.sample_uuid
|
||||
group.name = self.sample_name
|
||||
return group
|
||||
|
||||
def setUp(self):
|
||||
super(KeystoneClientPluginGroupTest, self).setUp()
|
||||
self._client = mock.MagicMock()
|
||||
|
||||
@mock.patch.object(client.KeystoneClientPlugin, 'client')
|
||||
def test_get_group_id(self, client_keystone):
|
||||
self._client.client.groups.get.return_value = (self
|
||||
._get_mock_group())
|
||||
|
||||
client_keystone.return_value = self._client
|
||||
client_plugin = client.KeystoneClientPlugin(
|
||||
context=mock.MagicMock()
|
||||
)
|
||||
|
||||
self.assertEqual(self.sample_uuid,
|
||||
client_plugin.get_group_id(self.sample_uuid))
|
||||
self._client.client.groups.get.assert_called_once_with(
|
||||
self.sample_uuid)
|
||||
|
||||
@mock.patch.object(client.KeystoneClientPlugin, 'client')
|
||||
def test_get_group_id_with_name(self, client_keystone):
|
||||
self._client.client.groups.get.side_effect = (keystone_exceptions
|
||||
.NotFound)
|
||||
self._client.client.groups.list.return_value = [
|
||||
self._get_mock_group()
|
||||
]
|
||||
|
||||
client_keystone.return_value = self._client
|
||||
client_plugin = client.KeystoneClientPlugin(
|
||||
context=mock.MagicMock()
|
||||
)
|
||||
|
||||
self.assertEqual(self.sample_uuid,
|
||||
client_plugin.get_group_id(self.sample_name))
|
||||
self.assertRaises(keystone_exceptions.NotFound,
|
||||
self._client.client.groups.get,
|
||||
self.sample_name)
|
||||
self._client.client.groups.list.assert_called_once_with(
|
||||
name=self.sample_name)
|
||||
|
||||
@mock.patch.object(client.KeystoneClientPlugin, 'client')
|
||||
def test_get_group_id_not_found(self, client_keystone):
|
||||
self._client.client.groups.get.side_effect = (keystone_exceptions
|
||||
.NotFound)
|
||||
self._client.client.groups.list.return_value = [
|
||||
]
|
||||
|
||||
client_keystone.return_value = self._client
|
||||
client_plugin = client.KeystoneClientPlugin(
|
||||
context=mock.MagicMock()
|
||||
)
|
||||
|
||||
ex = self.assertRaises(exception.EntityNotFound,
|
||||
client_plugin.get_group_id,
|
||||
self.sample_name)
|
||||
msg = ("The KeystoneGroup (%(name)s) could not be found." %
|
||||
{'name': self.sample_name})
|
||||
self.assertEqual(msg, six.text_type(ex))
|
||||
self.assertRaises(keystone_exceptions.NotFound,
|
||||
self._client.client.groups.get,
|
||||
self.sample_name)
|
||||
self._client.client.groups.list.assert_called_once_with(
|
||||
name=self.sample_name)
|
||||
|
|
Loading…
Reference in New Issue