Skip to content

Commit

Permalink
Fix file path in generate pipeline message function
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrous committed Aug 14, 2023
1 parent 4fda60b commit 29ab71d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 7 additions & 1 deletion sdc_aws_utils/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def generate_file_pipeline_message(file_path: str, alert_type: Optional[str] = N
Function to generate file pipeline message
"""

if "/" in file_path:
file_path = file_path.split("/")[-1]

if alert_type != "delete":
# Get the file name
alert = {
Expand Down Expand Up @@ -203,17 +206,20 @@ def get_message_ts(slack_client: WebClient, slack_channel: str, science_filename
for message in messages:
if "text" in message:
slack_science_filename = parse_slack_message(message["text"])

if not slack_science_filename:
continue
try:
if "/" in slack_science_filename:
slack_science_filename = slack_science_filename.split("/")[-1]
slack_science_file = parser(slack_science_filename)
except ValueError:
continue
science_file = parser(science_filename)

if have_same_keys_and_values(
[slack_science_file, science_file],
["time", "version", "mode", "test"],
["time", "mode", "test"],
):
return message["ts"]

Expand Down
1 change: 1 addition & 0 deletions test_file_manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest content
11 changes: 4 additions & 7 deletions tests/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,15 @@ def test_is_file_manifest_false():

# Test generate_file_pipeline_message function
def test_generate_file_pipeline_message_alert_type():
assert generate_file_pipeline_message("path/to/file.txt") == "Science File - ( _path/to/file.txt_ )"
assert generate_file_pipeline_message("path/to/file.txt") == "Science File - ( _file.txt_ )"


def test_generate_file_pipeline_message_alert_type():
assert generate_file_pipeline_message("path/to/file.txt", "sorted") == "File Sorted - ( _path/to/file.txt_ )"
assert generate_file_pipeline_message("path/to/file.txt", "sorted") == "File Sorted - ( _file.txt_ )"


def test_generate_file_pipeline_message_alert_type():
assert (
generate_file_pipeline_message("path/to/file.txt", "non-existing key")
== "Science File - ( _path/to/file.txt_ )"
)
assert generate_file_pipeline_message("path/to/file.txt", "non-existing key") == "Science File - ( _file.txt_ )"


def test_generate_file_pipeline_message_alert_type_delete():
Expand All @@ -146,7 +143,7 @@ def test_generate_file_pipeline_message_manifest(mocked_manifest):


def test_generate_file_pipeline_message_sorted():
assert generate_file_pipeline_message("path/to/file.txt", "sorted") == "File Sorted - ( _path/to/file.txt_ )"
assert generate_file_pipeline_message("path/to/file.txt", "sorted") == "File Sorted - ( _file.txt_ )"


# Test have_same_keys_and_values function
Expand Down

0 comments on commit 29ab71d

Please sign in to comment.