Merge "Add missing 'autospec' to unit tests - /unit/objects/"
This commit is contained in:
commit
8e82e8ef46
|
@ -15,6 +15,7 @@
|
|||
# under the License.
|
||||
|
||||
import datetime
|
||||
import types
|
||||
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
|
@ -87,7 +88,8 @@ class TestConductorObject(db_base.DbTestCase):
|
|||
self.assertEqual(expected, mock_get_cdr.call_args_list)
|
||||
self.assertEqual(self.context, c._context)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def _test_register(self, mock_target_version, update_existing=False):
|
||||
mock_target_version.return_value = '1.5'
|
||||
host = self.fake_conductor['hostname']
|
||||
|
@ -111,7 +113,8 @@ class TestConductorObject(db_base.DbTestCase):
|
|||
def test_register_update_existing_true(self):
|
||||
self._test_register(update_existing=True)
|
||||
|
||||
@mock.patch.object(objects.Conductor, 'unregister_all_hardware_interfaces')
|
||||
@mock.patch.object(objects.Conductor, 'unregister_all_hardware_interfaces',
|
||||
autospec=True)
|
||||
def test_unregister(self, mock_unreg_ifaces):
|
||||
host = self.fake_conductor['hostname']
|
||||
with mock.patch.object(self.dbapi, 'get_conductor',
|
||||
|
@ -122,7 +125,7 @@ class TestConductorObject(db_base.DbTestCase):
|
|||
c = objects.Conductor.get_by_hostname(self.context, host)
|
||||
c.unregister()
|
||||
mock_unregister_cdr.assert_called_once_with(host)
|
||||
mock_unreg_ifaces.assert_called_once_with()
|
||||
mock_unreg_ifaces.assert_called_once_with(mock.ANY)
|
||||
|
||||
def test_register_hardware_interfaces(self):
|
||||
host = self.fake_conductor['hostname']
|
||||
|
|
|
@ -94,7 +94,7 @@ class TestNotificationBase(test_base.TestCase):
|
|||
actual_payload = mock_notify.call_args[1]['payload']
|
||||
self.assertJsonEqual(expected_payload, actual_payload)
|
||||
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER')
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER', autospec=True)
|
||||
def test_emit_notification(self, mock_notifier):
|
||||
self.config(notification_level='debug')
|
||||
payload = self.TestNotificationPayload(an_extra_field='extra',
|
||||
|
@ -130,7 +130,7 @@ class TestNotificationBase(test_base.TestCase):
|
|||
expected_publisher='ironic-conductor.host',
|
||||
notif_level=fields.NotificationLevel.DEBUG)
|
||||
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER')
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER', autospec=True)
|
||||
def test_no_emit_level_too_low(self, mock_notifier):
|
||||
# Make sure notification doesn't emit when set notification
|
||||
# level < config level
|
||||
|
@ -153,7 +153,7 @@ class TestNotificationBase(test_base.TestCase):
|
|||
|
||||
self.assertFalse(mock_notifier.called)
|
||||
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER')
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER', autospec=True)
|
||||
def test_no_emit_notifs_disabled(self, mock_notifier):
|
||||
# Make sure notifications aren't emitted when notification_level
|
||||
# isn't defined, indicating notifications should be disabled
|
||||
|
@ -175,7 +175,7 @@ class TestNotificationBase(test_base.TestCase):
|
|||
|
||||
self.assertFalse(mock_notifier.called)
|
||||
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER')
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER', autospec=True)
|
||||
def test_no_emit_schema_not_populated(self, mock_notifier):
|
||||
self.config(notification_level='debug')
|
||||
payload = self.TestNotificationPayload(an_extra_field='extra',
|
||||
|
@ -195,7 +195,7 @@ class TestNotificationBase(test_base.TestCase):
|
|||
mock_context)
|
||||
self.assertFalse(mock_notifier.called)
|
||||
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER')
|
||||
@mock.patch('ironic.common.rpc.VERSIONED_NOTIFIER', autospec=True)
|
||||
def test_emit_notification_empty_schema(self, mock_notifier):
|
||||
self.config(notification_level='debug')
|
||||
payload = self.TestNotificationPayloadEmptySchema(fake_field='123')
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import contextlib
|
||||
import datetime
|
||||
import types
|
||||
|
||||
import iso8601
|
||||
import mock
|
||||
|
@ -436,7 +437,8 @@ class _TestObject(object):
|
|||
self.assertFalse(mock_convert.called)
|
||||
|
||||
@mock.patch.object(MyObj, 'convert_to_version', autospec=True)
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_do_version_changes_for_db_pinned(self, mock_target_version,
|
||||
mock_convert):
|
||||
# obj is same version as pinned, no conversion done
|
||||
|
@ -456,7 +458,8 @@ class _TestObject(object):
|
|||
mock_target_version.assert_called_with()
|
||||
self.assertFalse(mock_convert.called)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_do_version_changes_for_db_downgrade(self, mock_target_version):
|
||||
# obj is 1.5; convert to 1.4
|
||||
mock_target_version.return_value = '1.4'
|
||||
|
@ -542,7 +545,7 @@ class _TestObject(object):
|
|||
# Mock obj_load_attr as this is what is called if an attribute that we
|
||||
# try to access is not yet set. For all ironic objects it's a noop,
|
||||
# we've implemented it in MyObj purely for testing
|
||||
with mock.patch.object(obj, 'obj_load_attr'):
|
||||
with mock.patch.object(obj, 'obj_load_attr', autospec=True):
|
||||
MyObj._from_db_object(self.context, obj, dbobj,
|
||||
fields=['foo', 'bar'])
|
||||
self.assertEqual(obj.__class__.VERSION, obj.VERSION)
|
||||
|
@ -611,7 +614,8 @@ class _TestObject(object):
|
|||
self.assertRaises(object_exception.IncompatibleObjectVersion,
|
||||
obj.get_target_version)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_supports_version(self, mock_target_version):
|
||||
mock_target_version.return_value = "1.5"
|
||||
obj = MyObj(self.context)
|
||||
|
@ -756,7 +760,8 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
for item in thing2:
|
||||
self.assertIsInstance(item, MyObj)
|
||||
|
||||
@mock.patch('ironic.objects.base.IronicObject.indirection_api')
|
||||
@mock.patch('ironic.objects.base.IronicObject.indirection_api',
|
||||
autospec=True)
|
||||
def _test_deserialize_entity_newer(self, obj_version, backported_to,
|
||||
mock_indirection_api,
|
||||
my_version='1.6'):
|
||||
|
@ -827,7 +832,7 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
self.assertFalse(mock_release_mapping.called)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'convert_to_version', autospec=True)
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version', autospec=True)
|
||||
def test_serialize_entity_unpinned_api(self, mock_version, mock_convert):
|
||||
"""Test single element serializer with no backport, unpinned."""
|
||||
mock_version.return_value = MyObj.VERSION
|
||||
|
@ -848,7 +853,8 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
self.assertFalse(mock_convert.called)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'convert_to_version', autospec=True)
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_serialize_entity_unpinned_conductor(self, mock_version,
|
||||
mock_convert):
|
||||
"""Test single element serializer with no backport, unpinned."""
|
||||
|
@ -869,7 +875,7 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
mock_version.assert_called_once_with()
|
||||
self.assertFalse(mock_convert.called)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version', autospec=True)
|
||||
def test_serialize_entity_pinned_api(self, mock_version):
|
||||
"""Test single element serializer with backport to pinned version."""
|
||||
mock_version.return_value = '1.4'
|
||||
|
@ -888,7 +894,8 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
self.assertEqual('miss', data['missing'])
|
||||
self.assertFalse(mock_version.called)
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_serialize_entity_pinned_conductor(self, mock_version):
|
||||
"""Test single element serializer with backport to pinned version."""
|
||||
mock_version.return_value = '1.4'
|
||||
|
@ -908,7 +915,8 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
self.assertNotIn('ironic_object.changes', primitive)
|
||||
mock_version.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version')
|
||||
@mock.patch.object(base.IronicObject, 'get_target_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_serialize_entity_invalid_pin(self, mock_version):
|
||||
mock_version.side_effect = object_exception.InvalidTargetVersion(
|
||||
version='1.6')
|
||||
|
@ -963,7 +971,7 @@ class TestObjectSerializer(test_base.TestCase):
|
|||
|
||||
|
||||
class TestRegistry(test_base.TestCase):
|
||||
@mock.patch('ironic.objects.base.objects')
|
||||
@mock.patch('ironic.objects.base.objects', autospec=True)
|
||||
def test_hook_chooses_newer_properly(self, mock_objects):
|
||||
reg = base.IronicObjectRegistry()
|
||||
reg.registration_hook(MyObj, 0)
|
||||
|
@ -979,7 +987,7 @@ class TestRegistry(test_base.TestCase):
|
|||
reg.registration_hook(MyNewerObj, 0)
|
||||
self.assertEqual(MyNewerObj, mock_objects.MyObj)
|
||||
|
||||
@mock.patch('ironic.objects.base.objects')
|
||||
@mock.patch('ironic.objects.base.objects', autospec=True)
|
||||
def test_hook_keeps_newer_properly(self, mock_objects):
|
||||
reg = base.IronicObjectRegistry()
|
||||
reg.registration_hook(MyObj, 0)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import datetime
|
||||
import types
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
|
@ -146,13 +147,15 @@ class TestPortObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
|
|||
self.assertIsInstance(ports[0], objects.Port)
|
||||
self.assertEqual(self.context, ports[0]._context)
|
||||
|
||||
@mock.patch.object(obj_base.IronicObject, 'supports_version')
|
||||
@mock.patch.object(obj_base.IronicObject, 'supports_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_supports_physical_network_supported(self, mock_sv):
|
||||
mock_sv.return_value = True
|
||||
self.assertTrue(objects.Port.supports_physical_network())
|
||||
mock_sv.assert_called_once_with((1, 7))
|
||||
|
||||
@mock.patch.object(obj_base.IronicObject, 'supports_version')
|
||||
@mock.patch.object(obj_base.IronicObject, 'supports_version',
|
||||
spec_set=types.FunctionType)
|
||||
def test_supports_physical_network_unsupported(self, mock_sv):
|
||||
mock_sv.return_value = False
|
||||
self.assertFalse(objects.Port.supports_physical_network())
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
import datetime
|
||||
import types
|
||||
|
||||
import mock
|
||||
from testtools.matchers import HasLength
|
||||
|
@ -31,8 +32,10 @@ class TestVolumeConnectorObject(db_base.DbTestCase,
|
|||
super(TestVolumeConnectorObject, self).setUp()
|
||||
self.volume_connector_dict = db_utils.get_test_volume_connector()
|
||||
|
||||
@mock.patch('ironic.objects.VolumeConnector.get_by_uuid')
|
||||
@mock.patch('ironic.objects.VolumeConnector.get_by_id')
|
||||
@mock.patch('ironic.objects.VolumeConnector.get_by_uuid',
|
||||
spec_set=types.FunctionType)
|
||||
@mock.patch('ironic.objects.VolumeConnector.get_by_id',
|
||||
spec_set=types.FunctionType)
|
||||
def test_get(self, mock_get_by_id, mock_get_by_uuid):
|
||||
id = self.volume_connector_dict['id']
|
||||
uuid = self.volume_connector_dict['uuid']
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
import datetime
|
||||
import types
|
||||
|
||||
import mock
|
||||
from testtools.matchers import HasLength
|
||||
|
@ -30,8 +31,10 @@ class TestVolumeTargetObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
|
|||
super(TestVolumeTargetObject, self).setUp()
|
||||
self.volume_target_dict = db_utils.get_test_volume_target()
|
||||
|
||||
@mock.patch('ironic.objects.VolumeTarget.get_by_uuid')
|
||||
@mock.patch('ironic.objects.VolumeTarget.get_by_id')
|
||||
@mock.patch('ironic.objects.VolumeTarget.get_by_uuid',
|
||||
spec_set=types.FunctionType)
|
||||
@mock.patch('ironic.objects.VolumeTarget.get_by_id',
|
||||
spec_set=types.FunctionType)
|
||||
def test_get(self, mock_get_by_id, mock_get_by_uuid):
|
||||
id = self.volume_target_dict['id']
|
||||
uuid = self.volume_target_dict['uuid']
|
||||
|
|
Loading…
Reference in New Issue