[Kimchi-devel] [PATCH 5/5] Update test cases

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Tue Apr 22 17:00:45 UTC 2014


Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>

On 04/17/2014 06:04 PM, Aline Manera wrote:
> From: Aline Manera <alinefm at br.ibm.com>
>
> Properly test new APIs /host/users and /host/groups
>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   tests/test_model.py |    8 ++++----
>   tests/test_rest.py  |   24 ++++++++++++++++++++----
>   2 files changed, 24 insertions(+), 8 deletions(-)
>
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 357d969..2fb4446 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -611,13 +611,13 @@ class ModelTests(unittest.TestCase):
>                                     u'пeω-∨м')
>   
>               # change only VM users - groups are not changed (default is empty)
> -            users = ['root']
> +            users = inst.users_get_list()[:3]
>               inst.vm_update(u'пeω-∨м', {'users': users})
>               self.assertEquals(users, inst.vm_lookup(u'пeω-∨м')['users'])
>               self.assertEquals([], inst.vm_lookup(u'пeω-∨м')['groups'])
>   
>               # change only VM groups - users are not changed (default is empty)
> -            groups = ['root']
> +            groups = inst.groups_get_list()[:2]
>               inst.vm_update(u'пeω-∨м', {'groups': groups})
>               self.assertEquals(users, inst.vm_lookup(u'пeω-∨м')['users'])
>               self.assertEquals(groups, inst.vm_lookup(u'пeω-∨м')['groups'])
> @@ -631,14 +631,14 @@ class ModelTests(unittest.TestCase):
>   
>               # change VM users (wrong value) and groups
>               # when an error occurs, everything fails and nothing is changed
> -            self.assertRaises(OperationFailed, inst.vm_update, u'пeω-∨м',
> +            self.assertRaises(InvalidParameter, inst.vm_update, u'пeω-∨м',
>                                 {'users': ['userdoesnotexist'], 'groups': []})
>               self.assertEquals(users, inst.vm_lookup(u'пeω-∨м')['users'])
>               self.assertEquals(groups, inst.vm_lookup(u'пeω-∨м')['groups'])
>   
>               # change VM users and groups (wrong value)
>               # when an error occurs, everything fails and nothing is changed
> -            self.assertRaises(OperationFailed, inst.vm_update, u'пeω-∨м',
> +            self.assertRaises(InvalidParameter, inst.vm_update, u'пeω-∨м',
>                                 {'users': [], 'groups': ['groupdoesnotexist']})
>               self.assertEquals(users, inst.vm_lookup(u'пeω-∨м')['users'])
>               self.assertEquals(groups, inst.vm_lookup(u'пeω-∨м')['groups'])
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index a40ba93..06396db 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -225,18 +225,34 @@ class RestTests(unittest.TestCase):
>           self.assertEquals(u'∨м-црdαtеd', vm['name'])
>   
>           # change only VM users - groups are not changed (default is empty)
> -        req = json.dumps({'users': ['root']})
> +        resp = self.request('/host/users', '{}', 'GET')
> +        users = json.loads(resp.read())
> +        req = json.dumps({'users': users})
>           resp = self.request('/vms/∨м-црdαtеd', req, 'PUT')
>           self.assertEquals(200, resp.status)
>           info = json.loads(self.request('/vms/∨м-црdαtеd', '{}').read())
> -        self.assertEquals(['root'], info['users'])
> +        self.assertEquals(users, info['users'])
>   
>           # change only VM groups - users are not changed (default is empty)
> -        req = json.dumps({'groups': ['kimchi']})
> +        resp = self.request('/host/groups', '{}', 'GET')
> +        groups = json.loads(resp.read())
> +        req = json.dumps({'groups': groups})
>           resp = self.request('/vms/∨м-црdαtеd', req, 'PUT')
>           self.assertEquals(200, resp.status)
>           info = json.loads(self.request('/vms/∨м-црdαtеd', '{}').read())
> -        self.assertEquals(['kimchi'], info['groups'])
> +        self.assertEquals(groups, info['groups'])
> +
> +        # change VM users (wrong value) and groups
> +        # when an error occurs, everything fails and nothing is changed
> +        req = json.dumps({'users': ['userdoesnotexist'], 'groups': []})
> +        resp = self.request('/vms/∨м-црdαtеd', req, 'PUT')
> +        self.assertEquals(400, resp.status)
> +
> +        # change VM users and groups (wrong value)
> +        # when an error occurs, everything fails and nothing is changed
> +        req = json.dumps({'users': [], 'groups': ['groupdoesnotexist']})
> +        resp = self.request('/vms/∨м-црdαtеd', req, 'PUT')
> +        self.assertEquals(400, resp.status)
>   
>       def test_vm_lifecycle(self):
>           # Create a Template




More information about the Kimchi-devel mailing list