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,
321
def test_doesnt_enable_if_module_not_provided(self, apt_get_install,
322
path_exists, service_apache2,
326
326
result = hooks.enable_module(module)
415
415
self.assertFalse(log.called)
416
416
self.assertFalse(service_apache2.called)
418
@patch('subprocess.call')
420
@patch('hooks.service_apache2')
421
@patch('os.path.exists')
422
def test_disables_a_module(self, path_exists, service_apache2, log,
425
module_still_enabled = True
428
module_finally_disabled = 0
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
434
result = hooks.disable_module(module)
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)
443
@patch('subprocess.call')
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,
452
result = hooks.disable_module(module)
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)
460
@patch('subprocess.call')
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,
468
module_still_enabled = False
470
path_exists.return_value = module_still_enabled
472
result = hooks.disable_module(module)
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")
479
@patch('subprocess.call')
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):
486
module_still_enabled = True
489
module_finally_disabled = 1
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
495
result = hooks.disable_module(module)
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)
419
505
class RelationsTest(TestCase):
420
506
@patch('subprocess.check_output')