Merge lp:~smoser/cloud-init/fix-mock-tests into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Scott Moser on 2015-07-21
Status: Merged
Merged at revision: 1122
Proposed branch: lp:~smoser/cloud-init/fix-mock-tests
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 94 lines (+19/-19)
1 file modified
tests/unittests/test__init__.py (+19/-19)
To merge this branch: bzr merge lp:~smoser/cloud-init/fix-mock-tests
Reviewer Review Type Date Requested Status
cloud-init commiters 2015-07-21 Pending
Review via email: mp+265410@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/unittests/test__init__.py'
2--- tests/unittests/test__init__.py 2015-03-02 20:56:15 +0000
3+++ tests/unittests/test__init__.py 2015-07-21 16:13:59 +0000
4@@ -70,8 +70,8 @@
5 return_value=self.module_fake) as mockobj:
6 handlers.walker_handle_handler(self.data, self.ctype,
7 self.filename, self.payload)
8- mockobj.assert_called_with_once(self.expected_module_name)
9- self.write_file_mock.assert_called_with_once(
10+ mockobj.assert_called_once_with(self.expected_module_name)
11+ self.write_file_mock.assert_called_once_with(
12 self.expected_file_fullname, self.payload, 0o600)
13 self.assertEqual(self.data['handlercount'], 1)
14
15@@ -81,8 +81,8 @@
16 side_effect=ImportError) as mockobj:
17 handlers.walker_handle_handler(self.data, self.ctype,
18 self.filename, self.payload)
19- mockobj.assert_called_with_once(self.expected_module_name)
20- self.write_file_mock.assert_called_with_once(
21+ mockobj.assert_called_once_with(self.expected_module_name)
22+ self.write_file_mock.assert_called_once_with(
23 self.expected_file_fullname, self.payload, 0o600)
24 self.assertEqual(self.data['handlercount'], 0)
25
26@@ -93,8 +93,8 @@
27 return_value=self.module_fake) as mockobj:
28 handlers.walker_handle_handler(self.data, self.ctype,
29 self.filename, self.payload)
30- mockobj.assert_called_with_once(self.expected_module_name)
31- self.write_file_mock.assert_called_with_once(
32+ mockobj.assert_called_once_with(self.expected_module_name)
33+ self.write_file_mock.assert_called_once_with(
34 self.expected_file_fullname, self.payload, 0o600)
35 self.assertEqual(self.data['handlercount'], 0)
36
37@@ -122,7 +122,7 @@
38 self.frequency, self.headers)
39 # Assert that the handle_part() method of the mock object got
40 # called with the expected arguments.
41- mod_mock.handle_part.assert_called_with_once(
42+ mod_mock.handle_part.assert_called_once_with(
43 self.data, self.ctype, self.filename, self.payload)
44
45 def test_normal_version_2(self):
46@@ -136,8 +136,9 @@
47 self.frequency, self.headers)
48 # Assert that the handle_part() method of the mock object got
49 # called with the expected arguments.
50- mod_mock.handle_part.assert_called_with_once(
51- self.data, self.ctype, self.filename, self.payload)
52+ mod_mock.handle_part.assert_called_once_with(
53+ self.data, self.ctype, self.filename, self.payload,
54+ settings.PER_INSTANCE)
55
56 def test_modfreq_per_always(self):
57 """
58@@ -150,7 +151,7 @@
59 self.frequency, self.headers)
60 # Assert that the handle_part() method of the mock object got
61 # called with the expected arguments.
62- mod_mock.handle_part.assert_called_with_once(
63+ mod_mock.handle_part.assert_called_once_with(
64 self.data, self.ctype, self.filename, self.payload)
65
66 def test_no_handle_when_modfreq_once(self):
67@@ -159,21 +160,20 @@
68 mod_mock = mock.Mock(frequency=settings.PER_ONCE)
69 handlers.run_part(mod_mock, self.data, self.filename, self.payload,
70 self.frequency, self.headers)
71- # Assert that the handle_part() method of the mock object got
72- # called with the expected arguments.
73- mod_mock.handle_part.assert_called_with_once(
74- self.data, self.ctype, self.filename, self.payload)
75+ self.assertEqual(0, mod_mock.handle_part.call_count)
76
77 def test_exception_is_caught(self):
78 """Exceptions within C{handle_part} are caught and logged."""
79 mod_mock = mock.Mock(frequency=settings.PER_INSTANCE,
80 handler_version=1)
81- handlers.run_part(mod_mock, self.data, self.filename, self.payload,
82- self.frequency, self.headers)
83 mod_mock.handle_part.side_effect = Exception
84- handlers.run_part(mod_mock, self.data, self.filename, self.payload,
85- self.frequency, self.headers)
86- mod_mock.handle_part.assert_called_with_once(
87+ try:
88+ handlers.run_part(mod_mock, self.data, self.filename,
89+ self.payload, self.frequency, self.headers)
90+ except Exception:
91+ self.fail("Exception was not caught in handle_part")
92+
93+ mod_mock.handle_part.assert_called_once_with(
94 self.data, self.ctype, self.filename, self.payload)
95
96