]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Mock cinder.wsgi.Server in TestWSGIService
authorgit-harry <git-harry@live.co.uk>
Thu, 13 Nov 2014 21:50:23 +0000 (21:50 +0000)
committergit-harry <git-harry@live.co.uk>
Thu, 13 Nov 2014 21:50:23 +0000 (21:50 +0000)
The fixed tests were binding to port 8776. These unit tests should not
be starting the wsgi app and so the class has been mocked.

Change-Id: I52b8ce4788741a0802d4d91d413474101542a3e0
Closes-bug: #1392498

cinder/tests/test_service.py

index e7d1560df1bdb7dad5095e4e046718c24f90d209..e82e1c51c19a908c335f343e094c6dc836f24728 100644 (file)
@@ -232,26 +232,31 @@ class TestWSGIService(test.TestCase):
         self.assertEqual(test_service.server._pool.size,
                          1000)
 
-    def test_workers_set_default(self):
+    @mock.patch('cinder.wsgi.Server')
+    def test_workers_set_default(self, wsgi_server):
         test_service = service.WSGIService("osapi_volume")
         self.assertEqual(test_service.workers, processutils.get_worker_count())
 
-    def test_workers_set_good_user_setting(self):
+    @mock.patch('cinder.wsgi.Server')
+    def test_workers_set_good_user_setting(self, wsgi_server):
         self.override_config('osapi_volume_workers', 8)
         test_service = service.WSGIService("osapi_volume")
         self.assertEqual(test_service.workers, 8)
 
-    def test_workers_set_zero_user_setting(self):
+    @mock.patch('cinder.wsgi.Server')
+    def test_workers_set_zero_user_setting(self, wsgi_server):
         self.override_config('osapi_volume_workers', 0)
         test_service = service.WSGIService("osapi_volume")
         # If a value less than 1 is used, defaults to number of procs available
         self.assertEqual(test_service.workers, processutils.get_worker_count())
 
-    def test_workers_set_negative_user_setting(self):
+    @mock.patch('cinder.wsgi.Server')
+    def test_workers_set_negative_user_setting(self, wsgi_server):
         self.override_config('osapi_volume_workers', -1)
         self.assertRaises(exception.InvalidInput,
                           service.WSGIService,
                           "osapi_volume")
+        self.assertFalse(wsgi_server.called)
 
 
 class OSCompatibilityTestCase(test.TestCase):