except rpc_common.RemoteError as ex:
return util.remote_error(ex)
- raise exc.HTTPCreated(location=util.make_url(req, result))
+ return {'stack': format_stack(req, {engine_api.STACK_ID: result})}
@util.tenant_local
def lookup(self, req, stack_name, path='', body=None):
return {'resource_types': types}
+class StackSerializer(wsgi.JSONResponseSerializer):
+ """Handles serialization of specific controller method responses."""
+
+ def _populate_response_header(self, response, location, status):
+ response.status = status
+ response.headers['Location'] = location.encode('utf-8')
+ response.headers['Content-Type'] = 'application/json'
+ return response
+
+ def create(self, response, result):
+ self._populate_response_header(response,
+ result['stack']['links'][0]['href'],
+ 201)
+ response.body = self.to_json(result)
+ return response
+
+
def create_resource(options):
"""
Stacks resource factory method.
"""
# TODO(zaneb) handle XML based on Content-type/Accepts
deserializer = wsgi.JSONRequestDeserializer()
- serializer = wsgi.JSONResponseSerializer()
+ serializer = StackSerializer()
return wsgi.Resource(StackController(options), deserializer, serializer)
None).AndReturn(dict(identity))
self.m.ReplayAll()
- try:
- response = self.controller.create(req,
- tenant_id=identity.tenant,
- body=body)
- except webob.exc.HTTPCreated as created:
- self.assertEqual(created.location, self._url(identity))
- else:
- self.fail('HTTPCreated not raised')
+ response = self.controller.create(req,
+ tenant_id=identity.tenant,
+ body=body)
+
+ expected = {'stack':
+ {'id': '1',
+ 'links': [{'href': self._url(identity), 'rel': 'self'}]}}
+ self.assertEqual(response, expected)
+
self.m.VerifyAll()
def test_create_with_files(self):
None).AndReturn(dict(identity))
self.m.ReplayAll()
- try:
- response = self.controller.create(req,
- tenant_id=identity.tenant,
- body=body)
- except webob.exc.HTTPCreated as created:
- self.assertEqual(created.location, self._url(identity))
- else:
- self.fail('HTTPCreated not raised')
+ result = self.controller.create(req,
+ tenant_id=identity.tenant,
+ body=body)
+ expected = {'stack':
+ {'id': '1',
+ 'links': [{'href': self._url(identity), 'rel': 'self'}]}}
+ self.assertEqual(result, expected)
+
self.m.VerifyAll()
def test_create_err_rpcerr(self):
self.m.VerifyAll()
+class StackSerializerTest(HeatTestCase):
+
+ def setUp(self):
+ super(StackSerializerTest, self).setUp()
+ self.serializer = stacks.StackSerializer()
+
+ def test_serialize_create(self):
+ result = {'stack':
+ {'id': '1',
+ 'links': [{'href': 'location', "rel": "self"}]}}
+ response = webob.Response()
+ response = self.serializer.create(response, result)
+ self.assertEqual(response.status_int, 201)
+ self.assertEqual(response.headers['Location'], 'location')
+ self.assertEqual(response.headers['Content-Type'], 'application/json')
+
+
class ResourceControllerTest(ControllerTest, HeatTestCase):
'''
Tests the API class which acts as the WSGI controller,