Reviewed-by: Aline Manera <alinefm(a)linux.vnet.ibm.com>
On 01/20/2014 07:32 AM, lvroyce(a)linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
Add a testcase to test GET param passing and demo how GET param work
with current model implementation,which means:
1. change the API.json
2. wrap its model implementation to accept parameters
Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
---
tests/test_rest.py | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index a8e5842..dd2747b 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -1240,6 +1240,29 @@ class RestTests(unittest.TestCase):
self.assertIn('net_recv_rate', stats)
self.assertIn('net_sent_rate', stats)
+ def test_get_param(self):
+ req = json.dumps({'name': 'test', 'cdrom':
'/nonexistent.iso'})
+ self.request('/templates', req, 'POST')
+
+ # Create a VM
+ req = json.dumps({'name': 'test-vm1', 'template':
'/templates/test'})
+ resp = self.request('/vms', req, 'POST')
+ self.assertEquals(201, resp.status)
+ req = json.dumps({'name': 'test-vm2', 'template':
'/templates/test'})
+ resp = self.request('/vms', req, 'POST')
+ self.assertEquals(201, resp.status)
+
+ resp = request(host, port, '/vms')
+ self.assertEquals(200, resp.status)
+ res = json.loads(resp.read())
+ self.assertEquals(2, len(res))
+
+ resp = request(host, port, '/vms?name=test-vm1')
+ self.assertEquals(200, resp.status)
+ res = json.loads(resp.read())
+ self.assertEquals(1, len(res))
+ self.assertEquals('test-vm1', res[0]['name'])
+
class HttpsRestTests(RestTests):
"""