summaryrefslogtreecommitdiff
path: root/quantumclient/tests
diff options
context:
space:
mode:
authorSalvatore Orlando <salv.orlando@gmail.com>2012-07-24 23:45:10 -0700
committerSalvatore Orlando <salv.orlando@gmail.com>2012-07-26 03:23:46 -0700
commitd16e00a056bbe7ba576c4b7195180bfc383bbfad (patch)
tree018f3cb8bb61a65eec4a9d13fc9bbcf79ba58561 /quantumclient/tests
parentd70620ce9665738965f8d9953ba9c81ec1a4e1c2 (diff)
downloadpython-neutronclient-d16e00a056bbe7ba576c4b7195180bfc383bbfad.tar.gz
Allow to retrieve objects by name
Fixes bug 979527 xxx-show commands now can accept either an id or a name of the resource to retrieve, similarly to the "nova get" command. This has been preferred to using mutually exclusive keyword argument, in order to avoid confusion with other CLI tools. NOTE: the current patch allow search by name only for networks. The restriction will be lifted once name attributes for port and subnets are added. Change-Id: Id186139a01c9f2cfc36ca3405b4024bd7780622e
Diffstat (limited to 'quantumclient/tests')
-rw-r--r--quantumclient/tests/unit/test_cli20.py42
-rw-r--r--quantumclient/tests/unit/test_cli20_network.py15
-rw-r--r--quantumclient/tests/unit/test_cli20_port.py15
-rw-r--r--quantumclient/tests/unit/test_cli20_subnet.py15
4 files changed, 69 insertions, 18 deletions
diff --git a/quantumclient/tests/unit/test_cli20.py b/quantumclient/tests/unit/test_cli20.py
index 14a153e..b58d65c 100644
--- a/quantumclient/tests/unit/test_cli20.py
+++ b/quantumclient/tests/unit/test_cli20.py
@@ -107,6 +107,8 @@ class MyComparator(Comparator):
class CLITestV20Base(unittest.TestCase):
+ test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+
def _url(self, path, query=None):
_url_str = self.endurl + "/v" + API_VERSION + path + "." + FORMAT
return query and _url_str + "?" + query or _url_str
@@ -242,16 +244,11 @@ class CLITestV20Base(unittest.TestCase):
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
- query = None
- for field in fields:
- if query:
- query += "&fields=" + field
- else:
- query = "fields=" + field
- resnetworks = {resource:
- {'id': myid,
+ query = "&".join(["fields=%s" % field for field in fields])
+ expected_res = {resource:
+ {'id': myid,
'name': 'myname', }, }
- resstr = self.client.serialize(resnetworks)
+ resstr = self.client.serialize(expected_res)
path = getattr(self.client, resource + "_path")
self.client.httpclient.request(
self._url(path % myid, query), 'GET',
@@ -269,6 +266,33 @@ class CLITestV20Base(unittest.TestCase):
self.assertTrue(myid in _str)
self.assertTrue('myname' in _str)
+ def _test_show_resource_by_name(self, resource, cmd, name,
+ args, fields=[]):
+ self.mox.StubOutWithMock(cmd, "get_client")
+ self.mox.StubOutWithMock(self.client.httpclient, "request")
+ cmd.get_client().MultipleTimes().AndReturn(self.client)
+ query = "&".join(["fields=%s" % field for field in fields])
+ expected_res = {"%ss" % resource:
+ [{'id': 'some_id',
+ 'name': name, }], }
+ resstr = self.client.serialize(expected_res)
+ list_path = getattr(self.client, resource + "s_path")
+ self.client.httpclient.request(
+ self._url(list_path, "%s&name=%s" % (query, name)), 'GET',
+ body=None,
+ headers=ContainsKeyValue('X-Auth-Token',
+ TOKEN)).AndReturn((MyResp(200), resstr))
+ self.mox.ReplayAll()
+ cmd_parser = cmd.get_parser("show_" + resource)
+
+ parsed_args = cmd_parser.parse_args(args)
+ cmd.run(parsed_args)
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+ _str = self.fake_stdout.make_string()
+ self.assertTrue(name in _str)
+ self.assertTrue('some_id' in _str)
+
def _test_delete_resource(self, resource, cmd, myid, args):
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
diff --git a/quantumclient/tests/unit/test_cli20_network.py b/quantumclient/tests/unit/test_cli20_network.py
index 69fcd1d..ad85dc6 100644
--- a/quantumclient/tests/unit/test_cli20_network.py
+++ b/quantumclient/tests/unit/test_cli20_network.py
@@ -125,9 +125,18 @@ class CLITestV20Network(CLITestV20Base):
"""Show net: --fields id --fields name myid."""
resource = 'network'
cmd = ShowNetwork(MyApp(sys.stdout), None)
- myid = 'myid'
- args = ['--fields', 'id', '--fields', 'name', myid]
- self._test_show_resource(resource, cmd, myid, args, ['id', 'name'])
+ args = ['--fields', 'id', '--fields', 'name', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id, args,
+ ['id', 'name'])
+
+ def test_show_network_by_name(self):
+ """Show net: --fields id --fields name myname."""
+ resource = 'network'
+ cmd = ShowNetwork(MyApp(sys.stdout), None)
+ myname = 'myname'
+ args = ['--fields', 'id', '--fields', 'name', myname]
+ self._test_show_resource_by_name(resource, cmd, myname,
+ args, ['id', 'name'])
def test_delete_network(self):
"""Delete net: myid."""
diff --git a/quantumclient/tests/unit/test_cli20_port.py b/quantumclient/tests/unit/test_cli20_port.py
index 427d473..676aaea 100644
--- a/quantumclient/tests/unit/test_cli20_port.py
+++ b/quantumclient/tests/unit/test_cli20_port.py
@@ -124,9 +124,18 @@ class CLITestV20Port(CLITestV20Base):
"""Show port: --fields id --fields name myid."""
resource = 'port'
cmd = ShowPort(MyApp(sys.stdout), None)
- myid = 'myid'
- args = ['--fields', 'id', '--fields', 'name', myid]
- self._test_show_resource(resource, cmd, myid, args, ['id', 'name'])
+ args = ['--fields', 'id', '--fields', 'name', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id,
+ args, ['id', 'name'])
+
+ def test_show_port_by_name(self):
+ """Show port: --fields id --fields name myname."""
+ resource = 'port'
+ cmd = ShowPort(MyApp(sys.stdout), None)
+ myname = 'myname'
+ args = ['--fields', 'id', '--fields', 'name', myname]
+ self._test_show_resource_by_name(resource, cmd, myname,
+ args, ['id', 'name'])
def test_delete_port(self):
"""Delete port: myid."""
diff --git a/quantumclient/tests/unit/test_cli20_subnet.py b/quantumclient/tests/unit/test_cli20_subnet.py
index b649b74..8783ed0 100644
--- a/quantumclient/tests/unit/test_cli20_subnet.py
+++ b/quantumclient/tests/unit/test_cli20_subnet.py
@@ -157,9 +157,18 @@ class CLITestV20Subnet(CLITestV20Base):
"""Show subnet: --fields id --fields name myid."""
resource = 'subnet'
cmd = ShowSubnet(MyApp(sys.stdout), None)
- myid = 'myid'
- args = ['--fields', 'id', '--fields', 'name', myid]
- self._test_show_resource(resource, cmd, myid, args, ['id', 'name'])
+ args = ['--fields', 'id', '--fields', 'name', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id,
+ args, ['id', 'name'])
+
+ def test_show_subnet_by_name(self):
+ """Show subnet: --fields id --fields name myname."""
+ resource = 'subnet'
+ cmd = ShowSubnet(MyApp(sys.stdout), None)
+ myname = 'myname'
+ args = ['--fields', 'id', '--fields', 'name', myname]
+ self._test_show_resource_by_name(resource, cmd, myname,
+ args, ['id', 'name'])
def test_delete_subnet(self):
"""Delete subnet: subnetid."""