From a11f99bfea314db647da89bb86feab2c02ccedf1 Mon Sep 17 00:00:00 2001 From: shizhihui Date: Thu, 17 Nov 2016 05:51:44 +0800 Subject: [PATCH] Add unit tests for function 'index' the file: heat/tests/api/openstack_v1_test_stacks.py Change-Id: Icf60e8cea00f602aa2d5b83d611bfc7013451d38 --- heat/tests/api/openstack_v1/test_stacks.py | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/heat/tests/api/openstack_v1/test_stacks.py b/heat/tests/api/openstack_v1/test_stacks.py index 29bff90b9b..ab3d735e0d 100644 --- a/heat/tests/api/openstack_v1/test_stacks.py +++ b/heat/tests/api/openstack_v1/test_stacks.py @@ -551,6 +551,45 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase): filters=mock.ANY, show_nested=True) + def test_global_index_show_hidden_true(self, mock_enforce): + rpc_client = self.controller.rpc_client + rpc_client.list_stacks = mock.Mock(return_value=[]) + rpc_client.count_stacks = mock.Mock() + + params = {'show_hidden': 'True'} + req = self._get('/stacks', params=params) + self.controller.index(req, tenant_id=self.tenant) + rpc_client.list_stacks.assert_called_once_with(mock.ANY, + filters=mock.ANY, + show_hidden=True) + + def test_global_index_show_hidden_false(self, mock_enforce): + rpc_client = self.controller.rpc_client + rpc_client.list_stacks = mock.Mock(return_value=[]) + rpc_client.count_stacks = mock.Mock() + + params = {'show_hidden': 'false'} + req = self._get('/stacks', params=params) + self.controller.index(req, tenant_id=self.tenant) + rpc_client.list_stacks.assert_called_once_with(mock.ANY, + filters=mock.ANY, + show_hidden=False) + + def test_index_show_deleted_True_with_count_false(self, mock_enforce): + rpc_client = self.controller.rpc_client + rpc_client.list_stacks = mock.Mock(return_value=[]) + rpc_client.count_stacks = mock.Mock() + + params = {'show_deleted': 'True', + 'with_count': 'false'} + req = self._get('/stacks', params=params) + result = self.controller.index(req, tenant_id=self.tenant) + self.assertNotIn('count', result) + rpc_client.list_stacks.assert_called_once_with(mock.ANY, + filters=mock.ANY, + show_deleted=True) + self.assertFalse(rpc_client.count_stacks.called) + def test_index_show_deleted_True_with_count_True(self, mock_enforce): rpc_client = self.controller.rpc_client rpc_client.list_stacks = mock.Mock(return_value=[])