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
=== modified file 'tests/core/test_host.py'
--- tests/core/test_host.py 2013-08-21 10:13:22 +0000
+++ tests/core/test_host.py 2013-08-21 15:47:58 +0000
@@ -7,7 +7,6 @@
7from testtools import TestCase7from testtools import TestCase
88
9from charmhelpers.core import host9from charmhelpers.core import host
10from charmhelpers import fetch
1110
1211
13MOUNT_LINES = ("""12MOUNT_LINES = ("""
@@ -404,103 +403,6 @@
404 os_.fchmod.assert_called_with(fileno, perms)403 os_.fchmod.assert_called_with(fileno, perms)
405 mock_file.write.assert_called_with('what is {juju}')404 mock_file.write.assert_called_with('what is {juju}')
406405
407 @patch('subprocess.call')
408 @patch.object(host, 'log')
409 def test_installs_apt_packages(self, log, mock_call):
410 packages = ['foo', 'bar']
411 options = ['--foo', '--bar']
412
413 fetch.apt_install(packages, options)
414
415 mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
416 'install', 'foo', 'bar'])
417
418 @patch('subprocess.call')
419 @patch.object(host, 'log')
420 def test_installs_apt_packages_without_options(self, log, mock_call):
421 packages = ['foo', 'bar']
422
423 fetch.apt_install(packages)
424
425 mock_call.assert_called_with(['apt-get', '-y', 'install', 'foo',
426 'bar'])
427
428 @patch('subprocess.call')
429 @patch.object(host, 'log')
430 def test_installs_apt_packages_as_string(self, log, mock_call):
431 packages = 'foo bar'
432 options = ['--foo', '--bar']
433
434 fetch.apt_install(packages, options)
435
436 mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
437 'install', 'foo bar'])
438
439 @patch('subprocess.check_call')
440 @patch.object(host, 'log')
441 def test_installs_apt_packages_with_possible_errors(self, log, check_call):
442 packages = ['foo', 'bar']
443 options = ['--foo', '--bar']
444
445 fetch.apt_install(packages, options, fatal=True)
446
447 check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
448 'install', 'foo', 'bar'])
449
450
451 @patch('subprocess.check_call')
452 @patch.object(host, 'log')
453 def test_purges_apt_packages_as_string_fatal(self, log, mock_call):
454 packages = 'irrelevant names'
455 mock_call.side_effect = OSError('fail')
456
457 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
458 log.assert_called()
459
460
461 @patch('subprocess.check_call')
462 @patch.object(host, 'log')
463 def test_purges_apt_packages_fatal(self, log, mock_call):
464 packages = ['irrelevant', 'names']
465 mock_call.side_effect = OSError('fail')
466
467 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
468 log.assert_called()
469
470
471 @patch('subprocess.call')
472 @patch.object(host, 'log')
473 def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):
474 packages = 'foo bar'
475
476 fetch.apt_purge(packages)
477
478 log.assert_called()
479 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])
480
481
482 @patch('subprocess.call')
483 @patch.object(host, 'log')
484 def test_purges_apt_packages_nofatal(self, log, mock_call):
485 packages = ['foo', 'bar']
486
487 fetch.apt_purge(packages)
488
489 log.assert_called()
490 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',
491 'bar'])
492
493
494 @patch('subprocess.check_call')
495 def test_apt_update_fatal(self, check_call):
496 fetch.apt_update(fatal=True)
497 check_call.assert_called_with(['apt-get', 'update'])
498
499 @patch('subprocess.call')
500 def test_apt_update_nonfatal(self, call):
501 fetch.apt_update()
502 call.assert_called_with(['apt-get', 'update'])
503
504 @patch('subprocess.check_output')406 @patch('subprocess.check_output')
505 @patch.object(host, 'log')407 @patch.object(host, 'log')
506 def test_mounts_a_device(self, log, check_output):408 def test_mounts_a_device(self, log, check_output):
507409
=== modified file 'tests/fetch/test_fetch.py'
--- tests/fetch/test_fetch.py 2013-08-21 11:45:37 +0000
+++ tests/fetch/test_fetch.py 2013-08-21 15:47:58 +0000
@@ -306,3 +306,102 @@
306 expected_url = "http://example.com/foo"306 expected_url = "http://example.com/foo"
307 u = self.fh.base_url(sample_url)307 u = self.fh.base_url(sample_url)
308 self.assertEqual(u, expected_url)308 self.assertEqual(u, expected_url)
309
310
311class AptTests(TestCase):
312 @patch('subprocess.call')
313 @patch.object(fetch, 'log')
314 def test_installs_apt_packages(self, log, mock_call):
315 packages = ['foo', 'bar']
316 options = ['--foo', '--bar']
317
318 fetch.apt_install(packages, options)
319
320 mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
321 'install', 'foo', 'bar'])
322
323 @patch('subprocess.call')
324 @patch.object(fetch, 'log')
325 def test_installs_apt_packages_without_options(self, log, mock_call):
326 packages = ['foo', 'bar']
327
328 fetch.apt_install(packages)
329
330 mock_call.assert_called_with(['apt-get', '-y', 'install', 'foo',
331 'bar'])
332
333 @patch('subprocess.call')
334 @patch.object(fetch, 'log')
335 def test_installs_apt_packages_as_string(self, log, mock_call):
336 packages = 'foo bar'
337 options = ['--foo', '--bar']
338
339 fetch.apt_install(packages, options)
340
341 mock_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
342 'install', 'foo bar'])
343
344 @patch('subprocess.check_call')
345 @patch.object(fetch, 'log')
346 def test_installs_apt_packages_with_possible_errors(self, log, check_call):
347 packages = ['foo', 'bar']
348 options = ['--foo', '--bar']
349
350 fetch.apt_install(packages, options, fatal=True)
351
352 check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
353 'install', 'foo', 'bar'])
354
355
356 @patch('subprocess.check_call')
357 @patch.object(fetch, 'log')
358 def test_purges_apt_packages_as_string_fatal(self, log, mock_call):
359 packages = 'irrelevant names'
360 mock_call.side_effect = OSError('fail')
361
362 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
363 log.assert_called()
364
365
366 @patch('subprocess.check_call')
367 @patch.object(fetch, 'log')
368 def test_purges_apt_packages_fatal(self, log, mock_call):
369 packages = ['irrelevant', 'names']
370 mock_call.side_effect = OSError('fail')
371
372 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
373 log.assert_called()
374
375
376 @patch('subprocess.call')
377 @patch.object(fetch, 'log')
378 def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):
379 packages = 'foo bar'
380
381 fetch.apt_purge(packages)
382
383 log.assert_called()
384 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])
385
386
387 @patch('subprocess.call')
388 @patch.object(fetch, 'log')
389 def test_purges_apt_packages_nofatal(self, log, mock_call):
390 packages = ['foo', 'bar']
391
392 fetch.apt_purge(packages)
393
394 log.assert_called()
395 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',
396 'bar'])
397
398
399 @patch('subprocess.check_call')
400 def test_apt_update_fatal(self, check_call):
401 fetch.apt_update(fatal=True)
402 check_call.assert_called_with(['apt-get', 'update'])
403
404 @patch('subprocess.call')
405 def test_apt_update_nonfatal(self, call):
406 fetch.apt_update()
407 call.assert_called_with(['apt-get', 'update'])

Subscribers

People subscribed via source and target branches