Merge "Add Keystone Groups to REST API"

This commit is contained in:
Jenkins 2016-10-13 20:04:32 +00:00 committed by Gerrit Code Review
commit 47edc6b6de
4 changed files with 52 additions and 1 deletions

View File

@ -587,3 +587,21 @@ class Services(generic.View):
)
return {'items': services}
@urls.register
class Groups(generic.View):
"""API over all groups.
"""
url_regex = r'keystone/groups/$'
@rest_utils.ajax()
def get(self, request):
"""Get a list of groups.
The listing result is an object with property "items".
"""
domain_context = request.session.get('domain_context')
items = [d.to_dict() for d in api.keystone.group_list(
request, domain=request.GET.get('domain_id', domain_context))]
return {'items': items}

View File

@ -57,7 +57,8 @@
deleteProject: deleteProject,
grantRole: grantRole,
serviceCatalog: serviceCatalog,
getServices: getServices
getServices: getServices,
getGroups: getGroups
};
return service;
@ -102,6 +103,13 @@
});
}
function getGroups() {
return apiService.get('/api/keystone/groups/')
.error(function () {
toastService.add('error', gettext('Unable to fetch the groups.'));
});
}
/**
* @name getCurrentUserSession
* @param {Object} config - The configuration for which we want a session

View File

@ -384,6 +384,12 @@
"method": "get",
"path": "/api/keystone/services/",
"error": "Unable to fetch the services."
},
{
"func": "getGroups",
"method": "get",
"path": "/api/keystone/groups/",
"error": "Unable to fetch the groups."
}
];

View File

@ -673,6 +673,25 @@ class KeystoneRestTestCase(test.TestCase):
self.assertEqual(content['token'], 'token here')
self.assertNotIn('super_secret_thing', content)
#
# Groups
#
@mock.patch.object(keystone.api, 'keystone')
def test_group_get_list(self, kc):
request = self.mock_rest_request(**{
'session.get': mock.Mock(return_value='the_domain'),
'GET': {},
})
kc.group_list.return_value = [
mock.Mock(**{'to_dict.return_value': {'name': 'uno!'}}),
mock.Mock(**{'to_dict.return_value': {'name': 'dos!'}})
]
response = keystone.Groups().get(request)
self.assertStatusCode(response, 200)
self.assertEqual(response.json,
{"items": [{"name": "uno!"}, {"name": "dos!"}]})
kc.group_list.assert_called_once_with(request, domain='the_domain')
#
# Services
#