From: Salvatore Orlando Date: Thu, 4 Aug 2011 15:56:46 +0000 (+0100) Subject: Cosmetic changes to unit tests for client library. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4819574b66756cd16133f7f6bba8c7941f06ea84;p=openstack-build%2Fneutron-build.git Cosmetic changes to unit tests for client library. Pep8 fixes. --- diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index 0e914dbee..6abb6bed7 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -61,9 +61,9 @@ class APIRouterV01(wsgi.Router): parent_resource=dict(member_name='network', collection_name=uri_prefix +\ 'networks')) - + attachments_ctrl = attachments.Controller(plugin) - + mapper.connect("get_resource", uri_prefix + 'networks/{network_id}/' \ 'ports/{id}/attachment{.format}', diff --git a/quantum/api/views/attachments.py b/quantum/api/views/attachments.py index f2d22039b..955495889 100644 --- a/quantum/api/views/attachments.py +++ b/quantum/api/views/attachments.py @@ -33,5 +33,5 @@ class ViewBuilder(object): """Generic method used to generate an attachment entity.""" if attachment_data['attachment-id']: return dict(attachment=dict(id=attachment_data['attachment-id'])) - else: + else: return dict(attachment={}) diff --git a/quantum/api/views/networks.py b/quantum/api/views/networks.py index 94fac5edd..5efb425ea 100644 --- a/quantum/api/views/networks.py +++ b/quantum/api/views/networks.py @@ -15,9 +15,6 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - -LOG = logging.getLogger('quantum.api.views.networks') def get_view_builder(req): base_url = req.application_url @@ -32,7 +29,8 @@ class ViewBuilder(object): """ 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.""" if net_detail: network = self._build_detail(network_data) @@ -41,7 +39,6 @@ class ViewBuilder(object): if port_detail: ports = [self._build_port(port_data) for port_data in ports_data] network['network']['ports'] = ports - LOG.debug("NETWORK:%s", network) return network def _build_simple(self, network_data): @@ -59,4 +56,4 @@ class ViewBuilder(object): state=port_data['port-state']) if port_data['attachment-id']: port_dict['attachment'] = dict(id=port_data['attachment-id']) - return port_dict + return port_dict diff --git a/quantum/db/api.py b/quantum/db/api.py index 3b065ea65..ebdc3cb1a 100644 --- a/quantum/db/api.py +++ b/quantum/db/api.py @@ -17,7 +17,7 @@ # @author: Brad Hall, Nicira Networks, Inc. # @author: Dan Wendlandt, Nicira Networks, Inc. -import logging +import logging from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, exc @@ -27,7 +27,8 @@ from quantum.db import models _ENGINE = None _MAKER = None BASE = models.BASE -LOG = logging.getLogger('quantum.plugins.SamplePlugin') +LOG = logging.getLogger('quantum.db.api') + def configure_db(options): """ diff --git a/tests/unit/api.py b/tests/unit/test_clientlib.py similarity index 83% rename from tests/unit/api.py rename to tests/unit/test_clientlib.py index aed6c4bac..eab58b2bd 100644 --- a/tests/unit/api.py +++ b/tests/unit/test_clientlib.py @@ -23,7 +23,7 @@ import re from quantum.common.wsgi import Serializer 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 TENANT_1 = 'totore' @@ -43,7 +43,7 @@ class ServerStub(): return self.content 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 def __init__(self, host, port=9696, key_file="", cert_file=""): @@ -88,7 +88,7 @@ class ServerStub(): return res -class APITest(unittest.TestCase): +class ClientLibTest(unittest.TestCase): def setUp(self): """ Setups a test environment for the API client """ @@ -118,8 +118,8 @@ class APITest(unittest.TestCase): return data def _test_list_networks(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_list_networks - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_list_networks - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.list_networks, status, @@ -128,13 +128,13 @@ class APITest(unittest.TestCase): data=[], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_list_networks - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_list_networks - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) - def _test_list_network_details(self, - tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_list_network_details - tenant:%s "\ - "- format:%s - START", format, tenant) + def _test_list_network_details(self, tenant=TENANT_1, + format='json', status=200): + LOG.debug("_test_list_network_details - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.list_network_details, status, @@ -143,12 +143,12 @@ class APITest(unittest.TestCase): data=["001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_list_network_details - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_list_network_details - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_create_network(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_create_network - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_create_network - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.create_network, status, @@ -157,12 +157,12 @@ class APITest(unittest.TestCase): data=[{'network': {'net-name': 'testNetwork'}}], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_create_network - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_create_network - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_update_network(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_update_network - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_update_network - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.update_network, status, @@ -172,12 +172,12 @@ class APITest(unittest.TestCase): {'network': {'net-name': 'newName'}}], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_update_network - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_update_network - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_delete_network(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_delete_network - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_delete_network - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.delete_network, status, @@ -186,12 +186,12 @@ class APITest(unittest.TestCase): data=["001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_delete_network - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_delete_network - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_list_ports(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_list_ports - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_list_ports - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.list_ports, status, @@ -200,13 +200,13 @@ class APITest(unittest.TestCase): data=["001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_list_ports - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_list_ports - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_list_port_details(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_list_port_details - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_list_port_details - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.list_port_details, status, @@ -215,12 +215,12 @@ class APITest(unittest.TestCase): data=["001", "001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_list_port_details - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_list_port_details - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_create_port(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_create_port - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_create_port - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.create_port, status, @@ -229,12 +229,12 @@ class APITest(unittest.TestCase): data=["001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_create_port - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_create_port - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_delete_port(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_delete_port - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_delete_port - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.delete_port, status, @@ -243,12 +243,12 @@ class APITest(unittest.TestCase): data=["001", "001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_delete_port - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_delete_port - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_set_port_state(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_set_port_state - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_set_port_state - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.set_port_state, status, @@ -258,13 +258,13 @@ class APITest(unittest.TestCase): {'port': {'state': 'ACTIVE'}}], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_set_port_state - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_set_port_state - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_list_port_attachments(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_list_port_attachments - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_list_port_attachments - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.list_port_attachments, status, @@ -273,13 +273,13 @@ class APITest(unittest.TestCase): data=["001", "001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_list_port_attachments - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_list_port_attachments - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_attach_resource(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_attach_resource - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_attach_resource - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.attach_resource, status, @@ -289,13 +289,13 @@ class APITest(unittest.TestCase): {'resource': {'id': '1234'}}], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_attach_resource - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_attach_resource - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_detach_resource(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_detach_resource - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_detach_resource - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) self._assert_sanity(self.client.detach_resource, status, @@ -304,13 +304,13 @@ class APITest(unittest.TestCase): data=["001", "001"], params={'tenant': tenant, 'format': format}) - LOG.debug("_test_detach_resource - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_detach_resource - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def _test_ssl_certificates(self, tenant=TENANT_1, format='json', status=200): - LOG.debug("_test_ssl_certificates - tenant:%s "\ - "- format:%s - START", format, tenant) + LOG.debug("_test_ssl_certificates - tenant:%(tenant)s "\ + "- format:%(format)s - START" % locals()) # Set SSL, and our cert file self.client.use_ssl = True @@ -327,8 +327,8 @@ class APITest(unittest.TestCase): self.assertEquals(data["key_file"], cert_file) self.assertEquals(data["cert_file"], cert_file) - LOG.debug("_test_ssl_certificates - tenant:%s "\ - "- format:%s - END", format, tenant) + LOG.debug("_test_ssl_certificates - tenant:%(tenant)s "\ + "- format:%(format)s - END" % locals()) def test_list_networks_json(self): self._test_list_networks(format='json')