Debian Codegraph @

keystoneclient/tests/unit/v3/test_limits.py

raw symbols SCIP
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 import uuid
14
15 from keystoneclient.tests.unit.v3 import utils
16 from keystoneclient.v3 import limits
17
18
19 class LimitTests(utils.ClientTestCase, utils.CrudTests):
20 def setUp(self):
21 super(LimitTests, self).setUp()
22 self.key = 'limit'
23 self.collection_key = 'limits'
24 self.model = limits.Limit
25 self.manager = self.client.limits
26
27 def new_ref(self, **kwargs):
28 ref = {
29 'id': uuid.uuid4().hex,
30 'project_id': uuid.uuid4().hex,
31 'service_id': uuid.uuid4().hex,
32 'resource_name': uuid.uuid4().hex,
33 'resource_limit': 15,
34 'description': uuid.uuid4().hex
35 }
36 ref.update(kwargs)
37 return ref
38
39 def test_create(self):
40 # This test overrides the generic test case provided by the CrudTests
41 # class because the limits API supports creating multiple limits in a
42 # single POST request. As a result, it returns the limits as a list of
43 # all the created limits from the request. This is different from what
44 # the base test_create() method assumes about keystone's API. The
45 # changes here override the base test to closely model how the actual
46 # limit API behaves.
47 ref = self.new_ref()
48 manager_ref = ref.copy()
49 manager_ref.pop('id')
50 req_ref = [manager_ref.copy()]
51
52 self.stub_entity('POST', entity=req_ref, status_code=201)
53
54 returned = self.manager.create(**utils.parameterize(manager_ref))
55 self.assertIsInstance(returned, self.model)
56
57 expected_limit = req_ref.pop()
58 for attr in expected_limit:
59 self.assertEqual(
60 getattr(returned, attr),
61 expected_limit[attr],
62 'Expected different %s' % attr)
63 self.assertEntityRequestBodyIs([expected_limit])
64
65 def test_list_filter_by_service(self):
66 service_id = uuid.uuid4().hex
67 expected_query = {'service_id': service_id}
68 self.test_list(expected_query=expected_query, service=service_id)
69
70 def test_list_filtered_by_resource_name(self):
71 resource_name = uuid.uuid4().hex
72 self.test_list(resource_name=resource_name)
73
74 def test_list_filtered_by_region(self):
75 region_id = uuid.uuid4().hex
76 expected_query = {'region_id': region_id}
77 self.test_list(expected_query=expected_query, region=region_id)