Skip to content

Commit

Permalink
added testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
ASubaran committed Nov 12, 2024
1 parent 819f091 commit 1aa8e1b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 70 deletions.
38 changes: 0 additions & 38 deletions filenameprocessor/tests/test_lambda_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,44 +166,6 @@ def test_processing_from_configs_failed(self, mock_head_object, mock_upload_to_e
assert response["statusCode"] == 400
assert response["body"] == '"Failed to upload file content to cache from S3 bucket"'

# @mock_s3
# def test_lambda_invalid_csv_header(self):
# """tests SQS queue is not called when CSV headers are invalid due to misspelled header"""
# s3_client = self.set_up_s3_buckets_and_upload_file(
# file_content=VALID_FILE_CONTENT.replace("PERSON_DOB", "PERON_DOB"),
# )

# # Mock the get_supplier_permissions with full FLU permissions. Mock send_to_supplier_queue function.
# with patch("initial_file_validation.get_supplier_permissions", return_value=["FLU_FULL"]), patch(
# "send_sqs_message.send_to_supplier_queue"
# ) as mock_send_to_supplier_queue:
# lambda_handler(event=self.make_event(), context=None)

# mock_send_to_supplier_queue.assert_not_called()
# self.assert_ack_file_in_destination_s3_bucket(s3_client)

# # Validate the content of the ack file to ensure it reports an error due to invalid headers
# ack_file_obj = s3_client.get_object(Bucket=DESTINATION_BUCKET_NAME, Key=VALID_FLU_EMIS_ACK_FILE_KEY)
# ack_file_content = ack_file_obj["Body"].read().decode("utf-8")
# self.assertIn("Fatal Error", ack_file_content)
# self.assertIn("Infrastructure Level Response Value - Processing Error", ack_file_content)

# @mock_s3
# def test_lambda_invalid_columns_header_count(self):
# """tests SQS queue is not called when CSV headers are invalid due to missing header"""
# s3_client = self.set_up_s3_buckets_and_upload_file(
# file_content=VALID_FILE_CONTENT.replace("PERSON_DOB|", ""),
# )

# # Mock the get_supplier_permissions with full FLU permissions. Mock send_to_supplier_queue function.
# with patch("initial_file_validation.get_supplier_permissions", return_value=["FLU_FULL"]), patch(
# "send_sqs_message.send_to_supplier_queue"
# ) as mock_send_to_supplier_queue:
# lambda_handler(event=self.make_event(), context=None)

# mock_send_to_supplier_queue.assert_not_called()
# # self.assert_ack_file_in_destination_s3_bucket(s3_client)

@mock_s3
def test_lambda_invalid_vaccine_type(self):
"""tests SQS queue is not called when file key includes invalid vaccine type"""
Expand Down
86 changes: 54 additions & 32 deletions filenameprocessor/tests/test_make_and_upload_ack_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,23 @@ def setUp(self):
"""Set up test values to be used for the tests"""
self.message_id = str(uuid4())
self.created_at_formatted_string = "20200101T12345600"
self.ack_data_validation_passed_and_message_not_delivered = {
"MESSAGE_HEADER_ID": self.message_id,
"HEADER_RESPONSE_CODE": "Failure",
"ISSUE_SEVERITY": "Information",
"ISSUE_CODE": "OK",
"ISSUE_DETAILS_CODE": "20013",
"RESPONSE_TYPE": "Technical",
"RESPONSE_CODE": "10002",
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
"RECEIVED_TIME": self.created_at_formatted_string,
"MAILBOX_FROM": "",
"LOCAL_ID": "",
"MESSAGE_DELIVERY": False,
}
self.ack_data_validation_failed = {
"MESSAGE_HEADER_ID": self.message_id,
"HEADER_RESPONSE_CODE": "Failure",
"ISSUE_SEVERITY": "Fatal",
"ISSUE_CODE": "Fatal Error",
"ISSUE_DETAILS_CODE": "10001",
"RESPONSE_TYPE": "Technical",
"RESPONSE_CODE": "10002",
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
"RECEIVED_TIME": self.created_at_formatted_string,
"MAILBOX_FROM": "",
"LOCAL_ID": "",
"MESSAGE_DELIVERY": False,
}

def test_make_ack_data(self):
"Tests make_ack_data makes correct ack data based on the input args"
# Test case tuples are stuctured as (validation_passed, message_delivered, expected_result)
test_cases = [
(False, self.ack_data_validation_failed)
(False, {"MESSAGE_HEADER_ID": self.message_id,
"HEADER_RESPONSE_CODE": "Failure",
"ISSUE_SEVERITY": "Fatal",
"ISSUE_CODE": "Fatal Error",
"ISSUE_DETAILS_CODE": "10001",
"RESPONSE_TYPE": "Technical",
"RESPONSE_CODE": "10002",
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
"RECEIVED_TIME": self.created_at_formatted_string,
"MAILBOX_FROM": "",
"LOCAL_ID": "",
"MESSAGE_DELIVERY": False})
# No need to test validation failed and message delivery passed as this scenario cannot occur
]

Expand All @@ -87,8 +70,34 @@ def test_upload_ack_file(self):

# Test case tuples are stuctured as (ack_data, expected_result)
test_cases = [
self.ack_data_validation_passed_and_message_not_delivered,
self.ack_data_validation_failed,
{
"MESSAGE_HEADER_ID": str(uuid4()),
"HEADER_RESPONSE_CODE": "Failure",
"ISSUE_SEVERITY": "Information",
"ISSUE_CODE": "OK",
"ISSUE_DETAILS_CODE": "20013",
"RESPONSE_TYPE": "Technical",
"RESPONSE_CODE": "10002",
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
"RECEIVED_TIME": "20200101T12345600",
"MAILBOX_FROM": "",
"LOCAL_ID": "",
"MESSAGE_DELIVERY": False,
},
{
"MESSAGE_HEADER_ID": str(uuid4()),
"HEADER_RESPONSE_CODE": "Failure",
"ISSUE_SEVERITY": "Fatal",
"ISSUE_CODE": "Fatal Error",
"ISSUE_DETAILS_CODE": "10001",
"RESPONSE_TYPE": "Technical",
"RESPONSE_CODE": "10002",
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
"RECEIVED_TIME": "20200101T12345600",
"MAILBOX_FROM": "",
"LOCAL_ID": "",
"MESSAGE_DELIVERY": False,
}
]

# Call the upload_ack_file function
Expand Down Expand Up @@ -117,7 +126,20 @@ def test_make_and_upload_ack_file(self):

# Test case tuples are stuctured as (validation_passed, message_delivered, expected_result)
test_cases = [
(False, self.ack_data_validation_failed)
(False, {
"MESSAGE_HEADER_ID": self.message_id,
"HEADER_RESPONSE_CODE": "Failure",
"ISSUE_SEVERITY": "Fatal",
"ISSUE_CODE": "Fatal Error",
"ISSUE_DETAILS_CODE": "10001",
"RESPONSE_TYPE": "Technical",
"RESPONSE_CODE": "10002",
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
"RECEIVED_TIME": self.created_at_formatted_string,
"MAILBOX_FROM": "",
"LOCAL_ID": "",
"MESSAGE_DELIVERY": False,
})
]

# Call the make_and_upload_ack_file function
Expand Down

0 comments on commit 1aa8e1b

Please sign in to comment.