Cosmetic changes to unit tests for client library.
Pep8 fixes.
This commit is contained in:
parent
303eb0bedb
commit
4819574b66
|
@ -61,9 +61,9 @@ class APIRouterV01(wsgi.Router):
|
||||||
parent_resource=dict(member_name='network',
|
parent_resource=dict(member_name='network',
|
||||||
collection_name=uri_prefix +\
|
collection_name=uri_prefix +\
|
||||||
'networks'))
|
'networks'))
|
||||||
|
|
||||||
attachments_ctrl = attachments.Controller(plugin)
|
attachments_ctrl = attachments.Controller(plugin)
|
||||||
|
|
||||||
mapper.connect("get_resource",
|
mapper.connect("get_resource",
|
||||||
uri_prefix + 'networks/{network_id}/' \
|
uri_prefix + 'networks/{network_id}/' \
|
||||||
'ports/{id}/attachment{.format}',
|
'ports/{id}/attachment{.format}',
|
||||||
|
|
|
@ -33,5 +33,5 @@ class ViewBuilder(object):
|
||||||
"""Generic method used to generate an attachment entity."""
|
"""Generic method used to generate an attachment entity."""
|
||||||
if attachment_data['attachment-id']:
|
if attachment_data['attachment-id']:
|
||||||
return dict(attachment=dict(id=attachment_data['attachment-id']))
|
return dict(attachment=dict(id=attachment_data['attachment-id']))
|
||||||
else:
|
else:
|
||||||
return dict(attachment={})
|
return dict(attachment={})
|
||||||
|
|
|
@ -15,9 +15,6 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
LOG = logging.getLogger('quantum.api.views.networks')
|
|
||||||
|
|
||||||
def get_view_builder(req):
|
def get_view_builder(req):
|
||||||
base_url = req.application_url
|
base_url = req.application_url
|
||||||
|
@ -32,7 +29,8 @@ class ViewBuilder(object):
|
||||||
"""
|
"""
|
||||||
self.base_url = base_url
|
self.base_url = base_url
|
||||||
|
|
||||||
def build(self, network_data, net_detail=False, ports_data=None, port_detail=False):
|
def build(self, network_data, net_detail=False,
|
||||||
|
ports_data=None, port_detail=False):
|
||||||
"""Generic method used to generate a network entity."""
|
"""Generic method used to generate a network entity."""
|
||||||
if net_detail:
|
if net_detail:
|
||||||
network = self._build_detail(network_data)
|
network = self._build_detail(network_data)
|
||||||
|
@ -41,7 +39,6 @@ class ViewBuilder(object):
|
||||||
if port_detail:
|
if port_detail:
|
||||||
ports = [self._build_port(port_data) for port_data in ports_data]
|
ports = [self._build_port(port_data) for port_data in ports_data]
|
||||||
network['network']['ports'] = ports
|
network['network']['ports'] = ports
|
||||||
LOG.debug("NETWORK:%s", network)
|
|
||||||
return network
|
return network
|
||||||
|
|
||||||
def _build_simple(self, network_data):
|
def _build_simple(self, network_data):
|
||||||
|
@ -59,4 +56,4 @@ class ViewBuilder(object):
|
||||||
state=port_data['port-state'])
|
state=port_data['port-state'])
|
||||||
if port_data['attachment-id']:
|
if port_data['attachment-id']:
|
||||||
port_dict['attachment'] = dict(id=port_data['attachment-id'])
|
port_dict['attachment'] = dict(id=port_data['attachment-id'])
|
||||||
return port_dict
|
return port_dict
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
# @author: Brad Hall, Nicira Networks, Inc.
|
# @author: Brad Hall, Nicira Networks, Inc.
|
||||||
# @author: Dan Wendlandt, Nicira Networks, Inc.
|
# @author: Dan Wendlandt, Nicira Networks, Inc.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker, exc
|
from sqlalchemy.orm import sessionmaker, exc
|
||||||
|
@ -27,7 +27,8 @@ from quantum.db import models
|
||||||
_ENGINE = None
|
_ENGINE = None
|
||||||
_MAKER = None
|
_MAKER = None
|
||||||
BASE = models.BASE
|
BASE = models.BASE
|
||||||
LOG = logging.getLogger('quantum.plugins.SamplePlugin')
|
LOG = logging.getLogger('quantum.db.api')
|
||||||
|
|
||||||
|
|
||||||
def configure_db(options):
|
def configure_db(options):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -23,7 +23,7 @@ import re
|
||||||
from quantum.common.wsgi import Serializer
|
from quantum.common.wsgi import Serializer
|
||||||
from quantum.client import Client
|
from quantum.client import Client
|
||||||
|
|
||||||
LOG = logging.getLogger('quantum.tests.test_api')
|
LOG = logging.getLogger('quantum.tests.test_cliet')
|
||||||
|
|
||||||
# Set a couple tenants to use for testing
|
# Set a couple tenants to use for testing
|
||||||
TENANT_1 = 'totore'
|
TENANT_1 = 'totore'
|
||||||
|
@ -43,7 +43,7 @@ class ServerStub():
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
return status
|
return self.status
|
||||||
|
|
||||||
# To test error codes, set the host to 10.0.0.1, and the port to the code
|
# To test error codes, set the host to 10.0.0.1, and the port to the code
|
||||||
def __init__(self, host, port=9696, key_file="", cert_file=""):
|
def __init__(self, host, port=9696, key_file="", cert_file=""):
|
||||||
|
@ -88,7 +88,7 @@ class ServerStub():
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
class APITest(unittest.TestCase):
|
class ClientLibTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
""" Setups a test environment for the API client """
|
""" Setups a test environment for the API client """
|
||||||
|
@ -118,8 +118,8 @@ class APITest(unittest.TestCase):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _test_list_networks(self, tenant=TENANT_1, format='json', status=200):
|
def _test_list_networks(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_networks - tenant:%s "\
|
LOG.debug("_test_list_networks - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_networks,
|
self._assert_sanity(self.client.list_networks,
|
||||||
status,
|
status,
|
||||||
|
@ -128,13 +128,13 @@ class APITest(unittest.TestCase):
|
||||||
data=[],
|
data=[],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_networks - tenant:%s "\
|
LOG.debug("_test_list_networks - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_list_network_details(self,
|
def _test_list_network_details(self, tenant=TENANT_1,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_list_network_details - tenant:%s "\
|
LOG.debug("_test_list_network_details - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_network_details,
|
self._assert_sanity(self.client.list_network_details,
|
||||||
status,
|
status,
|
||||||
|
@ -143,12 +143,12 @@ class APITest(unittest.TestCase):
|
||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_network_details - tenant:%s "\
|
LOG.debug("_test_list_network_details - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_create_network(self, tenant=TENANT_1, format='json', status=200):
|
def _test_create_network(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_create_network - tenant:%s "\
|
LOG.debug("_test_create_network - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.create_network,
|
self._assert_sanity(self.client.create_network,
|
||||||
status,
|
status,
|
||||||
|
@ -157,12 +157,12 @@ class APITest(unittest.TestCase):
|
||||||
data=[{'network': {'net-name': 'testNetwork'}}],
|
data=[{'network': {'net-name': 'testNetwork'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_create_network - tenant:%s "\
|
LOG.debug("_test_create_network - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_update_network(self, tenant=TENANT_1, format='json', status=200):
|
def _test_update_network(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_update_network - tenant:%s "\
|
LOG.debug("_test_update_network - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.update_network,
|
self._assert_sanity(self.client.update_network,
|
||||||
status,
|
status,
|
||||||
|
@ -172,12 +172,12 @@ class APITest(unittest.TestCase):
|
||||||
{'network': {'net-name': 'newName'}}],
|
{'network': {'net-name': 'newName'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_update_network - tenant:%s "\
|
LOG.debug("_test_update_network - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_delete_network(self, tenant=TENANT_1, format='json', status=200):
|
def _test_delete_network(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_delete_network - tenant:%s "\
|
LOG.debug("_test_delete_network - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.delete_network,
|
self._assert_sanity(self.client.delete_network,
|
||||||
status,
|
status,
|
||||||
|
@ -186,12 +186,12 @@ class APITest(unittest.TestCase):
|
||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_delete_network - tenant:%s "\
|
LOG.debug("_test_delete_network - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_list_ports(self, tenant=TENANT_1, format='json', status=200):
|
def _test_list_ports(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_ports - tenant:%s "\
|
LOG.debug("_test_list_ports - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_ports,
|
self._assert_sanity(self.client.list_ports,
|
||||||
status,
|
status,
|
||||||
|
@ -200,13 +200,13 @@ class APITest(unittest.TestCase):
|
||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_ports - tenant:%s "\
|
LOG.debug("_test_list_ports - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_list_port_details(self,
|
def _test_list_port_details(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_port_details - tenant:%s "\
|
LOG.debug("_test_list_port_details - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_port_details,
|
self._assert_sanity(self.client.list_port_details,
|
||||||
status,
|
status,
|
||||||
|
@ -215,12 +215,12 @@ class APITest(unittest.TestCase):
|
||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_port_details - tenant:%s "\
|
LOG.debug("_test_list_port_details - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_create_port(self, tenant=TENANT_1, format='json', status=200):
|
def _test_create_port(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_create_port - tenant:%s "\
|
LOG.debug("_test_create_port - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.create_port,
|
self._assert_sanity(self.client.create_port,
|
||||||
status,
|
status,
|
||||||
|
@ -229,12 +229,12 @@ class APITest(unittest.TestCase):
|
||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_create_port - tenant:%s "\
|
LOG.debug("_test_create_port - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_delete_port(self, tenant=TENANT_1, format='json', status=200):
|
def _test_delete_port(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_delete_port - tenant:%s "\
|
LOG.debug("_test_delete_port - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.delete_port,
|
self._assert_sanity(self.client.delete_port,
|
||||||
status,
|
status,
|
||||||
|
@ -243,12 +243,12 @@ class APITest(unittest.TestCase):
|
||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_delete_port - tenant:%s "\
|
LOG.debug("_test_delete_port - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_set_port_state(self, tenant=TENANT_1, format='json', status=200):
|
def _test_set_port_state(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_set_port_state - tenant:%s "\
|
LOG.debug("_test_set_port_state - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.set_port_state,
|
self._assert_sanity(self.client.set_port_state,
|
||||||
status,
|
status,
|
||||||
|
@ -258,13 +258,13 @@ class APITest(unittest.TestCase):
|
||||||
{'port': {'state': 'ACTIVE'}}],
|
{'port': {'state': 'ACTIVE'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_set_port_state - tenant:%s "\
|
LOG.debug("_test_set_port_state - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_list_port_attachments(self,
|
def _test_list_port_attachments(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_port_attachments - tenant:%s "\
|
LOG.debug("_test_list_port_attachments - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_port_attachments,
|
self._assert_sanity(self.client.list_port_attachments,
|
||||||
status,
|
status,
|
||||||
|
@ -273,13 +273,13 @@ class APITest(unittest.TestCase):
|
||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_port_attachments - tenant:%s "\
|
LOG.debug("_test_list_port_attachments - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_attach_resource(self, tenant=TENANT_1,
|
def _test_attach_resource(self, tenant=TENANT_1,
|
||||||
format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_attach_resource - tenant:%s "\
|
LOG.debug("_test_attach_resource - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.attach_resource,
|
self._assert_sanity(self.client.attach_resource,
|
||||||
status,
|
status,
|
||||||
|
@ -289,13 +289,13 @@ class APITest(unittest.TestCase):
|
||||||
{'resource': {'id': '1234'}}],
|
{'resource': {'id': '1234'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_attach_resource - tenant:%s "\
|
LOG.debug("_test_attach_resource - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_detach_resource(self, tenant=TENANT_1,
|
def _test_detach_resource(self, tenant=TENANT_1,
|
||||||
format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_detach_resource - tenant:%s "\
|
LOG.debug("_test_detach_resource - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
self._assert_sanity(self.client.detach_resource,
|
self._assert_sanity(self.client.detach_resource,
|
||||||
status,
|
status,
|
||||||
|
@ -304,13 +304,13 @@ class APITest(unittest.TestCase):
|
||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_detach_resource - tenant:%s "\
|
LOG.debug("_test_detach_resource - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def _test_ssl_certificates(self, tenant=TENANT_1,
|
def _test_ssl_certificates(self, tenant=TENANT_1,
|
||||||
format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_ssl_certificates - tenant:%s "\
|
LOG.debug("_test_ssl_certificates - tenant:%(tenant)s "\
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%(format)s - START" % locals())
|
||||||
|
|
||||||
# Set SSL, and our cert file
|
# Set SSL, and our cert file
|
||||||
self.client.use_ssl = True
|
self.client.use_ssl = True
|
||||||
|
@ -327,8 +327,8 @@ class APITest(unittest.TestCase):
|
||||||
self.assertEquals(data["key_file"], cert_file)
|
self.assertEquals(data["key_file"], cert_file)
|
||||||
self.assertEquals(data["cert_file"], cert_file)
|
self.assertEquals(data["cert_file"], cert_file)
|
||||||
|
|
||||||
LOG.debug("_test_ssl_certificates - tenant:%s "\
|
LOG.debug("_test_ssl_certificates - tenant:%(tenant)s "\
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%(format)s - END" % locals())
|
||||||
|
|
||||||
def test_list_networks_json(self):
|
def test_list_networks_json(self):
|
||||||
self._test_list_networks(format='json')
|
self._test_list_networks(format='json')
|
Loading…
Reference in New Issue