Revice REST APIs

Revice REST APIs and tests for BayModel and Container.

Change-Id: I78f0b0100c375187b38215aeb1f1e2fef2e07c1e
Closes-Bug: #1508778
This commit is contained in:
shu-mutou 2015-10-22 12:30:12 +09:00
parent 4738b11e07
commit 6d50eadcfb
3 changed files with 17 additions and 13 deletions

View File

@ -60,7 +60,7 @@ def baymodel_create(request, **kwargs):
else:
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(BAYMODEL_CREATE_ATTRS))
return magnumclient(request).baymodels.create(args)
return magnumclient(request).baymodels.create(**args)
def baymodel_delete(request, id):

View File

@ -63,8 +63,8 @@ class BayModels(generic.View):
"""
new_baymodel = magnum.baymodel_create(request, **request.DATA)
return rest_utils.CreatedResponse(
'/api/containers/baymodel/%s' % new_baymodel['uuid'],
new_baymodel)
'/api/containers/baymodel/%s' % new_baymodel.uuid,
new_baymodel.to_dict())
@urls.register
@ -137,4 +137,5 @@ class Containers(generic.View):
"""
container = magnum.container_create(request, **request.DATA)
return rest_utils.CreatedResponse(
'/api/containers/container/%s' % container['uuid'], container)
'/api/containers/container/%s' % container.uuid,
container.to_dict())

View File

@ -39,17 +39,18 @@ class MagnumRestTestCase(test.TestCase):
@mock.patch.object(magnum, 'magnum')
def test_baymodel_create(self, client):
test_baymodel = TEST.baymodels.first()
test_body = json.dumps(test_baymodel)
test_baymodels = mock_resource(TEST.baymodels.list())
test_bmodel = test_baymodels[0]
test_body = json.dumps(test_bmodel.to_dict())
request = self.mock_rest_request(body=test_body)
client.baymodel_create.return_value = test_baymodel
client.baymodel_create.return_value = test_bmodel
response = magnum.BayModels().post(request)
self.assertStatusCode(response, 201)
self.assertEqual(response['location'],
'/api/containers/baymodel/%s' % test_baymodel['uuid'])
'/api/containers/baymodel/%s' % test_bmodel.uuid)
client.baymodel_create.assert_called_once_with(request,
**test_baymodel)
**test_bmodel.to_dict())
@mock.patch.object(magnum, 'magnum')
def test_baymodel_delete(self, client):
@ -117,16 +118,18 @@ class MagnumRestTestCase(test.TestCase):
@mock.patch.object(magnum, 'magnum')
def test_container_create(self, client):
test_cont = TEST.magnum_containers.first()
test_body = json.dumps(test_cont)
test_conts = mock_resource(TEST.magnum_containers.list())
test_cont = test_conts[0]
test_body = json.dumps(test_cont.to_dict())
request = self.mock_rest_request(body=test_body)
client.container_create.return_value = test_cont
response = magnum.Containers().post(request)
self.assertStatusCode(response, 201)
self.assertEqual(response['location'],
'/api/containers/container/%s' % test_cont['uuid'])
client.container_create.assert_called_once_with(request, **test_cont)
'/api/containers/container/%s' % test_cont.uuid)
client.container_create.assert_called_once_with(request,
**test_cont.to_dict())
@mock.patch.object(magnum, 'magnum')
def test_container_delete(self, client):