Fix response body of getting role inference rule

The response body of getting role inference rule api lacks a 'links' object,
comparing with the api-ref [1]. This patch is to add the 'links' object to
make the response body consistent with the api-ref.

[1] https://developer.openstack.org/api-ref/identity/v3/index.html#get-role-inference-rule

Closes-Bug: 1691048
Change-Id: I31ddb4addce22cde68bfa2ff8ffd18386fd44136
This commit is contained in:
jeremy.zhang 2017-05-19 10:16:03 +08:00
parent bcd8d22afc
commit 600c7247bc
2 changed files with 26 additions and 0 deletions

View File

@ -500,6 +500,10 @@ class ImpliedRolesV3(controller.V3Controller):
implied_role = self.role_api.get_role(implied_id)
stanza = self._implied_role_stanza(endpoint, implied_role)
response["role_inference"]['implies'] = stanza
response["links"] = {
"self": (endpoint + "/v3/roles/" + prior_id
+ "/implies/" + implied_id)
}
return response
@controller.protected(callback=_check_implies_role)

View File

@ -2512,9 +2512,31 @@ class ImpliedRolesTests(test_v3.RestfulTestCase, test_v3.AssignmentTestMixin,
for implied in role_inference['implies']:
self.assertIsNotNone(implied['links']['self'])
def _assert_expected_role_inference_rule_response(
self, expected_prior_id, expected_implied_id):
url = '/roles/%s/implies/%s' % (expected_prior_id, expected_implied_id)
response = self.get(url).json
self.assertThat(response['links']['self'],
matchers.EndsWith('/v3%s' % url))
role_inference = response['role_inference']
prior_role = role_inference['prior_role']
self.assertEqual(expected_prior_id, prior_role['id'])
self.assertIsNotNone(prior_role['name'])
self.assertThat(prior_role['links']['self'],
matchers.EndsWith('/v3/roles/%s' % expected_prior_id))
implied_role = role_inference['implies']
self.assertEqual(expected_implied_id, implied_role['id'])
self.assertIsNotNone(implied_role['name'])
self.assertThat(implied_role['links']['self'], matchers.EndsWith(
'/v3/roles/%s' % expected_implied_id))
def _assert_two_roles_implied(self):
self._assert_expected_implied_role_response(
self.prior['id'], [self.implied1['id'], self.implied2['id']])
self._assert_expected_role_inference_rule_response(
self.prior['id'], self.implied1['id'])
self._assert_expected_role_inference_rule_response(
self.prior['id'], self.implied2['id'])
def _assert_one_role_implied(self):
self._assert_expected_implied_role_response(