summaryrefslogtreecommitdiff
path: root/tests/unittests/test__init__.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-07-21 12:02:44 -0400
committerScott Moser <smoser@ubuntu.com>2015-07-21 12:02:44 -0400
commit0db6078c5555cdddcd195cefdc04154e4a754dd6 (patch)
tree3278788881649c388d978a39c9088c5884b9f130 /tests/unittests/test__init__.py
parentf73991b9697d15e2d7d931e493125ca291025673 (diff)
downloadvyos-cloud-init-0db6078c5555cdddcd195cefdc04154e4a754dd6.tar.gz
vyos-cloud-init-0db6078c5555cdddcd195cefdc04154e4a754dd6.zip
tests: fix TestHandlerHandlePart tests
these tests were previously passing, but doing so erroneously. I believe that an update to mock caused them to start failing. I've updated the tests now. The simple change is replacing 'assert_called_with_once' with 'assert_called_once_with'. The second set of changes is seemingly a correction of the following tests expectations: test_normal_version_2 : was not expecting to get frequency passed into handle_part, but should have been. test_no_handle_when_modfreq_once: was expecting to have handle_part called even though the test implies otherwise. test_exception_is_caught: this test just looked broken. Now, we're testing that the part handler is called and that no exception is raised past handle_part
Diffstat (limited to 'tests/unittests/test__init__.py')
-rw-r--r--tests/unittests/test__init__.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py
index c32783a6..153f1658 100644
--- a/tests/unittests/test__init__.py
+++ b/tests/unittests/test__init__.py
@@ -70,8 +70,8 @@ class TestWalkerHandleHandler(TestCase):
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 @@ class TestWalkerHandleHandler(TestCase):
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 @@ class TestWalkerHandleHandler(TestCase):
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 @@ class TestHandlerHandlePart(unittest.TestCase):
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 @@ class TestHandlerHandlePart(unittest.TestCase):
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 @@ class TestHandlerHandlePart(unittest.TestCase):
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 @@ class TestHandlerHandlePart(unittest.TestCase):
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)