PUT and GET one tests for PoC API.
* added test for GET on a single ID * added test for PUT on an existing resource * fixed LocalResourceController to accept optional ID in new resource Change-Id: I487d21882b93e48cc38b87076a7c3d754a54fe84
This commit is contained in:
parent
41bf761a96
commit
a559ff5955
|
@ -79,7 +79,7 @@ class ResourceController(RestController):
|
|||
|
||||
return []
|
||||
|
||||
@wsexpose(Resource, six.text_type, Resource)
|
||||
@wsexpose(Resource, six.text_type, body=Resource)
|
||||
def put(self, id, resource):
|
||||
|
||||
self._controller.set_resource(id, resource_definition=resource)
|
||||
|
@ -89,6 +89,7 @@ class ResourceController(RestController):
|
|||
@wsexpose(Resource, body=Resource)
|
||||
def post(self, resource):
|
||||
|
||||
self._controller.set_resource(resource_definition=resource)
|
||||
id = resource.id if hasattr(resource, 'id') else None
|
||||
self._controller.set_resource(id, resource_definition=resource)
|
||||
|
||||
return resource
|
||||
|
|
|
@ -75,3 +75,107 @@ class TestGraffiti(pecan_base.TestCase):
|
|||
response = self.post_json('/resource', params=resource_json)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
self.assertEqual(response.content_type, 'application/json')
|
||||
|
||||
def test_get_one(self):
|
||||
resource_json = {
|
||||
"name": "Cirros",
|
||||
"id": "0000-0000-0000-0000",
|
||||
"description": "Some Image",
|
||||
"provider": {
|
||||
"id": "1111-1111-1111-1111"
|
||||
},
|
||||
"capabilities": [
|
||||
{
|
||||
"capability_type": "MySQL",
|
||||
"capability_type_namespace": "TestNamespace",
|
||||
"properties": [
|
||||
{
|
||||
"name": "CPU",
|
||||
"value": "4"
|
||||
},
|
||||
{
|
||||
"name": "RAM",
|
||||
"value": "4GB"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "os",
|
||||
"value": "ubuntu"
|
||||
},
|
||||
{
|
||||
"name": "os_version",
|
||||
"value": "12.04"
|
||||
}
|
||||
],
|
||||
"requirements": [
|
||||
{
|
||||
"capability_type": "Apache",
|
||||
"capability_type_namespace": "TestNamespace",
|
||||
"criterion": "Wayne !SLEEPING"
|
||||
}
|
||||
],
|
||||
"type": "OS::Image"}
|
||||
|
||||
self.post_json('/resource', params=resource_json)
|
||||
|
||||
response = self.get_json('/resource/%s' % resource_json['id'])
|
||||
self.assertEqual(response.status_int, 200)
|
||||
self.assertEqual(response.content_type, 'application/json')
|
||||
self.assertEqual(response.json['id'], resource_json['id'])
|
||||
|
||||
def test_put(self):
|
||||
resource_json = {
|
||||
"name": "Cirros",
|
||||
"id": "0000-0000-0000-0000",
|
||||
"description": "Some Image",
|
||||
"provider": {
|
||||
"id": "1111-1111-1111-1111"
|
||||
},
|
||||
"capabilities": [
|
||||
{
|
||||
"capability_type": "MySQL",
|
||||
"capability_type_namespace": "TestNamespace",
|
||||
"properties": [
|
||||
{
|
||||
"name": "CPU",
|
||||
"value": "4"
|
||||
},
|
||||
{
|
||||
"name": "RAM",
|
||||
"value": "4GB"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "os",
|
||||
"value": "ubuntu"
|
||||
},
|
||||
{
|
||||
"name": "os_version",
|
||||
"value": "12.04"
|
||||
}
|
||||
],
|
||||
"requirements": [
|
||||
{
|
||||
"capability_type": "Apache",
|
||||
"capability_type_namespace": "TestNamespace",
|
||||
"criterion": "Wayne !SLEEPING"
|
||||
}
|
||||
],
|
||||
"type": "OS::Image"}
|
||||
|
||||
self.post_json('/resource', params=resource_json)
|
||||
|
||||
resource_json["name"] = "Nimbulus"
|
||||
|
||||
response = self.put_json('/resource/%s' % resource_json['id'],
|
||||
params=resource_json)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
self.assertEqual(response.content_type, 'application/json')
|
||||
response_json = response.json
|
||||
self.assertEqual(response_json['name'], 'Nimbulus')
|
||||
|
|
Loading…
Reference in New Issue