import httplib
import socket
import urllib
+
from quantum.common.wsgi import Serializer
else:
return httplib.HTTPConnection
+ def _send_request(self, conn, method, action, body, headers):
+ # Salvatore: Isolating this piece of code in its own method to
+ # facilitate stubout for testing
+ conn.request(method, action, body, headers)
+ return conn.getresponse()
+
+
def do_request(self, method, action, body=None,
headers=None, params=None):
"""
else:
c = connection_type(self.host, self.port)
- c.request(method, action, body, headers)
- res = c.getresponse()
+ res = self._send_request(c, method, action, body, headers)
status_code = self.get_status_code(res)
if status_code in (httplib.OK,
httplib.CREATED,
--- /dev/null
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+""" Stubs for client tools unit tests """
+
+from quantum import client
+from tests.unit import testlib_api
+
+
+def stubout_send_request(stubs, api):
+ """Simulates a failure in fetch image_glance_disk."""
+
+ def fake_send_request(self, conn, method, action, body, headers):
+ # ignore headers and connection
+ req = testlib_api.create_request(action, body,
+ "application/json", method)
+ res = req.get_response(api)
+ return res
+
+ stubs.Set(client.Client, '_send_request', fake_send_request)
+
+class FakeHTTPConnection:
+ """ stub HTTP connection class for CLI testing """
+ pass
import logging
+import stubout
import sys
import unittest
from quantum import api as server
+from quantum import cli
+from quantum.db import api as db
+from tests.unit.client_tools import stubs as client_stubs
LOG = logging.getLogger('quantum.tests.test_cli')
def setUp(self):
"""Prepare the test environment"""
+ options = {}
+ options['plugin_provider'] = 'quantum.plugins.SamplePlugin.FakePlugin'
+ self.api = server.APIRouterV01(options)
+ self.tenant_id = "test_tenant"
+ self.network_name_1 = "test_network_1"
+ self.network_name_2 = "test_network_2"
+ # Stubout do_request
+ self.stubs = stubout.StubOutForTesting()
+ client_stubs.stubout_send_request(self.stubs, self.api)
+ # Redirect stdout
+ # Pre-populate data
pass
def tearDown(self):
"""Clear the test environment"""
+ db.clear_db()
+
+ def test_list_networks_api(self):
pass