def _verify_create_response(wrapper): self.assert_response(wrapper, 201, "Create policies failed.") response = json.loads(wrapper.content) self.assertEqual(len(request_body), len(response["policies"])) # this iterates over the response policies, checks to see that each # have 'id' and 'links' keys, and then checks to see that the rest # of the response policy is in the original set of policies to be #created for pol in response["policies"]: original_pol = pol.copy() for key in ('id', 'links'): self.assertIn(key, pol) del original_pol[key] self.assertIn(original_pol, request_body) # now make sure the Location header points to the list policies #header location = path_only(self.get_location_header(wrapper)) self.assertEqual(location, self.policies_url) links = [path_only(link["href"]) for link in pol["links"] if link["rel"] == "self" for pol in response["policies"]] return links
def _verify_create_response(wrapper): self.assert_response(wrapper, 201, "Create policies failed.") response = json.loads(wrapper.content) self.assertEqual(len(request_body), len(response["policies"])) # this iterates over the response policies, checks to see that each # have 'id' and 'links' keys, and then checks to see that the rest # of the response policy is in the original set of policies to be #created for pol in response["policies"]: original_pol = pol.copy() for key in ('id', 'links'): self.assertIn(key, pol) del original_pol[key] self.assertIn(original_pol, request_body) # now make sure the Location header points to the list policies #header location = path_only(self.get_location_header(wrapper)) self.assertEqual(location, self.policies_url) links = [ path_only(link["href"]) for link in pol["links"] if link["rel"] == "self" for pol in response["policies"] ] return links
def update_and_view_scaling_policy(self, path): """ Updating a scaling policy returns with a 204 no content. When viewing the policy again, it should contain the updated version. """ request_body = policy()[-1] # the one that was not created wrapper = yield request(root, 'PUT', path, body=json.dumps(request_body)) self.assert_response(wrapper, 204, "Update policy failed.") self.assertEqual(wrapper.content, "") # now try to view wrapper = yield request(root, 'GET', path) self.assert_response(wrapper, 200) response = json.loads(wrapper.content) updated = response['policy'] self.assertIn('id', updated) self.assertIn('links', updated) self.assertIn( path, [path_only(link["href"]) for link in updated["links"]]) del updated['id'] del updated['links'] self.assertEqual(updated, request_body)
def update_and_view_scaling_policy(self, path): """ Updating a scaling policy returns with a 204 no content. When viewing the policy again, it should contain the updated version. """ request_body = _policy()[-1] # the one that was not created wrapper = yield request(root, 'PUT', path, body=json.dumps(request_body)) self.assert_response(wrapper, 204, "Update policy failed.") self.assertEqual(wrapper.content, "") # now try to view wrapper = yield request(root, 'GET', path) self.assert_response(wrapper, 200) response = json.loads(wrapper.content) updated = response['policy'] self.assertIn('id', updated) self.assertIn('links', updated) self.assertIn(path, [path_only(link["href"]) for link in updated["links"]]) del updated['id'] del updated['links'] self.assertEqual(updated, request_body)
def _check_create_response(wrapper): # the body is probably verified by the unit tests - check the # header and status code self.assert_response(wrapper, 201, "Create failed.") # now make sure the Location header points to something good! return path_only(self.get_location_header(wrapper))