1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from oslo_utils import timeutils
from keystoneclient import exceptions
from keystoneclient.tests.unit.v3 import utils
from keystoneclient.v3 import application_credentials
class ApplicationCredentialTests(utils.ClientTestCase, utils.CrudTests):
def setUp(self):
super(ApplicationCredentialTests, self).setUp()
self.key = 'application_credential'
self.collection_key = 'application_credentials'
self.model = application_credentials.ApplicationCredential
self.manager = self.client.application_credentials
self.path_prefix = 'users/%s' % self.TEST_USER_ID
def new_ref(self, **kwargs):
kwargs = super(ApplicationCredentialTests, self).new_ref(**kwargs)
kwargs.setdefault('name', uuid.uuid4().hex)
kwargs.setdefault('description', uuid.uuid4().hex)
kwargs.setdefault('unrestricted', False)
return kwargs
def test_create_with_roles(self):
ref = self.new_ref(user=uuid.uuid4().hex)
ref['roles'] = [{'name': 'atestrole'}]
req_ref = ref.copy()
req_ref.pop('id')
user = req_ref.pop('user')
self.stub_entity('POST',
['users', user, self.collection_key],
status_code=201, entity=req_ref)
super(ApplicationCredentialTests, self).test_create(ref=ref,
req_ref=req_ref)
def test_create_with_role_id_and_names(self):
ref = self.new_ref(user=uuid.uuid4().hex)
ref['roles'] = [{'name': 'atestrole', 'domain': 'nondefault'},
uuid.uuid4().hex]
req_ref = ref.copy()
req_ref.pop('id')
user = req_ref.pop('user')
req_ref['roles'] = [{'name': 'atestrole', 'domain': 'nondefault'},
{'id': ref['roles'][1]}]
self.stub_entity('POST',
['users', user, self.collection_key],
status_code=201, entity=req_ref)
super(ApplicationCredentialTests, self).test_create(ref=ref,
req_ref=req_ref)
def test_create_expires(self):
ref = self.new_ref(user=uuid.uuid4().hex)
ref['expires_at'] = timeutils.parse_isotime(
'2013-03-04T12:00:01.000000Z')
req_ref = ref.copy()
req_ref.pop('id')
user = req_ref.pop('user')
req_ref['expires_at'] = '2013-03-04T12:00:01.000000Z'
self.stub_entity('POST',
['users', user, self.collection_key],
status_code=201, entity=req_ref)
super(ApplicationCredentialTests, self).test_create(ref=ref,
req_ref=req_ref)
def test_create_unrestricted(self):
ref = self.new_ref(user=uuid.uuid4().hex)
ref['unrestricted'] = True
req_ref = ref.copy()
req_ref.pop('id')
user = req_ref.pop('user')
self.stub_entity('POST',
['users', user, self.collection_key],
status_code=201, entity=req_ref)
super(ApplicationCredentialTests, self).test_create(ref=ref,
req_ref=req_ref)
def test_create_with_access_rules(self):
ref = self.new_ref(user=uuid.uuid4().hex)
access_rules = [
{
'method': 'GET',
'path': '/v3/projects',
'service': 'identity'
}
]
ref['access_rules'] = access_rules
req_ref = ref.copy()
req_ref.pop('id')
user = req_ref.pop('user')
self.stub_entity('POST',
['users', user, self.collection_key],
status_code=201, entity=req_ref)
super(ApplicationCredentialTests, self).test_create(ref=ref,
req_ref=req_ref)
def test_get(self):
ref = self.new_ref(user=uuid.uuid4().hex)
self.stub_entity(
'GET', ['users', ref['user'], self.collection_key, ref['id']],
entity=ref)
returned = self.manager.get(ref['id'], ref['user'])
self.assertIsInstance(returned, self.model)
for attr in ref:
self.assertEqual(
getattr(returned, attr),
ref[attr],
'Expected different %s' % attr)
def test_update(self):
self.assertRaises(exceptions.MethodNotImplemented, self.manager.update)
|