Merge "Tenants API Client - Role Tests Parity:"

This commit is contained in:
Jenkins
2013-07-31 22:26:39 +00:00
committed by Gerrit Code Review
2 changed files with 49 additions and 27 deletions

View File

@@ -21,8 +21,10 @@ from cloudcafe.identity.v2_0.tenants_api.models.responses.role import \
Roles, Role
from cloudcafe.identity.v2_0.tenants_api.models.responses.user import \
Users, User
from cloudcafe.identity.v2_0.common.models.constants import AdminExtensions
_version = 'v2.0'
_admin_extensions = AdminExtensions.OS_KS_ADM
class TenantsAPI_Client(AutoMarshallingRestClient):
@@ -250,20 +252,22 @@ class TenantsAPI_Client(AutoMarshallingRestClient):
requestslib_kwargs=requestslib_kwargs)
return response
def create_role_for_tenant_user(self, id_=None, name=None,
tenant_id=None, user_id=None,
requestslib_kwargs=None):
def assign_role_to_tenant_user(self, role_id=None, name=None,
tenant_id=None, user_id=None,
requestslib_kwargs=None):
"""
@summary: Creates a role for a given tenant user
@summary: Assigns a role to a given tenant user
"""
url = '{0}/tenants/{1}/users/{2}/roles'.format(self.base_url,
tenant_id, user_id)
url = '{0}/tenants/{1}/users/{2}/roles/{3}/{4}'.format(
self.base_url,
tenant_id,
user_id,
_admin_extensions,
role_id)
role_request_object = Role(id_=id_, name=name)
response = self.request('POST', url,
response = self.request('PUT', url,
response_entity_type=Role,
request_entity=role_request_object,
requestslib_kwargs=requestslib_kwargs)
return response
@@ -275,7 +279,7 @@ class TenantsAPI_Client(AutoMarshallingRestClient):
@type tenant_id: String
@param user_id: The id of the user
@type user_id: String
@return: server_response
@return: response
@rtype: Response
"""
@@ -286,20 +290,28 @@ class TenantsAPI_Client(AutoMarshallingRestClient):
requestslib_kwargs=requestslib_kwargs)
return response
def delete_role_of_tenant_user(self, tenant_id,
user_id, requestslib_kwargs=None):
def remove_role_of_tenant_user(self, tenant_id=None,
user_id=None, role_id=None,
requestslib_kwargs=None):
"""
@summary: Deletes the specified roles for a tenant user
@param tenant_id: The id of a tenant
@type tenant_id: String
@param user_id: The id of a user
@type user_id: String
@param role_id: The id of a role
@type role_id: String
@return: resp
@rtype: Requests.response
"""
url = '{0}/tenants/{1}/users/{2}/roles'.format(self.base_url,
tenant_id, user_id)
url = '{0}/tenants/{1}/users/{2}/roles/{3}/{4}'.format(
self.base_url,
tenant_id,
user_id,
_admin_extensions,
role_id)
response = self.request('DELETE', url,
requestslib_kwargs=requestslib_kwargs)
return response

View File

@@ -22,12 +22,12 @@ IDENTITY_ENDPOINT_URL = "http://localhost:5000"
class TenantsClientTest(TestCase):
def setUp(self):
self.url = IDENTITY_ENDPOINT_URL
self.serialize_format = "json"
self.deserialize_format = "json"
self.auth_token = "AUTH_TOKEN"
self.admin_extensions = "OS-KSADM"
self.tenant_api_client = TenantsAPI_Client(
url=self.url,
@@ -45,6 +45,10 @@ class TenantsClientTest(TestCase):
self.tenant_users_url = "{0}/users".format(self.tenant_url)
self.user_role_url = "{0}/{1}/roles".format(self.tenant_users_url,
self.user_id)
self.role_id = "ROLE_ID"
self.tenant_user_role_url = "{0}/{1}/{2}".format(self.user_role_url,
self.admin_extensions,
self.role_id)
HTTPretty.enable()
@@ -104,11 +108,12 @@ class TenantsClientTest(TestCase):
self._build_assertions(actual_response, self.user_url)
def test_create_user_for_tenant(self):
HTTPretty.register_uri(HTTPretty.POST, self.users_url)
url = "{0}/v2.0/users".format(self.url)
HTTPretty.register_uri(HTTPretty.POST, url)
actual_response = self.tenant_api_client.create_user_for_a_tenant(
name="Admin", tenant_id=self.tenant_id)
self._build_assertions(actual_response, self.users_url)
self._build_assertions(actual_response, url)
def test_update_user(self):
HTTPretty.register_uri(HTTPretty.PUT, self.user_url)
@@ -133,12 +138,15 @@ class TenantsClientTest(TestCase):
tenant_id=self.tenant_id)
self._build_assertions(actual_response, self.tenant_users_url)
def test_create_role_for_tenant_user(self):
HTTPretty.register_uri(HTTPretty.POST, self.user_role_url)
def test_assign_role_to_tenant_user(self):
HTTPretty.register_uri(HTTPretty.PUT, self.tenant_user_role_url)
actual_response = self.tenant_api_client.create_role_for_tenant_user(
name="Admin", user_id=self.user_id, tenant_id=self.tenant_id)
self._build_assertions(actual_response, self.user_role_url)
actual_response = self.tenant_api_client.assign_role_to_tenant_user(
name="Admin",
user_id=self.user_id,
tenant_id=self.tenant_id,
role_id=self.role_id)
self._build_assertions(actual_response, self.tenant_user_role_url)
def test_get_users_roles_for_tenant(self):
HTTPretty.register_uri(HTTPretty.GET,
@@ -150,12 +158,14 @@ class TenantsClientTest(TestCase):
user_id=self.user_id)
self._build_assertions(actual_response, self.user_role_url)
def test_delete_role_of_tenant_user(self):
HTTPretty.register_uri(HTTPretty.DELETE, self.user_role_url)
def test_remove_role_of_tenant_user(self):
HTTPretty.register_uri(HTTPretty.DELETE, self.tenant_user_role_url)
actual_response = self.tenant_api_client.delete_role_of_tenant_user(
tenant_id=self.tenant_id, user_id=self.user_id)
self._build_assertions(actual_response, self.user_role_url)
actual_response = self.tenant_api_client.remove_role_of_tenant_user(
tenant_id=self.tenant_id,
user_id=self.user_id,
role_id=self.role_id)
self._build_assertions(actual_response, self.tenant_user_role_url)
def _build_assertions(self, actual_response, url):
assert HTTPretty.last_request.headers['Content-Type'] == \