diff options
author | Akihiro Motoki <motoki@da.jp.nec.com> | 2016-08-01 09:33:20 +0000 |
---|---|---|
committer | Akihiro Motoki <motoki@da.jp.nec.com> | 2016-08-02 05:09:41 +0000 |
commit | 092c3e5e91a89fd63040df0477202a4607409abc (patch) | |
tree | 0b8a5a44a575b63b9251b1618d3836cb1ac2e271 | |
parent | 389aae7d16468136ff70b6b6802bf85f1a1aefb4 (diff) | |
download | python-neutronclient-092c3e5e91a89fd63040df0477202a4607409abc.tar.gz |
Make find_resourceid_by_id public in python binding class
This is a regression of Iec3e9b379255111f5390325778a1d07bf73b29d.
The unit test coverage was missing.
Change-Id: I0fc5d6dedf469ea70854a53b4e79f3b8bf9206a6
Closes-Bug: #1608403
-rw-r--r-- | neutronclient/tests/unit/test_name_or_id.py | 35 | ||||
-rw-r--r-- | neutronclient/v2_0/client.py | 8 |
2 files changed, 39 insertions, 4 deletions
diff --git a/neutronclient/tests/unit/test_name_or_id.py b/neutronclient/tests/unit/test_name_or_id.py index 7ae3ff9..dcb9a23 100644 --- a/neutronclient/tests/unit/test_name_or_id.py +++ b/neutronclient/tests/unit/test_name_or_id.py @@ -190,3 +190,38 @@ class CLITestNameorID(testtools.TestCase): self.client, 'security_group', name, project) self.assertIn('Unable to find', exc.message) self.assertEqual(404, exc.status_code) + + def _test_get_resource_by_id(self, id_only=False): + _id = str(uuid.uuid4()) + net = {'id': _id, 'name': 'test'} + reses = {'networks': [net], } + resstr = self.client.serialize(reses) + self.mox.StubOutWithMock(self.client.httpclient, "request") + path = getattr(self.client, "networks_path") + if id_only: + query_params = "fields=id&id=%s" % _id + else: + query_params = "id=%s" % _id + self.client.httpclient.request( + test_cli20.MyUrlComparator( + test_cli20.end_url(path, query_params), + self.client), + 'GET', + body=None, + headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN) + ).AndReturn((test_cli20.MyResp(200), resstr)) + self.mox.ReplayAll() + if id_only: + returned_id = neutronV20.find_resourceid_by_id( + self.client, 'network', _id) + self.assertEqual(_id, returned_id) + else: + result = neutronV20.find_resource_by_id( + self.client, 'network', _id) + self.assertEqual(net, result) + + def test_get_resource_by_id(self): + self._test_get_resource_by_id(id_only=False) + + def test_get_resourceid_by_id(self): + self._test_get_resource_by_id(id_only=True) diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index 0b5ca6b..eaa0846 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -408,8 +408,8 @@ class ClientBase(object): return k return resource + 's' - def _find_resource_by_id(self, resource, resource_id, cmd_resource=None, - parent_id=None, fields=None): + def find_resource_by_id(self, resource, resource_id, cmd_resource=None, + parent_id=None, fields=None): if not cmd_resource: cmd_resource = resource cmd_resource_plural = self.get_resource_plural(cmd_resource) @@ -469,8 +469,8 @@ class ClientBase(object): def find_resource(self, resource, name_or_id, project_id=None, cmd_resource=None, parent_id=None, fields=None): try: - return self._find_resource_by_id(resource, name_or_id, - cmd_resource, parent_id, fields) + return self.find_resource_by_id(resource, name_or_id, + cmd_resource, parent_id, fields) except exceptions.NotFound: try: return self._find_resource_by_name( |