cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #00713
[Merge] lp:~smoser/cloud-init/fix-mock-tests into lp:cloud-init
Scott Moser has proposed merging lp:~smoser/cloud-init/fix-mock-tests into lp:cloud-init.
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~smoser/cloud-init/fix-mock-tests/+merge/265410
--
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/fix-mock-tests into lp:cloud-init.
=== modified file 'tests/unittests/test__init__.py'
--- tests/unittests/test__init__.py 2015-03-02 20:56:15 +0000
+++ tests/unittests/test__init__.py 2015-07-21 16:13:59 +0000
@@ -70,8 +70,8 @@
return_value=self.module_fake) as mockobj:
handlers.walker_handle_handler(self.data, self.ctype,
self.filename, self.payload)
- mockobj.assert_called_with_once(self.expected_module_name)
- self.write_file_mock.assert_called_with_once(
+ mockobj.assert_called_once_with(self.expected_module_name)
+ self.write_file_mock.assert_called_once_with(
self.expected_file_fullname, self.payload, 0o600)
self.assertEqual(self.data['handlercount'], 1)
@@ -81,8 +81,8 @@
side_effect=ImportError) as mockobj:
handlers.walker_handle_handler(self.data, self.ctype,
self.filename, self.payload)
- mockobj.assert_called_with_once(self.expected_module_name)
- self.write_file_mock.assert_called_with_once(
+ mockobj.assert_called_once_with(self.expected_module_name)
+ self.write_file_mock.assert_called_once_with(
self.expected_file_fullname, self.payload, 0o600)
self.assertEqual(self.data['handlercount'], 0)
@@ -93,8 +93,8 @@
return_value=self.module_fake) as mockobj:
handlers.walker_handle_handler(self.data, self.ctype,
self.filename, self.payload)
- mockobj.assert_called_with_once(self.expected_module_name)
- self.write_file_mock.assert_called_with_once(
+ mockobj.assert_called_once_with(self.expected_module_name)
+ self.write_file_mock.assert_called_once_with(
self.expected_file_fullname, self.payload, 0o600)
self.assertEqual(self.data['handlercount'], 0)
@@ -122,7 +122,7 @@
self.frequency, self.headers)
# Assert that the handle_part() method of the mock object got
# called with the expected arguments.
- mod_mock.handle_part.assert_called_with_once(
+ mod_mock.handle_part.assert_called_once_with(
self.data, self.ctype, self.filename, self.payload)
def test_normal_version_2(self):
@@ -136,8 +136,9 @@
self.frequency, self.headers)
# Assert that the handle_part() method of the mock object got
# called with the expected arguments.
- mod_mock.handle_part.assert_called_with_once(
- self.data, self.ctype, self.filename, self.payload)
+ mod_mock.handle_part.assert_called_once_with(
+ self.data, self.ctype, self.filename, self.payload,
+ settings.PER_INSTANCE)
def test_modfreq_per_always(self):
"""
@@ -150,7 +151,7 @@
self.frequency, self.headers)
# Assert that the handle_part() method of the mock object got
# called with the expected arguments.
- mod_mock.handle_part.assert_called_with_once(
+ mod_mock.handle_part.assert_called_once_with(
self.data, self.ctype, self.filename, self.payload)
def test_no_handle_when_modfreq_once(self):
@@ -159,21 +160,20 @@
mod_mock = mock.Mock(frequency=settings.PER_ONCE)
handlers.run_part(mod_mock, self.data, self.filename, self.payload,
self.frequency, self.headers)
- # Assert that the handle_part() method of the mock object got
- # called with the expected arguments.
- mod_mock.handle_part.assert_called_with_once(
- self.data, self.ctype, self.filename, self.payload)
+ self.assertEqual(0, mod_mock.handle_part.call_count)
def test_exception_is_caught(self):
"""Exceptions within C{handle_part} are caught and logged."""
mod_mock = mock.Mock(frequency=settings.PER_INSTANCE,
handler_version=1)
- handlers.run_part(mod_mock, self.data, self.filename, self.payload,
- self.frequency, self.headers)
mod_mock.handle_part.side_effect = Exception
- handlers.run_part(mod_mock, self.data, self.filename, self.payload,
- self.frequency, self.headers)
- mod_mock.handle_part.assert_called_with_once(
+ try:
+ handlers.run_part(mod_mock, self.data, self.filename,
+ self.payload, self.frequency, self.headers)
+ except Exception:
+ self.fail("Exception was not caught in handle_part")
+
+ mod_mock.handle_part.assert_called_once_with(
self.data, self.ctype, self.filename, self.payload)
Follow ups