def test_is_deleted_exceptions(self, mock_manager): mock_manager.side_effect = [ boto_exception.EC2ResponseError( status="fake", reason="fake", body={"Error": { "Code": "fake_code" }}), boto_exception.EC2ResponseError( status="fake", reason="fake", body={"Error": { "Code": "InvalidInstanceID.NotFound" }}) ] manager = resources.EC2Server(resource=mock.MagicMock()) self.assertFalse(manager.is_deleted()) self.assertTrue(manager.is_deleted())
def test_is_deleted(self, mock_manager): raw_res1 = mock.MagicMock(state="terminated") raw_res2 = mock.MagicMock(state="terminated") resource = mock.MagicMock(id="test_id") manager = resources.EC2Server(resource=resource) mock_manager().get_only_instances.return_value = [raw_res1] self.assertTrue(manager.is_deleted()) raw_res1.state = "running" self.assertFalse(manager.is_deleted()) mock_manager().get_only_instances.return_value = [raw_res1, raw_res2] self.assertFalse(manager.is_deleted()) raw_res1.state = "terminated" self.assertTrue(manager.is_deleted()) mock_manager().get_only_instances.return_value = [] self.assertTrue(manager.is_deleted())
def test_list(self, mock_manager): manager = resources.EC2Server() mock_manager().get_only_instances.return_value = ["a", "b", "c"] self.assertEqual(["a", "b", "c"], manager.list())
def test_delete(self, mock_manager): resource = mock.MagicMock(id="test_id") manager = resources.EC2Server(resource=resource) manager.delete() mock_manager().terminate_instances.assert_called_once_with( instance_ids=["test_id"])