def test_cluster_policy_list(self): data = self.params sot = cp.ClusterPolicyListRequest(**data) self.assertEqual('fake_cluster', sot.identity) self.assertEqual('fake_name', sot.policy_name) self.assertEqual('fake_type', sot.policy_type) self.assertTrue(sot.enabled) self.assertEqual('enabled', sot.sort)
def test_list2_cluster_not_found(self, mock_find): mock_find.side_effect = exc.ResourceNotFound(type='cluster', id='Bogus') req = orcp.ClusterPolicyListRequest(identity='Bogus') ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_policy_list, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual("The cluster 'Bogus' could not be found.", six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'Bogus')
def test_list2(self, mock_get, mock_find): x_obj = mock.Mock(id='FAKE_CLUSTER') mock_find.return_value = x_obj b1 = mock.Mock() b1.to_dict.return_value = {'k': 'v1'} b2 = mock.Mock() b2.to_dict.return_value = {'k': 'v2'} mock_get.return_value = [b1, b2] req = orcp.ClusterPolicyListRequest(identity='CLUSTER') result = self.svc.cluster_policy_list( self.ctx, req.obj_to_primitive()) self.assertEqual([{'k': 'v1'}, {'k': 'v2'}], result) mock_find.assert_called_once_with(self.ctx, 'CLUSTER') mock_get.assert_called_once_with(self.ctx, 'FAKE_CLUSTER', filters={}, sort=None)
def test_list2_with_param(self, mock_get, mock_find): x_obj = mock.Mock(id='FAKE_CLUSTER') mock_find.return_value = x_obj mock_get.return_value = [] params = { 'identity': 'CLUSTER', 'policy_name': 'fake_name', 'policy_type': 'fake_type', 'enabled': True, 'sort': 'enabled' } req = orcp.ClusterPolicyListRequest(**params) result = self.eng.cluster_policy_list(self.ctx, req.obj_to_primitive()) self.assertEqual([], result) mock_find.assert_called_once_with(self.ctx, 'CLUSTER')
def test_cluster_policy_list_primitive(self): data = self.params sot = cp.ClusterPolicyListRequest(**data) res = sot.obj_to_primitive() self.assertIn('identity', res['senlin_object.changes']) self.assertIn('sort', res['senlin_object.changes']) self.assertIn('enabled', res['senlin_object.changes']) self.assertIn('policy_name', res['senlin_object.changes']) self.assertIn('policy_type', res['senlin_object.changes']) self.assertEqual('1.0', res['senlin_object.version']) self.assertEqual('senlin', res['senlin_object.namespace']) self.assertEqual('ClusterPolicyListRequest', res['senlin_object.name']) param = res['senlin_object.data'] self.assertEqual('fake_cluster', param['identity']) self.assertEqual('enabled', param['sort']) self.assertEqual('fake_name', param['policy_name']) self.assertEqual('fake_type', param['policy_type']) self.assertTrue(param['enabled'])