[Kimchi-devel] [project-kimchi][PATCHv4 2/5] Add testcase for GET param
Shu Ming
shuming at linux.vnet.ibm.com
Fri Jan 3 02:13:47 UTC 2014
It seems that this test case is a generic test case for GET parameter,
not a test case showing the storage servers listing by target type. Why
should you have a generic test case?
2013/12/30 10:17, lvroyce at linux.vnet.ibm.com:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Add a testcase to test GET param passing.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
> tests/test_rest.py | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index f597796..42573fc 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -1056,6 +1056,43 @@ class RestTests(unittest.TestCase):
> self.assertIn('net_recv_rate', stats)
> self.assertIn('net_sent_rate', stats)
>
> + def test_get_param(self):
> + def hack_model(func):
> + def _get_param_func(*args, **kwargs):
> + key = kwargs.pop('name', None)
> + res = func(**kwargs)
> + if key and key in res:
> + res = [key]
> + return res
> + return _get_param_func
> +
> + global model
> + old_handler = model.vms_get_list
> + model.vms_get_list = hack_model(model.vms_get_list)
> +
> + 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'])
> +
> + model.vms_get_list = old_handler
>
> class HttpsRestTests(RestTests):
> """
More information about the Kimchi-devel
mailing list