From 2609db413bbeed6333e019837b2d636c0b402df8 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 13 Aug 2014 06:08:26 +1000 Subject: [PATCH] identity/v2 user resource Change-Id: I68c7c9e6a08dfe24cf031284a63e1dd8db8fbc27 --- openstack/identity/__init__.py | 0 openstack/identity/identity_service.py | 29 ++++++++++++ openstack/identity/v2/__init__.py | 0 openstack/identity/v2/user.py | 33 ++++++++++++++ .../tests/identity/test_identity_service.py | 32 +++++++++++++ openstack/tests/identity/v2/test_user.py | 45 +++++++++++++++++++ 6 files changed, 139 insertions(+) create mode 100644 openstack/identity/__init__.py create mode 100644 openstack/identity/identity_service.py create mode 100644 openstack/identity/v2/__init__.py create mode 100644 openstack/identity/v2/user.py create mode 100644 openstack/tests/identity/test_identity_service.py create mode 100644 openstack/tests/identity/v2/test_user.py diff --git a/openstack/identity/__init__.py b/openstack/identity/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/identity/identity_service.py b/openstack/identity/identity_service.py new file mode 100644 index 000000000..8e49c6c3a --- /dev/null +++ b/openstack/identity/identity_service.py @@ -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) diff --git a/openstack/identity/v2/__init__.py b/openstack/identity/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/identity/v2/user.py b/openstack/identity/v2/user.py new file mode 100644 index 000000000..5176ea11a --- /dev/null +++ b/openstack/identity/v2/user.py @@ -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') diff --git a/openstack/tests/identity/test_identity_service.py b/openstack/tests/identity/test_identity_service.py new file mode 100644 index 000000000..a095dcbe8 --- /dev/null +++ b/openstack/tests/identity/test_identity_service.py @@ -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) diff --git a/openstack/tests/identity/v2/test_user.py b/openstack/tests/identity/v2/test_user.py new file mode 100644 index 000000000..2931fb1d3 --- /dev/null +++ b/openstack/tests/identity/v2/test_user.py @@ -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)