def test_take_snapshot_and_lab_is_not_whitelisted(self, mock_take_snapshot, mock_change_lab_status): my_lab = "reserved_lab" with HTTMock(self.mock_api): with self.assertRaises(exceptions.TaskError): snapshot_tasks.take_snapshot(my_lab, "not_whitelisted_state", "etag", lab_whitelisted=False) mock_change_lab_status.assert_called_with(my_lab, "state_operation_failed") mock_take_snapshot.assert_not_called()
def test_take_snapshot_fails(self, mock_change_state, mock_change_lab_status, mock_snapshot_status, mock_take_snapshot): my_lab = "reserved_lab" mock_snapshot_status.side_effect = ["queued", "creating"] mock_take_snapshot.side_effect = [RuntimeError] mock_change_state.return_value = "etag" with HTTMock(self.mock_api): with self.assertRaises(RuntimeError): snapshot_tasks.take_snapshot(my_lab, "some_state", "etag", lab_whitelisted=True) mock_take_snapshot.assert_called_with(my_lab) mock_change_lab_status.assert_called_with(my_lab, "state_operation_failed") mock_change_state.assert_called_with("some_state", "etag", "failed")
def test_take_snapshot(self, mock_change_lab_status, mock_snapshot_status, mock_take_snapshot): mock_snapshot_status.side_effect = ["queued", "creating"] mock_take_snapshot.return_value = ("some_snapshot_id", "some_event_id") with HTTMock(self.mock_api): self.assertTrue( snapshot_tasks.take_snapshot("reserved_lab", "some_state", "etag", lab_whitelisted=True)) mock_change_lab_status.assert_called_with("reserved_lab", "ready") mock_take_snapshot.assert_called_with("reserved_lab")
def test_take_snapshot_and_lab_is_not_reserved(self, mock_change_lab_status, mock_snapshot_status, mock_take_snapshot): mock_snapshot_status.side_effect = ["queued", "creating"] mock_take_snapshot.return_value = ("some_snapshot_id", "some_event_id") with HTTMock(self.mock_api): with self.assertRaises(exceptions.TaskError): self.assertTrue( snapshot_tasks.take_snapshot("free_lab", "some_state", "etag")) mock_change_lab_status.assert_called_with("free_lab", "state_operation_failed") mock_take_snapshot.assert_not_called()