Merge "Convert mox to mock: tests/compute/test_nova.py"

This commit is contained in:
Jenkins 2014-12-15 18:18:30 +00:00 committed by Gerrit Code Review
commit 40995e4434

View File

@ -12,6 +12,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import contextlib
import mock
from cinder.compute import nova from cinder.compute import nova
from cinder import context from cinder import context
from cinder import test from cinder import test
@ -39,14 +43,21 @@ class NovaApiTestCase(test.TestCase):
self.api = nova.API() self.api = nova.API()
self.novaclient = FakeNovaClient() self.novaclient = FakeNovaClient()
self.ctx = context.get_admin_context() self.ctx = context.get_admin_context()
self.mox.StubOutWithMock(nova, 'novaclient')
def test_update_server_volume(self): def test_update_server_volume(self):
nova.novaclient(self.ctx).AndReturn(self.novaclient) with contextlib.nested(
self.mox.StubOutWithMock(self.novaclient.volumes, mock.patch.object(nova, 'novaclient'),
'update_server_volume') mock.patch.object(self.novaclient.volumes,
self.novaclient.volumes.update_server_volume('server_id', 'attach_id', 'update_server_volume')
'new_volume_id') ) as (mock_novaclient, mock_update_server_volume):
self.mox.ReplayAll() mock_novaclient.return_value = self.novaclient
self.api.update_server_volume(self.ctx, 'server_id', 'attach_id',
'new_volume_id') 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'
)