Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / tests / unit / objects / qos / test_rule_type.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 # rule types are so different from other objects that we don't base the test
14 # class on the common base class for all objects
15
16 import mock
17
18 from neutron import manager
19 from neutron.objects.qos import rule_type
20 from neutron.services.qos import qos_consts
21 from neutron.tests import base as test_base
22
23
24 DB_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
25
26
27 class QosRuleTypeObjectTestCase(test_base.BaseTestCase):
28
29     def setUp(self):
30         self.config_parse()
31         self.setup_coreplugin(DB_PLUGIN_KLASS)
32         super(QosRuleTypeObjectTestCase, self).setUp()
33
34     def test_get_objects(self):
35         core_plugin = manager.NeutronManager.get_plugin()
36         rule_types_mock = mock.PropertyMock(
37             return_value=qos_consts.VALID_RULE_TYPES)
38         with mock.patch.object(core_plugin, 'supported_qos_rule_types',
39                                new_callable=rule_types_mock,
40                                create=True):
41             types = rule_type.QosRuleType.get_objects()
42             self.assertEqual(sorted(qos_consts.VALID_RULE_TYPES),
43                              sorted(type_['type'] for type_ in types))
44
45     def test_wrong_type(self):
46         self.assertRaises(ValueError, rule_type.QosRuleType, type='bad_type')