diff --git a/circle/dashboard/tests/test_views.py b/circle/dashboard/tests/test_views.py index 41b19e8..d79c260 100644 --- a/circle/dashboard/tests/test_views.py +++ b/circle/dashboard/tests/test_views.py @@ -529,36 +529,38 @@ class VmDetailTest(LoginMixin, TestCase): def test_permitted_wake_up_wrong_state(self): c = Client() self.login(c, "user2") - with patch.object(WakeUpOperation, 'async') as mock_method: + with patch.object(WakeUpOperation, 'async') as mock_method, \ + patch.object(Instance.WrongStateError, 'send_message') as wro: inst = Instance.objects.get(pk=1) mock_method.side_effect = inst.wake_up inst.status = 'RUNNING' inst.set_level(self.u2, 'owner') - with patch('dashboard.views.messages') as msg: - c.post("/dashboard/vm/1/op/wake_up/") - assert msg.error.called + c.post("/dashboard/vm/1/op/wake_up/") inst = Instance.objects.get(pk=1) self.assertEqual(inst.status, 'RUNNING') # mocked anyway assert mock_method.called + assert wro.called def test_permitted_wake_up(self): c = Client() self.login(c, "user2") - with patch.object(Instance, 'select_node', return_value=None): - with patch.object(WakeUpOperation, 'async') as new_wake_up: - with patch('vm.tasks.vm_tasks.wake_up.apply_async') as wuaa: - inst = Instance.objects.get(pk=1) - new_wake_up.side_effect = inst.wake_up - inst.get_remote_queue_name = Mock(return_value='test') - inst.status = 'SUSPENDED' - inst.set_level(self.u2, 'owner') - with patch('dashboard.views.messages') as msg: - response = c.post("/dashboard/vm/1/op/wake_up/") - assert not msg.error.called - self.assertEqual(response.status_code, 302) - self.assertEqual(inst.status, 'RUNNING') - assert new_wake_up.called - assert wuaa.called + with patch.object(Instance, 'select_node', return_value=None), \ + patch.object(WakeUpOperation, 'async') as new_wake_up, \ + patch('vm.tasks.vm_tasks.wake_up.apply_async') as wuaa, \ + patch.object(Instance.WrongStateError, 'send_message') as wro: + inst = Instance.objects.get(pk=1) + new_wake_up.side_effect = inst.wake_up + inst.get_remote_queue_name = Mock(return_value='test') + inst.status = 'SUSPENDED' + inst.set_level(self.u2, 'owner') + with patch('dashboard.views.messages') as msg: + response = c.post("/dashboard/vm/1/op/wake_up/") + assert not msg.error.called + self.assertEqual(response.status_code, 302) + self.assertEqual(inst.status, 'RUNNING') + assert new_wake_up.called + assert wuaa.called + assert not wro.called def test_unpermitted_wake_up(self): c = Client()