Check and delete for policy_association_for_region_and_service

Calls proper function in the manager and driver

Unit tests now check pre- and post- conditions on CRUD

Change-Id: I26e4d4f15ff39dd76141aa5fb7aae1ebb6680bf7
Closes-bug: 1400362
This commit is contained in:
Adam Young 2014-12-08 14:12:24 -05:00 committed by Brant Knudson
parent 9ee165f19d
commit 1c615db7f2
2 changed files with 24 additions and 17 deletions

View File

@ -120,7 +120,7 @@ class EndpointPolicyV3Controller(controller.V3Controller):
self.policy_api.get_policy(policy_id)
self.catalog_api.get_service(service_id)
self.catalog_api.get_region(region_id)
self.endpoint_policy_api.create_policy_association(
self.endpoint_policy_api.check_policy_association(
policy_id, service_id=service_id, region_id=region_id)
@controller.protected()
@ -130,7 +130,7 @@ class EndpointPolicyV3Controller(controller.V3Controller):
self.policy_api.get_policy(policy_id)
self.catalog_api.get_service(service_id)
self.catalog_api.get_region(region_id)
self.endpoint_policy_api.create_policy_association(
self.endpoint_policy_api.delete_policy_association(
policy_id, service_id=service_id, region_id=region_id)
@controller.protected()

View File

@ -47,7 +47,26 @@ class EndpointPolicyTestCase(TestExtensionCase):
self.region = self.new_region_ref()
self.catalog_api.create_region(self.region)
def assert_head_and_get_return_same_response(self, url, expected_status):
self.get(url, expected_status=expected_status)
self.head(url, expected_status=expected_status)
# endpoint policy crud tests
def _crud_test(self, url):
# Test when the resource does not exist also ensures
# that there is not a false negative after creation.
self.assert_head_and_get_return_same_response(url, expected_status=404)
self.put(url, expected_status=204)
# test that the new resource is accessible.
self.assert_head_and_get_return_same_response(url, expected_status=204)
self.delete(url, expected_status=204)
# test that the deleted resource is no longer accessible
self.assert_head_and_get_return_same_response(url, expected_status=404)
def test_crud_for_policy_for_explicit_endpoint(self):
"""PUT, HEAD and DELETE for explicit endpoint policy."""
@ -56,11 +75,7 @@ class EndpointPolicyTestCase(TestExtensionCase):
'/endpoints/%(endpoint_id)s') % {
'policy_id': self.policy['id'],
'endpoint_id': self.endpoint['id']}
self.put(url, expected_status=204)
self.get(url, expected_status=204)
self.head(url, expected_status=204)
self.delete(url, expected_status=204)
self._crud_test(url)
def test_crud_for_policy_for_service(self):
"""PUT, HEAD and DELETE for service endpoint policy."""
@ -69,11 +84,7 @@ class EndpointPolicyTestCase(TestExtensionCase):
'/services/%(service_id)s') % {
'policy_id': self.policy['id'],
'service_id': self.service['id']}
self.put(url, expected_status=204)
self.get(url, expected_status=204)
self.head(url, expected_status=204)
self.delete(url, expected_status=204)
self._crud_test(url)
def test_crud_for_policy_for_region_and_service(self):
"""PUT, HEAD and DELETE for region and service endpoint policy."""
@ -83,11 +94,7 @@ class EndpointPolicyTestCase(TestExtensionCase):
'policy_id': self.policy['id'],
'service_id': self.service['id'],
'region_id': self.region['id']}
self.put(url, expected_status=204)
self.get(url, expected_status=204)
self.head(url, expected_status=204)
self.delete(url, expected_status=204)
self._crud_test(url)
def test_get_policy_for_endpoint(self):
"""GET /endpoints/{endpoint_id}/policy."""