コード例 #1
0
    def test_stop_capture_db_nothing_to_stop(self, mock_boto, mock_disable_triggers):
        mock_disable_triggers.return_value = True

        for stage in STAGES:
            os.environ['STAGE'] = stage
            result = handler.stop_capture_db(self.initial_event, self.context)
            assert result['statusCode'] == 200
            assert result['message'] == f"Stopped the {stage} db: False"

        os.environ['STAGE'] = 'UNKNOWN'
        with self.assertRaises(Exception) as context:
            handler.stop_capture_db(self.initial_event, self.context)
コード例 #2
0
    def test_stop_capture_db_something_to_stop(self, mock_boto, mock_disable_triggers):
        mock_disable_triggers.return_value = True
        mock_client = mock.Mock()
        my_mock_db_clusters = self.mock_db_clusters
        mock_client.describe_db_clusters.return_value = my_mock_db_clusters
        mock_client.list_event_source_mappings.return_value = self.mock_event_source_mapping
        mock_boto.return_value = mock_client

        for stage in STAGES:
            my_mock_db_clusters['DBClusters'][0]['DBClusterIdentifier'] = DB[stage]
            my_mock_db_clusters['DBClusters'][0]['Status'] = 'available'
            mock_client.describe_db_clusters.return_value = my_mock_db_clusters
            mock_client.start_db_cluster.return_value = {DB[stage]}
            mock_client.get_queue_url.return_value = {'QueueUrl': 'queue'}
            os.environ['STAGE'] = stage
            result = handler.stop_capture_db(self.initial_event, self.context)
            assert result['statusCode'] == 200
            assert result['message'] == f"Stopped the {stage} db: True"

        os.environ['STAGE'] = 'UNKNOWN'
        with self.assertRaises(Exception) as context:
            handler.stop_capture_db(self.initial_event, self.context)