~charmers/charms/trusty/apache2/trunk

« back to all changes in this revision

Viewing changes to tests/test_balancer_hook.py

  • Committer: Diogo Baeder de Paula Pinto
  • Date: 2013-01-30 17:02:40 UTC
  • mto: (27.2.12 apache2)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: diogobaeder@canonical.com-20130130170240-k6yqzap234lsvb0x
Covering disable_module

Show diffs side-by-side

added added

removed removed

Lines of Context:
318
318
    @patch('hooks.service_apache2')
319
319
    @patch('os.path.exists')
320
320
    @patch('hooks.apt_get_install')
321
 
    def test_does_nothing_if_module_not_provided(self, apt_get_install,
322
 
                                                 path_exists, service_apache2,
323
 
                                                 log, mock_call):
 
321
    def test_doesnt_enable_if_module_not_provided(self, apt_get_install,
 
322
                                                  path_exists, service_apache2,
 
323
                                                  log, mock_call):
324
324
        module = None
325
325
 
326
326
        result = hooks.enable_module(module)
337
337
    @patch('hooks.service_apache2')
338
338
    @patch('os.path.exists')
339
339
    @patch('hooks.apt_get_install')
340
 
    def test_does_nothing_if_module_already_enabled(self, apt_get_install,
341
 
                                                    path_exists,
342
 
                                                    service_apache2, log,
343
 
                                                    mock_call):
 
340
    def test_doesnt_enable_if_module_already_enabled(self, apt_get_install,
 
341
                                                     path_exists,
 
342
                                                     service_apache2, log,
 
343
                                                     mock_call):
344
344
        module = 'foo'
345
345
        module_already_enabled = True
346
346
 
415
415
        self.assertFalse(log.called)
416
416
        self.assertFalse(service_apache2.called)
417
417
 
 
418
    @patch('subprocess.call')
 
419
    @patch('hooks.log')
 
420
    @patch('hooks.service_apache2')
 
421
    @patch('os.path.exists')
 
422
    def test_disables_a_module(self, path_exists, service_apache2, log,
 
423
                               mock_call):
 
424
        module = 'foo'
 
425
        module_still_enabled = True
 
426
        apache_check = True
 
427
        apache_reload = None
 
428
        module_finally_disabled = 0
 
429
 
 
430
        path_exists.return_value = module_still_enabled
 
431
        service_apache2.side_effect = [apache_check, apache_reload]
 
432
        mock_call.return_value = module_finally_disabled
 
433
 
 
434
        result = hooks.disable_module(module)
 
435
 
 
436
        self.assertTrue(result)
 
437
        path_exists.assert_called_with(
 
438
            "/etc/apache2/mods-enabled/%s.load" % (module))
 
439
        mock_call.assert_called_with(['/usr/sbin/a2dismod', module])
 
440
        service_apache2.assert_has_calls([call('check'), call('reload')])
 
441
        self.assertFalse(log.called)
 
442
 
 
443
    @patch('subprocess.call')
 
444
    @patch('hooks.log')
 
445
    @patch('hooks.service_apache2')
 
446
    @patch('os.path.exists')
 
447
    def test_doest_disable_if_module_not_provided(self, path_exists,
 
448
                                                  service_apache2, log,
 
449
                                                  mock_call):
 
450
        module = None
 
451
 
 
452
        result = hooks.disable_module(module)
 
453
 
 
454
        self.assertTrue(result)
 
455
        self.assertFalse(path_exists.called)
 
456
        self.assertFalse(service_apache2.called)
 
457
        self.assertFalse(log.called)
 
458
        self.assertFalse(mock_call.called)
 
459
 
 
460
    @patch('subprocess.call')
 
461
    @patch('hooks.log')
 
462
    @patch('hooks.service_apache2')
 
463
    @patch('os.path.exists')
 
464
    def test_does_nothing_if_module_already_disabled(self, path_exists,
 
465
                                                     service_apache2, log,
 
466
                                                     mock_call):
 
467
        module = 'foo'
 
468
        module_still_enabled = False
 
469
 
 
470
        path_exists.return_value = module_still_enabled
 
471
 
 
472
        result = hooks.disable_module(module)
 
473
 
 
474
        self.assertTrue(result)
 
475
        path_exists.assert_called_with(
 
476
            "/etc/apache2/mods-enabled/%s.load" % (module))
 
477
        log.assert_called_with("Module already disabled")
 
478
 
 
479
    @patch('subprocess.call')
 
480
    @patch('hooks.log')
 
481
    @patch('hooks.service_apache2')
 
482
    @patch('os.path.exists')
 
483
    def test_fails_to_disable_if_dismod_fails(self, path_exists,
 
484
                                              service_apache2, log, mock_call):
 
485
        module = 'foo'
 
486
        module_still_enabled = True
 
487
        apache_check = True
 
488
        apache_reload = None
 
489
        module_finally_disabled = 1
 
490
 
 
491
        path_exists.return_value = module_still_enabled
 
492
        service_apache2.side_effect = [apache_check, apache_reload]
 
493
        mock_call.return_value = module_finally_disabled
 
494
 
 
495
        result = hooks.disable_module(module)
 
496
 
 
497
        self.assertFalse(result)
 
498
        path_exists.assert_called_with(
 
499
            "/etc/apache2/mods-enabled/%s.load" % (module))
 
500
        mock_call.assert_called_with(['/usr/sbin/a2dismod', module])
 
501
        self.assertFalse(service_apache2.called)
 
502
        self.assertFalse(log.called)
 
503
 
418
504
 
419
505
class RelationsTest(TestCase):
420
506
    @patch('subprocess.check_output')