def test_get_dbstatus_delete_success(self, mock_client): # test successful delete of the db cluster mock_rds = mock_client.return_value mock_rds.get_waiter.return_value = self.mock_waiter event = {"output": {"taskname": "Delete", "identifier": "database-1"}} context = ContextManager(20) data = get_dbstatus_function.lambda_get_dbinstance_status( event, context) self.assertEqual(data.get("taskname"), "Delete") self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), self.task_complete)
def test_get_dbstatus_rename_success(self, mock_client): #test availability status of db instance post rename operation mock_rds = mock_client.return_value mock_waiter = self.mock_waiter mock_rds.get_waiter.return_value = mock_waiter event = {"output": {"taskname": "Rename", "identifier": "database-1"}} context = ContextManager(45) data = get_dbstatus_function.lambda_get_dbinstance_status( event, context) self.assertEqual(data.get("taskname"), "Rename") self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), self.task_complete)
def test_get_dbstatus_delete_failure(self, mock_client): # test rds waiter max attempt limit post deleting a db cluster mock_rds = mock_client.return_value mock_waiter = self.mock_waiter mock_rds.get_waiter.return_value = mock_waiter mock_waiter.wait.side_effect = Exception( "Waiter database-1 Max attempts exceeded") event = {"output": {"taskname": "Delete", "identifier": "database-1"}} context = ContextManager(50) with self.assertRaises(custom_exceptions.RateExceededException) as err: _ = get_dbstatus_function.lambda_get_dbinstance_status( event, context) self.assertEqual(err.exception, self.mock_rateexceeded_exception)
def test_get_dbstatus_restore_max_attempts_exceeded_failure( self, mock_client): #test rate limiting while checking status post any operation mock_rds = mock_client.return_value mock_waiter = self.mock_waiter mock_rds.get_waiter.return_value = mock_waiter mock_waiter.wait.side_effect = Exception( "Waiter database-1 Max attempts exceeded") event = {"output": {"taskname": "Restore", "identifier": "database-1"}} context = ContextManager(40) with self.assertRaises(custom_exceptions.RateExceededException) as err: _ = get_dbstatus_function.lambda_get_dbinstance_status( event, context) self.assertEqual(err.exception, self.mock_rateexceeded_exception)
def test_get_dbstatus_restore_instance_not_found(self, mock_client): #test instance not found exception while checking status post any db instance operation mock_rds = mock_client.return_value mock_waiter = self.mock_waiter mock_rds.get_waiter.return_value = mock_waiter mock_waiter.wait.side_effect = Exception("Waiter database-1 not found") event = {"output": {"taskname": "Restore", "identifier": "database-1"}} context = ContextManager(25) with self.assertRaises( custom_exceptions.InstanceUnavailableException) as err: _ = get_dbstatus_function.lambda_get_dbinstance_status( event, context) self.assertEqual(err.exception, self.mock_instance_not_found_failure)
def test_get_dbstatus_restore_failed(self, mock_client): #test failure of rds waiter post db instance restore operation mock_rds = mock_client.return_value mock_waiter = self.mock_waiter mock_rds.get_waiter.return_value = mock_waiter mock_waiter.wait.side_effect = Exception( "Waiter encountered a terminal failure state") event = {"output": {"taskname": "Restore", "identifier": "database-1"}} context = ContextManager(55) data = get_dbstatus_function.lambda_get_dbinstance_status( event, context) self.assertEqual(data.get("taskname"), "Restore") self.assertEqual(data.get("status"), self.mock_snapshot_creation_failure_status) self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), self.task_failed)