def test_get_dbstatus_rename_success(self, mock_waiter_patch, mock_client): #test availability status of db cluster post rename operation mock_rds = mock_client.return_value mock_rds.describe_db_clusters.return_value = self.mocked_describe_db_clusters mock_waiter_client = mock_waiter_patch.start() mock_waiter_client.check_dbcluster_status.return_value = self.mock_waiter mock_rds.get_waiter.return_value = self.mock_waiter event = {"output": {"taskname": "Rename", "identifier": "database-1"}} context = ContextManager(145) data = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(data.get("taskname"), "Rename") self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), "TASK_COMPLETE")
def test_get_dbstatus_rename_failure(self, mock_waiter_patch, mock_client): #test expiry scenario of rds waiter post rename operation of db cluster mock_rds = mock_client.return_value mock_rds.describe_db_clusters.return_value = self.mocked_describe_db_clusters mock_waiter_client = mock_waiter_patch.start() mock_waiter = self.mock_waiter mock_waiter_client.check_dbcluster_status.return_value = mock_waiter mock_rds.get_waiter.return_value = mock_waiter mock_waiter.wait.side_effect = Exception( "Waiter database-1-instance-1 Max attempts exceeded") event = {"output": {"taskname": "Rename", "identifier": "database-1"}} context = ContextManager(45) with self.assertRaises(custom_exceptions.RateExceededException) as err: _ = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(err.exception, self.mock_rateexceeded_exception)
def test_get_dbstatus_restore_max_attempts_exceeded( self, mock_waiter_patch, mock_client): #test rate limiting while checking status post any cluster operation mock_rds = mock_client.return_value mock_rds.describe_db_clusters.return_value = self.mocked_describe_db_clusters mock_waiter_client = mock_waiter_patch.start() mock_waiter = self.mock_waiter mock_waiter_client.check_dbcluster_status.return_value = 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(55) with self.assertRaises(Exception) as err: _ = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(err.exception, self.mock_rateexceeded_exception)
def test_cluster_unavailable(self, mock_waiter_patch, mock_client): #test instance not found exception while checking status post any cluster operation mock_rds = mock_client.return_value mock_rds.describe_db_clusters.return_value = self.mocked_describe_db_clusters mock_waiter_client = mock_waiter_patch.start() mock_waiter = self.mock_waiter mock_waiter_client.check_dbcluster_status.return_value = 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(45) with self.assertRaises(Exception) as err: _ = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(err.exception, self.mock_instance_not_found_failure)
def test_get_dbstatus_snapshot_success(self, mock_client): #test successful availability of cluster snapshot post create operation mock_rds = mock_client.return_value mock_rds.get_waiter.return_value = self.mock_waiter event = { "output": { "taskname": "SnapshotCreation", "identifier": "database-1" } } context = ContextManager(45) data = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(data.get("taskname"), "SnapshotCreation") self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), "TASK_COMPLETE")
def test_get_dbstatus_restore_failed(self, mock_waiter_patch, mock_client): #test failure of rds waiter post cluster restore operation mock_rds = mock_client.return_value mock_rds.describe_db_clusters.return_value = self.mocked_describe_db_clusters mock_waiter_client = mock_waiter_patch.start() mock_waiter = self.mock_waiter mock_waiter_client.check_dbcluster_status.return_value = 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(45) data = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(data.get("taskname"), "Restore") self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), self.task_complete)
def test_get_dbstatus_snapshot_failure(self, mock_client): #test failure of rds waiter post cluster snapshot creation 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": "SnapshotCreation", "identifier": "database-1" } } context = ContextManager(45) with self.assertRaises(Exception) as err: _ = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(err.exception, self.mock_snapshot_creation_failure_status)
def test_get_dbstatus_delete_success(self, mock_client): # test successful delete of the db cluster # in case of successful delete, instance not found exception is caught # and required status returned mock_rds = mock_client.return_value mock_rds.get_waiter.return_value = self.mock_waiter 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": "Delete", "identifier": "database-1"}} context = ContextManager(145) with self.assertRaises(custom_exceptions.DeletionException) as err: data = get_dbcluster_status_function.lambda_get_cluster_status( event, context) self.assertEqual(err.exception, self.mock_instance_not_found_failure) self.assertEqual(data.get("taskname"), "Delete") self.assertEqual(data.get("identifier"), "database-1") self.assertEqual(data.get("task"), "TASK_COMPLETE")