Add V2 user roles tests

The cross over between the user manager and the role manager is not
tested. As this will be changed soon re-enforce the current behaviour.

Change-Id: I3f8d8215a10cf09cfaad57ffa359f36d0417fb31
This commit is contained in:
Jamie Lennox
2014-07-04 10:11:12 +10:00
parent 552b4f46cf
commit 2635c994e0

View File

@@ -15,6 +15,7 @@ import uuid
import httpretty
from keystoneclient.tests.v2_0 import utils
from keystoneclient.v2_0 import roles
from keystoneclient.v2_0 import users
@@ -235,3 +236,49 @@ class UserTests(utils.TestCase):
self.client.user_id = user_id
self.client.users.update_own_password('DCBA', 'ABCD')
self.assertRequestBodyIs(json=req_body)
@httpretty.activate
def test_user_role_listing(self):
user_id = uuid.uuid4().hex
role_id1 = uuid.uuid4().hex
role_id2 = uuid.uuid4().hex
tenant_id = uuid.uuid4().hex
user_resp = {
'user': {
'id': user_id,
'email': uuid.uuid4().hex,
'name': uuid.uuid4().hex,
}
}
roles_resp = {
'roles': {
'values': [
{
'name': uuid.uuid4().hex,
'id': role_id1,
},
{
'name': uuid.uuid4().hex,
'id': role_id2,
}
]
}
}
self.stub_url(httpretty.GET,
['users', user_id],
json=user_resp)
self.stub_url(httpretty.GET,
['tenants', tenant_id, 'users', user_id, 'roles'],
json=roles_resp)
user = self.client.users.get(user_id)
role_objs = user.list_roles(tenant_id)
for r in role_objs:
self.assertIsInstance(r, roles.Role)
self.assertEqual(set([role_id1, role_id2]),
set([r.id for r in role_objs]))