def test_upload_image_is_delegated_to_command(self): command = self.mox.CreateMock(vdi_through_dev.UploadToGlanceAsRawTgz) self.mox.StubOutWithMock(vdi_through_dev, 'UploadToGlanceAsRawTgz') vdi_through_dev.UploadToGlanceAsRawTgz('ctx', 'session', 'instance', 'image_id', 'vdis').AndReturn(command) command.upload_image().AndReturn('result') self.mox.ReplayAll() store = vdi_through_dev.VdiThroughDevStore() result = store.upload_image('ctx', 'session', 'instance', 'image_id', 'vdis') self.assertEqual('result', result)
def test_upload_image_is_delegated_to_command(self): command = mock.create_autospec(vdi_through_dev.UploadToGlanceAsRawTgz, spec_set=True) command.upload_image.return_value = 'result' with mock.patch.object(vdi_through_dev, 'UploadToGlanceAsRawTgz', return_value=command) as mock_upload: store = vdi_through_dev.VdiThroughDevStore() result = store.upload_image( 'ctx', 'session', 'instance', 'image_id', 'vdis') self.assertEqual('result', result) mock_upload.assert_called_once_with( 'ctx', 'session', 'instance', 'image_id', 'vdis') command.upload_image.assert_called_once_with()