Merge lp:~mew/charm-helpers/apt-test-fixes into lp:charm-helpers

Proposed by Matthew Wedgwood
Status: Merged
Approved by: Michael Nelson
Approved revision: 71
Merged at revision: 71
Proposed branch: lp:~mew/charm-helpers/apt-test-fixes
Merge into: lp:charm-helpers
Diff against target: 222 lines (+99/-98)
2 files modified
tests/core/test_host.py (+0/-98)
tests/fetch/test_fetch.py (+99/-0)
To merge this branch: bzr merge lp:~mew/charm-helpers/apt-test-fixes
Reviewer Review Type Date Requested Status
Michael Nelson Approve
Review via email: mp+181340@code.launchpad.net

Commit message

Relocate apt-related tests to the fetch test suite and fix log mocks

Description of the change

When the apt-related helpers were moved to the fetch module, the tests were left behind in the core.hosts suite. This change relocates apt-related tests to the fetch test suite and fixes log mocks.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

LGTM - straightforward.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/core/test_host.py'
2--- tests/core/test_host.py 2013-08-21 10:13:22 +0000
3+++ tests/core/test_host.py 2013-08-21 15:47:58 +0000
4@@ -7,7 +7,6 @@
5 from testtools import TestCase
6
7 from charmhelpers.core import host
8-from charmhelpers import fetch
9
10
11 MOUNT_LINES = ("""
12@@ -404,103 +403,6 @@
13 os_.fchmod.assert_called_with(fileno, perms)
14 mock_file.write.assert_called_with('what is {juju}')
15
16- @patch('subprocess.call')
17- @patch.object(host, 'log')
18- def test_installs_apt_packages(self, log, mock_call):
19- packages = ['foo', 'bar']
20- options = ['--foo', '--bar']
21-
22- fetch.apt_install(packages, options)
23-
24- mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
25- 'install', 'foo', 'bar'])
26-
27- @patch('subprocess.call')
28- @patch.object(host, 'log')
29- def test_installs_apt_packages_without_options(self, log, mock_call):
30- packages = ['foo', 'bar']
31-
32- fetch.apt_install(packages)
33-
34- mock_call.assert_called_with(['apt-get', '-y', 'install', 'foo',
35- 'bar'])
36-
37- @patch('subprocess.call')
38- @patch.object(host, 'log')
39- def test_installs_apt_packages_as_string(self, log, mock_call):
40- packages = 'foo bar'
41- options = ['--foo', '--bar']
42-
43- fetch.apt_install(packages, options)
44-
45- mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
46- 'install', 'foo bar'])
47-
48- @patch('subprocess.check_call')
49- @patch.object(host, 'log')
50- def test_installs_apt_packages_with_possible_errors(self, log, check_call):
51- packages = ['foo', 'bar']
52- options = ['--foo', '--bar']
53-
54- fetch.apt_install(packages, options, fatal=True)
55-
56- check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
57- 'install', 'foo', 'bar'])
58-
59-
60- @patch('subprocess.check_call')
61- @patch.object(host, 'log')
62- def test_purges_apt_packages_as_string_fatal(self, log, mock_call):
63- packages = 'irrelevant names'
64- mock_call.side_effect = OSError('fail')
65-
66- mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
67- log.assert_called()
68-
69-
70- @patch('subprocess.check_call')
71- @patch.object(host, 'log')
72- def test_purges_apt_packages_fatal(self, log, mock_call):
73- packages = ['irrelevant', 'names']
74- mock_call.side_effect = OSError('fail')
75-
76- mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
77- log.assert_called()
78-
79-
80- @patch('subprocess.call')
81- @patch.object(host, 'log')
82- def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):
83- packages = 'foo bar'
84-
85- fetch.apt_purge(packages)
86-
87- log.assert_called()
88- mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])
89-
90-
91- @patch('subprocess.call')
92- @patch.object(host, 'log')
93- def test_purges_apt_packages_nofatal(self, log, mock_call):
94- packages = ['foo', 'bar']
95-
96- fetch.apt_purge(packages)
97-
98- log.assert_called()
99- mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',
100- 'bar'])
101-
102-
103- @patch('subprocess.check_call')
104- def test_apt_update_fatal(self, check_call):
105- fetch.apt_update(fatal=True)
106- check_call.assert_called_with(['apt-get', 'update'])
107-
108- @patch('subprocess.call')
109- def test_apt_update_nonfatal(self, call):
110- fetch.apt_update()
111- call.assert_called_with(['apt-get', 'update'])
112-
113 @patch('subprocess.check_output')
114 @patch.object(host, 'log')
115 def test_mounts_a_device(self, log, check_output):
116
117=== modified file 'tests/fetch/test_fetch.py'
118--- tests/fetch/test_fetch.py 2013-08-21 11:45:37 +0000
119+++ tests/fetch/test_fetch.py 2013-08-21 15:47:58 +0000
120@@ -306,3 +306,102 @@
121 expected_url = "http://example.com/foo"
122 u = self.fh.base_url(sample_url)
123 self.assertEqual(u, expected_url)
124+
125+
126+class AptTests(TestCase):
127+ @patch('subprocess.call')
128+ @patch.object(fetch, 'log')
129+ def test_installs_apt_packages(self, log, mock_call):
130+ packages = ['foo', 'bar']
131+ options = ['--foo', '--bar']
132+
133+ fetch.apt_install(packages, options)
134+
135+ mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
136+ 'install', 'foo', 'bar'])
137+
138+ @patch('subprocess.call')
139+ @patch.object(fetch, 'log')
140+ def test_installs_apt_packages_without_options(self, log, mock_call):
141+ packages = ['foo', 'bar']
142+
143+ fetch.apt_install(packages)
144+
145+ mock_call.assert_called_with(['apt-get', '-y', 'install', 'foo',
146+ 'bar'])
147+
148+ @patch('subprocess.call')
149+ @patch.object(fetch, 'log')
150+ def test_installs_apt_packages_as_string(self, log, mock_call):
151+ packages = 'foo bar'
152+ options = ['--foo', '--bar']
153+
154+ fetch.apt_install(packages, options)
155+
156+ mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
157+ 'install', 'foo bar'])
158+
159+ @patch('subprocess.check_call')
160+ @patch.object(fetch, 'log')
161+ def test_installs_apt_packages_with_possible_errors(self, log, check_call):
162+ packages = ['foo', 'bar']
163+ options = ['--foo', '--bar']
164+
165+ fetch.apt_install(packages, options, fatal=True)
166+
167+ check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
168+ 'install', 'foo', 'bar'])
169+
170+
171+ @patch('subprocess.check_call')
172+ @patch.object(fetch, 'log')
173+ def test_purges_apt_packages_as_string_fatal(self, log, mock_call):
174+ packages = 'irrelevant names'
175+ mock_call.side_effect = OSError('fail')
176+
177+ mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
178+ log.assert_called()
179+
180+
181+ @patch('subprocess.check_call')
182+ @patch.object(fetch, 'log')
183+ def test_purges_apt_packages_fatal(self, log, mock_call):
184+ packages = ['irrelevant', 'names']
185+ mock_call.side_effect = OSError('fail')
186+
187+ mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
188+ log.assert_called()
189+
190+
191+ @patch('subprocess.call')
192+ @patch.object(fetch, 'log')
193+ def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):
194+ packages = 'foo bar'
195+
196+ fetch.apt_purge(packages)
197+
198+ log.assert_called()
199+ mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])
200+
201+
202+ @patch('subprocess.call')
203+ @patch.object(fetch, 'log')
204+ def test_purges_apt_packages_nofatal(self, log, mock_call):
205+ packages = ['foo', 'bar']
206+
207+ fetch.apt_purge(packages)
208+
209+ log.assert_called()
210+ mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',
211+ 'bar'])
212+
213+
214+ @patch('subprocess.check_call')
215+ def test_apt_update_fatal(self, check_call):
216+ fetch.apt_update(fatal=True)
217+ check_call.assert_called_with(['apt-get', 'update'])
218+
219+ @patch('subprocess.call')
220+ def test_apt_update_nonfatal(self, call):
221+ fetch.apt_update()
222+ call.assert_called_with(['apt-get', 'update'])

Subscribers

People subscribed via source and target branches