Exemplo n.º 1
0
 def test_delete_all_requests_dberror(self):
     """
     Tests db error deleting all requests from the request_status table
     """
     exp_err = 'Database Error. Internal database error, please contact LP DAAC User Services'
     try:
         mock_secretsmanager_get_parameter(1)
         database.single_query = Mock(side_effect=[DbError(exp_err)])
         requests_db.delete_all_requests()
         self.fail("expected DatabaseError")
     except requests_db.DatabaseError as err:
         self.assertEqual(exp_err, str(err))
     database.single_query.assert_called_once()
def task(event, context):    #pylint: disable-msg=unused-argument
    """
    Task called by the handler to perform the work.

    This task will parse the input, removing the granuleId and file keys for a granule.

        Args:
            event (dict): passed through from the handler
            context (Object): passed through from the handler

        Returns:
            dict: dict containing granuleId and keys. See handler for detail.

        Raises:
            ExtractFilePathsError: An error occurred parsing the input.
    """
    result = {}
    _LOG.debug(f"event: '{event}' ")
    try:
        function = event['function']
    except KeyError:
        raise BadRequestError("Missing 'function' in input data")

    if function == "query":
        result = query_requests(event)

    if function == "add":
        result = add_request(event)

    if function == "clear":
        result = requests_db.delete_all_requests()

    return result
Exemplo n.º 3
0
 def tearDown(self):
     boto3.client = Mock()  # todo: Why?
     mock_secretsmanager_get_parameter(1)
     try:
         requests_db.delete_all_requests()
     except requests_db.NotFound:
         pass
     except requests_db.DatabaseError:
         pass
     requests_db.request_id_generator = self.mock_generator
     CumulusLogger.error = self.mock_error
     CumulusLogger.info = self.mock_info
     boto3.client = self.mock_boto3_client
     os.environ.pop('PREFIX', None)
     del os.environ['RESTORE_EXPIRE_DAYS']
     del os.environ['RESTORE_REQUEST_RETRIES']
     db_config.del_env()
     del os.environ["RESTORE_RETRIEVAL_TYPE"]
Exemplo n.º 4
0
 def tearDown(self):
     boto3.client = Mock()
     mock_ssm_get_parameter(1)
     requests_db.request_id_generator = self.mock_request_group_id
     requests_db.get_utc_now_iso = self.mock_utcnow
     try:
         requests_db.delete_all_requests()
     except requests_db.NotFound:
         pass
     except requests_db.DatabaseError:
         pass
     boto3.client = self.mock_boto3
     del os.environ["PREFIX"]
     del os.environ["DATABASE_HOST"]
     del os.environ["DATABASE_NAME"]
     del os.environ["DATABASE_USER"]
     del os.environ["DATABASE_PW"]
     del os.environ["PLATFORM"]
Exemplo n.º 5
0
 def tearDown(self):
     boto3.client = Mock()
     mock_ssm_get_parameter(1)
     try:
         requests_db.delete_all_requests()
     except requests_db.NotFound:
         pass
     except requests_db.DatabaseError:
         pass
     requests_db.get_utc_now_iso = self.mock_utcnow
     boto3.client = self.mock_boto3_client
     try:
         del os.environ['COPY_RETRY_SLEEP_SECS']
         del os.environ['COPY_RETRIES']
         del os.environ["DATABASE_HOST"]
         del os.environ["DATABASE_NAME"]
         del os.environ["DATABASE_USER"]
         del os.environ["DATABASE_PW"]
     except KeyError:
         pass
Exemplo n.º 6
0
 def tearDown(self):
     boto3.client = Mock()
     mock_ssm_get_parameter(1)
     try:
         requests_db.delete_all_requests()
     except requests_db.NotFound:
         pass
     except requests_db.DatabaseError:
         pass
     requests_db.request_id_generator = self.mock_generator
     CumulusLogger.error = self.mock_error
     CumulusLogger.info = self.mock_info
     boto3.client = self.mock_boto3_client
     del os.environ['RESTORE_EXPIRE_DAYS']
     del os.environ['RESTORE_REQUEST_RETRIES']
     del os.environ["DATABASE_HOST"]
     del os.environ["DATABASE_NAME"]
     del os.environ["DATABASE_USER"]
     del os.environ["DATABASE_PW"]
     del os.environ["DATABASE_PORT"]
     del os.environ["RESTORE_RETRIEVAL_TYPE"]
Exemplo n.º 7
0
 def test_delete_all_requests(self):
     """
     Tests deleting all requests from the request_status table
     """
     try:
         self.create_test_requests()
         boto3.client = Mock()
         mock_ssm_get_parameter(1)
         result = requests_db.delete_all_requests()
         self.assertEqual([], result)
     except requests_db.DatabaseError as err:
         self.fail(f"delete_all_requests. {str(err)}")
 def tearDown(self):
     boto3.client = Mock()
     mock_secretsmanager_get_parameter(1)
     try:
         requests_db.delete_all_requests()
     except requests_db.NotFound:
         pass
     except requests_db.DatabaseError:
         pass
     requests_db.get_utc_now_iso = self.mock_utcnow
     boto3.client = self.mock_boto3_client
     try:
         os.environ.pop('PREFIX')
         del os.environ['COPY_RETRY_SLEEP_SECS']
         del os.environ['COPY_RETRIES']
         del os.environ['DATABASE_HOST']
         del os.environ['DATABASE_NAME']
         del os.environ['DATABASE_USER']
         del os.environ['DATABASE_PW']
     except KeyError:
         pass
 def test_delete_all_requests(self):
     """
     Tests deleting all requests from the request_status table
     """
     exp_request_ids = [REQUEST_ID1, REQUEST_ID2, REQUEST_ID3, REQUEST_ID4, REQUEST_ID5,
                        REQUEST_ID6, REQUEST_ID7, REQUEST_ID8, REQUEST_ID9, REQUEST_ID10,
                        REQUEST_ID11]
     try:
         create_select_requests(exp_request_ids)
         empty_result = []
         mock_ssm_get_parameter(1)
         database.single_query = Mock(
             side_effect=[empty_result])
         result = requests_db.delete_all_requests()
         database.single_query.assert_called()
         self.assertEqual(empty_result, result)
     except requests_db.DatabaseError as err:
         self.fail(f"delete_all_requests. {str(err)}")