예제 #1
0
    def test_policy_index_whitelists_params(self, mock_call, mock_parse,
                                            mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', True)
        fake_id = uuidutils.generate_uuid()
        params = {
            'name': 'FAKE',
            'type': 'TYPE',
            'limit': 20,
            'marker': fake_id,
            'sort': 'name:asc',
            'global_project': True,
        }
        req = self._get('/policies', params=params)
        obj = vorp.PolicyListRequest()
        mock_parse.return_value = obj

        engine_resp = [{'foo': 'bar'}]
        mock_call.return_value = engine_resp

        result = self.controller.index(req)

        expected = {u'policies': engine_resp}
        self.assertEqual(expected, result)

        mock_parse.assert_called_once_with(
            'PolicyListRequest', req, {
                'name': ['FAKE'],
                'type': ['TYPE'],
                'limit': '20',
                'marker': fake_id,
                'sort': 'name:asc',
                'project_safe': False,
            })
        mock_call.assert_called_once_with(req.context, 'policy_list', mock.ANY)
예제 #2
0
    def test_policy_index_normal(self, mock_call, mock_parse, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', True)
        req = self._get('/policies')

        engine_resp = [{
            u'id': u'aaaa-bbbb-cccc',
            u'name': u'policy-1',
            u'type': u'test_policy_type',
            u'spec': {
                u'param_1': u'value1',
                u'param_2': u'value2',
            },
            u'created_time': u'2015-02-24T19:17:22Z',
            u'updated_time': None,
        }]

        mock_call.return_value = engine_resp
        obj = vorp.PolicyListRequest()
        mock_parse.return_value = obj

        result = self.controller.index(req)

        expected = {u'policies': engine_resp}
        self.assertEqual(expected, result)

        mock_parse.assert_called_once_with('PolicyListRequest', req,
                                           {'project_safe': True})
        mock_call.assert_called_once_with(req.context, 'policy_list', mock.ANY)
예제 #3
0
    def test_policy_list_with_params(self, mock_get):
        mock_get.return_value = []
        marker = uuidutils.generate_uuid()
        params = {
            'limit': 10,
            'marker': marker,
            'name': ['test-policy'],
            'type': ['senlin.policy.scaling-1.0'],
            'sort': 'name:asc',
            'project_safe': True
        }
        req = orpo.PolicyListRequest(**params)

        result = self.svc.policy_list(self.ctx, req.obj_to_primitive())

        self.assertEqual([], result)
        mock_get.assert_called_once_with(self.ctx,
                                         limit=10,
                                         marker=marker,
                                         sort='name:asc',
                                         filters={
                                             'name': ['test-policy'],
                                             'type':
                                             ['senlin.policy.scaling-1.0']
                                         },
                                         project_safe=True)
예제 #4
0
    def test_policy_list(self, mock_get):
        x_obj_1 = mock.Mock()
        x_obj_1.to_dict.return_value = {'k': 'v1'}
        x_obj_2 = mock.Mock()
        x_obj_2.to_dict.return_value = {'k': 'v2'}
        mock_get.return_value = [x_obj_1, x_obj_2]
        req = orpo.PolicyListRequest(project_safe=True)

        result = self.svc.policy_list(self.ctx, req.obj_to_primitive())
        self.assertEqual([{'k': 'v1'}, {'k': 'v2'}], result)
        mock_get.assert_called_once_with(self.ctx, project_safe=True)
예제 #5
0
 def test_policy_list_request_body_full(self):
     params = {
         'name': ['policy1'],
         'type': ['senlin.policy.scaling-1.0'],
         'limit': 2,
         'marker': 'd6901ce0-1403-4b9c-abf5-25c59cf79823',
         'sort': 'name:asc',
         'project_safe': False
     }
     sot = policies.PolicyListRequest(**params)
     self.assertEqual(['policy1'], sot.name)
     self.assertEqual(['senlin.policy.scaling-1.0'], sot.type)
     self.assertEqual(2, sot.limit)
     self.assertEqual('d6901ce0-1403-4b9c-abf5-25c59cf79823', sot.marker)
     self.assertEqual('name:asc', sot.sort)
     self.assertFalse(sot.project_safe)