Merge "Remove redundant mock rpc statement"

This commit is contained in:
Jenkins 2017-08-03 21:56:27 +00:00 committed by Gerrit Code Review
commit 80b9150ccf

View File

@ -27,7 +27,6 @@ from cinder import objects
from cinder import test
from cinder.tests.unit.api import fakes
from cinder.tests.unit import fake_constants as fake
from cinder.tests.unit import fake_notifier
def stub_qos_specs(id):
@ -274,10 +273,8 @@ class QoSSpecManageApiTest(test.TestCase):
def test_qos_specs_delete(self, mock_qos_delete, mock_qos_get_specs):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' % (
fake.PROJECT_ID, fake.QOS_SPEC_ID), use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.controller.delete(req, fake.QOS_SPEC_ID)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.get_qos_specs',
side_effect=return_qos_specs_get_qos_specs)
@ -285,8 +282,6 @@ class QoSSpecManageApiTest(test.TestCase):
side_effect=return_qos_specs_delete)
def test_qos_specs_delete_not_found(self, mock_qos_delete,
mock_qos_get_specs):
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
(fake.PROJECT_ID,
fake.WILL_NOT_BE_FOUND_ID),
@ -294,7 +289,7 @@ class QoSSpecManageApiTest(test.TestCase):
self.assertRaises(exception.QoSSpecsNotFound,
self.controller.delete, req,
fake.WILL_NOT_BE_FOUND_ID)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.get_qos_specs',
side_effect=return_qos_specs_get_qos_specs)
@ -305,11 +300,9 @@ class QoSSpecManageApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' % (
fake.PROJECT_ID, fake.IN_USE_ID), use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
req, fake.IN_USE_ID)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.get_qos_specs',
side_effect=return_qos_specs_get_qos_specs)
@ -321,12 +314,10 @@ class QoSSpecManageApiTest(test.TestCase):
(fake.PROJECT_ID, fake.IN_USE_ID),
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(webob.exc.HTTPInternalServerError,
self.controller.delete,
req, fake.IN_USE_ID)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
def test_qos_specs_delete_with_invalid_force(self):
invalid_force = "invalid_bool"
@ -347,10 +338,8 @@ class QoSSpecManageApiTest(test.TestCase):
(fake.PROJECT_ID, fake.IN_USE_ID),
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.controller.delete_keys(req, fake.IN_USE_ID, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.delete_keys',
side_effect=return_qos_specs_delete_keys)
@ -361,12 +350,10 @@ class QoSSpecManageApiTest(test.TestCase):
fake.WILL_NOT_BE_FOUND_ID),
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(exception.QoSSpecsNotFound,
self.controller.delete_keys,
req, fake.WILL_NOT_BE_FOUND_ID, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.delete_keys',
side_effect=return_qos_specs_delete_keys)
@ -376,12 +363,10 @@ class QoSSpecManageApiTest(test.TestCase):
use_admin_context=True)
body = {"keys": ['foo', 'zoo']}
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(exception.QoSSpecsKeyNotFound,
self.controller.delete_keys,
req, fake.IN_USE_ID, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.delete_keys',
side_effect=return_qos_specs_delete_keys)
@ -391,11 +376,8 @@ class QoSSpecManageApiTest(test.TestCase):
(fake.PROJECT_ID, fake.IN_USE_ID),
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier,
autospec=True) as mock_get_notifier:
self.controller.delete_keys(req, fake.IN_USE_ID, body)
mock_get_notifier.assert_called_once_with('QoSSpecs')
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.create',
side_effect=return_qos_specs_create)
@ -408,11 +390,9 @@ class QoSSpecManageApiTest(test.TestCase):
fake.PROJECT_ID,
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
res_dict = self.controller.create(req, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
self.assertEqual('qos_specs_%s' % fake.QOS_SPEC_ID,
res_dict['qos_specs']['name'])
self.assertTrue(mock_validate.called)
@ -425,11 +405,9 @@ class QoSSpecManageApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.create',
side_effect=return_qos_specs_create)
@ -439,11 +417,9 @@ class QoSSpecManageApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(webob.exc.HTTPConflict,
self.controller.create, req, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.create',
side_effect=return_qos_specs_create)
@ -453,11 +429,9 @@ class QoSSpecManageApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
use_admin_context=True)
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
self.assertRaises(webob.exc.HTTPInternalServerError,
self.controller.create, req, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@ddt.data({'foo': {'a': 'b'}},
{'qos_specs': {'a': 'b'}},
@ -496,8 +470,6 @@ class QoSSpecManageApiTest(test.TestCase):
@mock.patch('cinder.volume.qos_specs.update',
side_effect=return_qos_specs_update)
def test_update(self, mock_qos_update):
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
(fake.PROJECT_ID, fake.QOS_SPEC_ID),
use_admin_context=True)
@ -505,13 +477,11 @@ class QoSSpecManageApiTest(test.TestCase):
'key2': 'value2'}}
res = self.controller.update(req, fake.QOS_SPEC_ID, body)
self.assertDictEqual(body, res)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.update',
side_effect=return_qos_specs_update)
def test_update_not_found(self, mock_qos_update):
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
(fake.PROJECT_ID,
fake.WILL_NOT_BE_FOUND_ID),
@ -521,13 +491,11 @@ class QoSSpecManageApiTest(test.TestCase):
self.assertRaises(exception.QoSSpecsNotFound,
self.controller.update,
req, fake.WILL_NOT_BE_FOUND_ID, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.update',
side_effect=return_qos_specs_update)
def test_update_invalid_input(self, mock_qos_update):
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
(fake.PROJECT_ID, fake.INVALID_ID),
use_admin_context=True)
@ -536,13 +504,11 @@ class QoSSpecManageApiTest(test.TestCase):
self.assertRaises(exception.InvalidQoSSpecs,
self.controller.update,
req, fake.INVALID_ID, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.update',
side_effect=return_qos_specs_update)
def test_update_failed(self, mock_qos_update):
notifier = fake_notifier.get_fake_notifier()
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
(fake.PROJECT_ID,
fake.UPDATE_FAILED_ID),
@ -552,7 +518,7 @@ class QoSSpecManageApiTest(test.TestCase):
self.assertRaises(webob.exc.HTTPInternalServerError,
self.controller.update,
req, fake.UPDATE_FAILED_ID, body)
self.assertEqual(1, notifier.get_notification_count())
self.assertEqual(1, self.notifier.get_notification_count())
@mock.patch('cinder.volume.qos_specs.get_qos_specs',
side_effect=return_qos_specs_get_qos_specs)