diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index d57f749b6..9e27302e7 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -69,28 +69,38 @@ def _stub_snapshot(**kwargs): return snapshot -def _stub_consistencygroup(**kwargs): +def _stub_consistencygroup(detailed=True, **kwargs): consistencygroup = { - "created_at": "2012-08-28T16:30:31.000000", - "description": None, "name": "cg", "id": "11111111-1111-1111-1111-111111111111", - "availability_zone": "myzone", - "status": "available", } + if detailed: + details = { + "created_at": "2012-08-28T16:30:31.000000", + "description": None, + "availability_zone": "myzone", + "status": "available", + } + consistencygroup.update(details) consistencygroup.update(kwargs) return consistencygroup -def _stub_cgsnapshot(**kwargs): +def _stub_cgsnapshot(detailed=True, **kwargs): cgsnapshot = { - "created_at": "2012-08-28T16:30:31.000000", - "description": None, "name": None, "id": "11111111-1111-1111-1111-111111111111", - "status": "available", - "consistencygroup_id": "00000000-0000-0000-0000-000000000000", } + if detailed: + details = { + "created_at": "2012-08-28T16:30:31.000000", + "description": None, + "name": None, + "id": "11111111-1111-1111-1111-111111111111", + "status": "available", + "consistencygroup_id": "00000000-0000-0000-0000-000000000000", + } + cgsnapshot.update(details) cgsnapshot.update(kwargs) return cgsnapshot @@ -458,6 +468,11 @@ class FakeHTTPClient(base_client.HTTPClient): _stub_consistencygroup(id='1234'), _stub_consistencygroup(id='4567')]}) + def get_consistencygroups(self, **kw): + return (200, {}, {"consistencygroups": [ + _stub_consistencygroup(detailed=False, id='1234'), + _stub_consistencygroup(detailed=False, id='4567')]}) + def get_consistencygroups_1234(self, **kw): return (200, {}, {'consistencygroup': _stub_consistencygroup(id='1234')}) @@ -465,6 +480,9 @@ class FakeHTTPClient(base_client.HTTPClient): def post_consistencygroups(self, **kw): return (202, {}, {'consistencygroup': {}}) + def put_consistencygroups_1234(self, **kw): + return (200, {}, {'consistencygroup': {}}) + def post_consistencygroups_1234_delete(self, **kw): return (202, {}, {}) @@ -477,12 +495,20 @@ class FakeHTTPClient(base_client.HTTPClient): _stub_cgsnapshot(id='1234'), _stub_cgsnapshot(id='4567')]}) + def get_cgsnapshots(self, **kw): + return (200, {}, {"cgsnapshots": [ + _stub_cgsnapshot(detailed=False, id='1234'), + _stub_cgsnapshot(detailed=False, id='4567')]}) + def get_cgsnapshots_1234(self, **kw): return (200, {}, {'cgsnapshot': _stub_cgsnapshot(id='1234')}) def post_cgsnapshots(self, **kw): return (202, {}, {'cgsnapshot': {}}) + def put_cgsnapshots_1234(self, **kw): + return (200, {}, {'cgsnapshot': {}}) + def delete_cgsnapshots_1234(self, **kw): return (202, {}, {}) diff --git a/cinderclient/tests/v2/test_cgsnapshots.py b/cinderclient/tests/v2/test_cgsnapshots.py index 0d5fad333..984344088 100644 --- a/cinderclient/tests/v2/test_cgsnapshots.py +++ b/cinderclient/tests/v2/test_cgsnapshots.py @@ -46,10 +46,35 @@ class cgsnapshotsTest(utils.TestCase): 'project_id': None}} cs.assert_called('POST', '/cgsnapshots', body=expected) + def test_update_cgsnapshot(self): + v = cs.cgsnapshots.list()[0] + expected = {'cgsnapshot': {'name': 'cgs2'}} + v.update(name='cgs2') + cs.assert_called('PUT', '/cgsnapshots/1234', body=expected) + cs.cgsnapshots.update('1234', name='cgs2') + cs.assert_called('PUT', '/cgsnapshots/1234', body=expected) + cs.cgsnapshots.update(v, name='cgs2') + cs.assert_called('PUT', '/cgsnapshots/1234', body=expected) + + def test_update_cgsnapshot_no_props(self): + cs.cgsnapshots.update('1234') + def test_list_cgsnapshot(self): cs.cgsnapshots.list() cs.assert_called('GET', '/cgsnapshots/detail') + def test_list_cgsnapshot_detailed_false(self): + cs.cgsnapshots.list(detailed=False) + cs.assert_called('GET', '/cgsnapshots') + + def test_list_cgsnapshot_with_search_opts(self): + cs.cgsnapshots.list(search_opts={'foo': 'bar'}) + cs.assert_called('GET', '/cgsnapshots/detail?foo=bar') + + def test_list_cgsnapshot_with_empty_search_opt(self): + cs.cgsnapshots.list(search_opts={'foo': 'bar', '123': None}) + cs.assert_called('GET', '/cgsnapshots/detail?foo=bar') + def test_get_cgsnapshot(self): cgsnapshot_id = '1234' cs.cgsnapshots.get(cgsnapshot_id) diff --git a/cinderclient/tests/v2/test_consistencygroups.py b/cinderclient/tests/v2/test_consistencygroups.py index 234cb3ce9..74136b9c2 100644 --- a/cinderclient/tests/v2/test_consistencygroups.py +++ b/cinderclient/tests/v2/test_consistencygroups.py @@ -47,6 +47,36 @@ class ConsistencygroupsTest(utils.TestCase): 'project_id': None}} cs.assert_called('POST', '/consistencygroups', body=expected) + def test_update_consistencygroup(self): + v = cs.consistencygroups.list()[0] + expected = {'consistencygroup': {'name': 'cg2'}} + v.update(name='cg2') + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update('1234', name='cg2') + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update(v, name='cg2') + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + + def test_update_consistencygroup_no_props(self): + cs.consistencygroups.update('1234') + def test_list_consistencygroup(self): cs.consistencygroups.list() cs.assert_called('GET', '/consistencygroups/detail') + + def test_list_consistencygroup_detailed_false(self): + cs.consistencygroups.list(detailed=False) + cs.assert_called('GET', '/consistencygroups') + + def test_list_consistencygroup_with_search_opts(self): + cs.consistencygroups.list(search_opts={'foo': 'bar'}) + cs.assert_called('GET', '/consistencygroups/detail?foo=bar') + + def test_list_consistencygroup_with_empty_search_opt(self): + cs.consistencygroups.list(search_opts={'foo': 'bar', 'abc': None}) + cs.assert_called('GET', '/consistencygroups/detail?foo=bar') + + def test_get_consistencygroup(self): + consistencygroup_id = '1234' + cs.consistencygroups.get(consistencygroup_id) + cs.assert_called('GET', '/consistencygroups/%s' % consistencygroup_id)