]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Convert mox to mock: tests/compute/test_nova.py
authorBala Gopal Raj <balagopalraj@techpatron.co.in>
Fri, 12 Dec 2014 09:30:43 +0000 (04:30 -0500)
committerHuang Zhiteng <winston.d@gmail.com>
Mon, 15 Dec 2014 07:14:54 +0000 (07:14 +0000)
Replace mox testing library by mock in the file
cinder/tests/compute/test_nova.py

Implements: blueprint mox-to-mock-conversion
Change-Id: Ic819afb4391708a0afebe4fc2855c93e3cb3f4c4

cinder/tests/compute/test_nova.py

index 0aff99d7e975845c58d28bd5922ccc3826add46b..9196917f2d16b96dc21f663d14bb931fbb3ca45c 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import contextlib
+
+import mock
+
 from cinder.compute import nova
 from cinder import context
 from cinder import test
@@ -39,14 +43,21 @@ class NovaApiTestCase(test.TestCase):
         self.api = nova.API()
         self.novaclient = FakeNovaClient()
         self.ctx = context.get_admin_context()
-        self.mox.StubOutWithMock(nova, 'novaclient')
 
     def test_update_server_volume(self):
-        nova.novaclient(self.ctx).AndReturn(self.novaclient)
-        self.mox.StubOutWithMock(self.novaclient.volumes,
-                                 'update_server_volume')
-        self.novaclient.volumes.update_server_volume('server_id', 'attach_id',
-                                                     'new_volume_id')
-        self.mox.ReplayAll()
-        self.api.update_server_volume(self.ctx, 'server_id', 'attach_id',
-                                      'new_volume_id')
+        with contextlib.nested(
+                mock.patch.object(nova, 'novaclient'),
+                mock.patch.object(self.novaclient.volumes,
+                                  'update_server_volume')
+        ) as (mock_novaclient, mock_update_server_volume):
+            mock_novaclient.return_value = self.novaclient
+
+            self.api.update_server_volume(self.ctx, 'server_id',
+                                          'attach_id', 'new_volume_id')
+
+        mock_novaclient.assert_called_once_with(self.ctx)
+        mock_update_server_volume.assert_called_once_with(
+            'server_id',
+            'attach_id',
+            'new_volume_id'
+        )