4
from test_utils import CharmTestCase
6
with patch('nova_compute_utils.register_configs') as configs:
7
configs.return_value = 'test-config'
8
import pause_resume as actions
11
class PauseTestCase(CharmTestCase):
14
super(PauseTestCase, self).setUp(
15
actions, ["pause_unit_helper"])
17
def test_pauses_services(self):
19
self.pause_unit_helper.assert_called_once_with('test-config')
22
class ResumeTestCase(CharmTestCase):
25
super(ResumeTestCase, self).setUp(
26
actions, ["resume_unit_helper"])
28
def test_pauses_services(self):
30
self.resume_unit_helper.assert_called_once_with('test-config')
33
class MainTestCase(CharmTestCase):
36
super(MainTestCase, self).setUp(actions, ["action_fail"])
38
def test_invokes_action(self):
41
def dummy_action(args):
42
dummy_calls.append(True)
44
with mock.patch.dict(actions.ACTIONS, {"foo": dummy_action}):
46
self.assertEqual(dummy_calls, [True])
48
def test_unknown_action(self):
49
"""Unknown actions aren't a traceback."""
50
exit_string = actions.main(["foo"])
51
self.assertEqual("Action foo undefined", exit_string)
53
def test_failing_action(self):
54
"""Actions which traceback trigger action_fail() calls."""
57
self.action_fail.side_effect = dummy_calls.append
59
def dummy_action(args):
60
raise ValueError("uh oh")
62
with mock.patch.dict(actions.ACTIONS, {"foo": dummy_action}):
64
self.assertEqual(dummy_calls, ["Action foo failed: uh oh"])