]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Stubout work in progress
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Wed, 10 Aug 2011 23:52:15 +0000 (00:52 +0100)
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Wed, 10 Aug 2011 23:52:15 +0000 (00:52 +0100)
quantum/client.py
tests/unit/client_tools/stubs.py [new file with mode: 0644]
tests/unit/test_cli.py

index ca05236faaec0a621bff28e8d3f74bf4c16bd2ef..3bc04ec452b5980e594d8d5e32c3dfc47e2ccf00 100644 (file)
@@ -19,6 +19,7 @@
 import httplib
 import socket
 import urllib
+
 from quantum.common.wsgi import Serializer
 
 
@@ -91,6 +92,13 @@ class Client(object):
         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):
         """
@@ -132,8 +140,7 @@ class Client(object):
             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,
diff --git a/tests/unit/client_tools/stubs.py b/tests/unit/client_tools/stubs.py
new file mode 100644 (file)
index 0000000..04a2e3c
--- /dev/null
@@ -0,0 +1,37 @@
+# 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    
index b662d6715d49b609504e928848e92f1cf575047d..d772ed32d7268b43f7a4fbb82b1f17c840fc8795 100644 (file)
 
 
 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')
 
@@ -34,8 +38,22 @@ class CLITest(unittest.TestCase):
 
     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