identity/v2 user resource

Change-Id: I68c7c9e6a08dfe24cf031284a63e1dd8db8fbc27
This commit is contained in:
Jamie Lennox 2014-08-13 06:08:26 +10:00 committed by Terry Howe
parent 9855a7c4bd
commit 2609db413b
6 changed files with 139 additions and 0 deletions

View File

View File

@ -0,0 +1,29 @@
# 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.
from openstack.auth import service_filter
class IdentityService(service_filter.ServiceFilter):
"""The identity service."""
def __init__(self, **kwargs):
"""Create an image service."""
kwargs['service_type'] = 'identity'
super(IdentityService, self).__init__(**kwargs)
class AdminService(IdentityService):
def __init__(self, **kwargs):
kwargs['visibility'] = service_filter.ServiceFilter.ADMIN
super(AdminService, self).__init__(**kwargs)

View File

View File

@ -0,0 +1,33 @@
# 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.
from openstack.identity import identity_service
from openstack import resource
class User(resource.Resource):
resource_key = 'user'
resources_key = 'users'
base_path = '/users'
service = identity_service.AdminService()
# capabilities
allow_create = True
allow_retrieve = True
allow_update = True
allow_delete = True
allow_list = True
# Properties
email = resource.prop('email')
enabled = resource.prop('enabled', type=bool)
name = resource.prop('name')

View File

@ -0,0 +1,32 @@
# 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 testtools
from openstack.identity import identity_service
class TestIdentityService(testtools.TestCase):
def test_regular_service(self):
sot = identity_service.IdentityService()
self.assertEqual('identity', sot.service_type)
self.assertEqual('public', sot.visibility)
self.assertIsNone(sot.region)
self.assertIsNone(sot.service_name)
def test_admin_service(self):
sot = identity_service.AdminService()
self.assertEqual('identity', sot.service_type)
self.assertEqual('admin', sot.visibility)
self.assertIsNone(sot.region)
self.assertIsNone(sot.service_name)

View File

@ -0,0 +1,45 @@
# 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 testtools
from openstack.identity.v2 import user
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
'email': '1',
'enabled': True,
'id': '3',
'name': '4',
}
class TestUser(testtools.TestCase):
def test_basic(self):
sot = user.User()
self.assertEqual('user', sot.resource_key)
self.assertEqual('users', sot.resources_key)
self.assertEqual('/users', sot.base_path)
self.assertEqual('identity', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_retrieve)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = user.User(EXAMPLE)
self.assertEqual(EXAMPLE['email'], sot.email)
self.assertEqual(EXAMPLE['enabled'], sot.enabled)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['name'], sot.name)