Adds test_show_XX_fields cases to show some fields
This patch modifies the _show method to make it accept field_list.
It adds the cases to show some fields for network/subnet/port.
A related url example is
/v2.0/networks/103d47a3-XXXX-018c095ab35d?fields=id&fields=name
Change-Id: If2b9edd67ad0c43679332ec28ca80940c0c67d9e
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index 68ca66a..a064d44 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -114,6 +114,18 @@
self.assertEqual(self.name, network['name'])
@attr(type='smoke')
+ def test_show_network_fields(self):
+ # Verifies showing some fields of a network works
+ field_list = [('fields', 'id'), ('fields', 'name'), ]
+ resp, body = self.client.show_network(self.network['id'],
+ field_list=field_list)
+ self.assertEqual('200', resp['status'])
+ network = body['network']
+ self.assertEqual(len(network), 2)
+ self.assertEqual(self.network['id'], network['id'])
+ self.assertEqual(self.name, network['name'])
+
+ @attr(type='smoke')
def test_list_networks(self):
# Verify the network exists in the list of all networks
resp, body = self.client.list_networks()
@@ -136,6 +148,18 @@
self.assertEqual(self.cidr, subnet['cidr'])
@attr(type='smoke')
+ def test_show_subnet_fields(self):
+ # Verifies showing some fields of a subnet works
+ field_list = [('fields', 'id'), ('fields', 'cidr'), ]
+ resp, body = self.client.show_subnet(self.subnet['id'],
+ field_list=field_list)
+ self.assertEqual('200', resp['status'])
+ subnet = body['subnet']
+ self.assertEqual(len(subnet), 2)
+ self.assertEqual(self.subnet['id'], subnet['id'])
+ self.assertEqual(self.cidr, subnet['cidr'])
+
+ @attr(type='smoke')
def test_list_subnets(self):
# Verify the subnet exists in the list of all subnets
resp, body = self.client.list_subnets()
@@ -173,6 +197,17 @@
self.assertEqual(self.port['id'], port['id'])
@attr(type='smoke')
+ def test_show_port_fields(self):
+ # Verifies showing fields of a port works
+ field_list = [('fields', 'id'), ]
+ resp, body = self.client.show_port(self.port['id'],
+ field_list=field_list)
+ self.assertEqual('200', resp['status'])
+ port = body['port']
+ self.assertEqual(len(port), 1)
+ self.assertEqual(self.port['id'], port['id'])
+
+ @attr(type='smoke')
def test_list_ports(self):
# Verify the port exists in the list of all ports
resp, body = self.client.list_ports()
diff --git a/tempest/services/network/network_client_base.py b/tempest/services/network/network_client_base.py
index 42ca5bf..5ddf6ff 100644
--- a/tempest/services/network/network_client_base.py
+++ b/tempest/services/network/network_client_base.py
@@ -115,9 +115,14 @@
return _delete
def _shower(self, resource_name):
- def _show(resource_id):
+ def _show(resource_id, field_list=[]):
+ # field_list is a sequence of two-element tuples, with the
+ # first element being 'fields'. An example:
+ # [('fields', 'id'), ('fields', 'name')]
plural = self.pluralize(resource_name)
uri = '%s/%s' % (self.get_uri(plural), resource_id)
+ if field_list:
+ uri += '?' + urllib.urlencode(field_list)
resp, body = self.get(uri)
body = self.deserialize_single(body)
return resp, body