Debian Codegraph @

keystoneclient/tests/unit/v3/test_trusts.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain 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,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10 # implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 import uuid
15
16 from oslo_utils import timeutils
17
18 from keystoneclient import exceptions
19 from keystoneclient.tests.unit.v3 import utils
20 from keystoneclient.v3.contrib import trusts
21
22
23 class TrustTests(utils.ClientTestCase, utils.CrudTests):
24 def setUp(self):
25 super(TrustTests, self).setUp()
26 self.key = 'trust'
27 self.collection_key = 'trusts'
28 self.model = trusts.Trust
29 self.manager = self.client.trusts
30 self.path_prefix = 'OS-TRUST'
31
32 def new_ref(self, **kwargs):
33 kwargs = super(TrustTests, self).new_ref(**kwargs)
34 kwargs.setdefault('project_id', uuid.uuid4().hex)
35 return kwargs
36
37 def test_create(self):
38 ref = self.new_ref()
39 ref['trustor_user_id'] = uuid.uuid4().hex
40 ref['trustee_user_id'] = uuid.uuid4().hex
41 ref['impersonation'] = False
42 super(TrustTests, self).test_create(ref=ref)
43
44 def test_create_limited_uses(self):
45 ref = self.new_ref()
46 ref['trustor_user_id'] = uuid.uuid4().hex
47 ref['trustee_user_id'] = uuid.uuid4().hex
48 ref['impersonation'] = False
49 ref['remaining_uses'] = 5
50 super(TrustTests, self).test_create(ref=ref)
51
52 def test_create_roles(self):
53 ref = self.new_ref()
54 ref['trustor_user_id'] = uuid.uuid4().hex
55 ref['trustee_user_id'] = uuid.uuid4().hex
56 ref['impersonation'] = False
57 req_ref = ref.copy()
58 req_ref.pop('id')
59
60 # Note the TrustManager takes a list of role_names, and converts
61 # internally to the slightly odd list-of-dict API format, so we
62 # have to pass the expected request data to allow correct stubbing
63 ref['role_names'] = ['atestrole']
64 req_ref['roles'] = [{'name': 'atestrole'}]
65 super(TrustTests, self).test_create(ref=ref, req_ref=req_ref)
66
67 def test_create_role_id_and_names(self):
68 ref = self.new_ref()
69 ref['trustor_user_id'] = uuid.uuid4().hex
70 ref['trustee_user_id'] = uuid.uuid4().hex
71 ref['impersonation'] = False
72 req_ref = ref.copy()
73 req_ref.pop('id')
74
75 # Note the TrustManager takes a list of role_names, and converts
76 # internally to the slightly odd list-of-dict API format, so we
77 # have to pass the expected request data to allow correct stubbing
78 ref['role_names'] = ['atestrole']
79 ref['role_ids'] = [uuid.uuid4().hex]
80 req_ref['roles'] = [{'name': 'atestrole'}, {'id': ref['role_ids'][0]}]
81 super(TrustTests, self).test_create(ref=ref, req_ref=req_ref)
82
83 def test_create_expires(self):
84 ref = self.new_ref()
85 ref['trustor_user_id'] = uuid.uuid4().hex
86 ref['trustee_user_id'] = uuid.uuid4().hex
87 ref['impersonation'] = False
88 ref['expires_at'] = timeutils.parse_isotime(
89 '2013-03-04T12:00:01.000000Z')
90 req_ref = ref.copy()
91 req_ref.pop('id')
92
93 # Note the TrustManager takes a datetime.datetime object for
94 # expires_at, and converts it internally into an iso format datestamp
95 req_ref['expires_at'] = '2013-03-04T12:00:01.000000Z'
96 super(TrustTests, self).test_create(ref=ref, req_ref=req_ref)
97
98 def test_create_imp(self):
99 ref = self.new_ref()
100 ref['trustor_user_id'] = uuid.uuid4().hex
101 ref['trustee_user_id'] = uuid.uuid4().hex
102 ref['impersonation'] = True
103 super(TrustTests, self).test_create(ref=ref)
104
105 def test_create_roles_imp(self):
106 ref = self.new_ref()
107 ref['trustor_user_id'] = uuid.uuid4().hex
108 ref['trustee_user_id'] = uuid.uuid4().hex
109 ref['impersonation'] = True
110 req_ref = ref.copy()
111 req_ref.pop('id')
112 ref['role_names'] = ['atestrole']
113 req_ref['roles'] = [{'name': 'atestrole'}]
114 super(TrustTests, self).test_create(ref=ref, req_ref=req_ref)
115
116 def test_list_filter_trustor(self):
117 expected_query = {'trustor_user_id': '12345'}
118 super(TrustTests, self).test_list(expected_query=expected_query,
119 trustor_user='12345')
120
121 def test_list_filter_trustee(self):
122 expected_query = {'trustee_user_id': '12345'}
123 super(TrustTests, self).test_list(expected_query=expected_query,
124 trustee_user='12345')
125
126 def test_update(self):
127 # Update not supported for the OS-TRUST API
128 self.assertRaises(exceptions.MethodNotImplemented, self.manager.update)