Coverage for manila/tests/test_context.py: 100%
30 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2011 OpenStack LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
15from manila import context
16from manila import test
19class ContextTestCase(test.TestCase):
21 def test_request_context_elevated(self):
22 user_context = context.RequestContext(
23 'fake_user', 'fake_project', is_admin=False)
24 self.assertFalse(user_context.is_admin)
25 self.assertEqual([], user_context.roles)
26 admin_context = user_context.elevated()
27 self.assertFalse(user_context.is_admin)
28 self.assertTrue(admin_context.is_admin)
29 self.assertNotIn('admin', user_context.roles)
30 self.assertIn('admin', admin_context.roles)
32 def test_request_context_sets_is_admin(self):
33 ctxt = context.RequestContext('111',
34 '222',
35 roles=['admin', 'weasel'])
36 self.assertTrue(ctxt.is_admin)
38 def test_request_context_sets_is_service(self):
39 ctxt = context.RequestContext('111',
40 '222',
41 roles=['service', 'admin'],
42 service_roles=['service'])
43 self.assertTrue(ctxt.is_service)
45 def test_request_context_sets_is_admin_upcase(self):
46 ctxt = context.RequestContext('111',
47 '222',
48 roles=['Admin', 'weasel'])
49 self.assertTrue(ctxt.is_admin)
51 def test_request_context_read_deleted(self):
52 ctxt = context.RequestContext('111',
53 '222',
54 read_deleted='yes')
55 self.assertEqual('yes', ctxt.read_deleted)
57 ctxt.read_deleted = 'no'
58 self.assertEqual('no', ctxt.read_deleted)
60 def test_request_context_read_deleted_invalid(self):
61 self.assertRaises(ValueError,
62 context.RequestContext,
63 '111',
64 '222',
65 read_deleted=True)
67 ctxt = context.RequestContext('111', '222')
68 self.assertRaises(ValueError,
69 setattr,
70 ctxt,
71 'read_deleted',
72 True)