From b9f46668a27a4d657f980a8059567dd233daa5a6 Mon Sep 17 00:00:00 2001 From: joao-voltarelli Date: Wed, 9 Jul 2025 12:18:14 -0300 Subject: [PATCH 1/2] ENH: Handling file extensions when posting an artifact --- botcity/maestro/sdk.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/botcity/maestro/sdk.py b/botcity/maestro/sdk.py index 64beae0..38ae946 100644 --- a/botcity/maestro/sdk.py +++ b/botcity/maestro/sdk.py @@ -744,6 +744,19 @@ def post_artifact(self, task_id: int, artifact_name: str, filepath: str) -> mode Returns: Server response message. See [ServerMessage][botcity.maestro.model.ServerMessage] """ + file = Path(filepath) + + if not file.exists(): + raise FileNotFoundError(f"No such file: {filepath}") + + if not file.is_file(): + raise ValueError("Invalid file type. Please make sure you are using a valid file path " + "and not pointing to a directory.") + + file_extension = file.suffix + if not artifact_name.endswith(file_extension): + artifact_name = f"{artifact_name}{file_extension}" + artifact_id = self._create_artifact(task_id=task_id, name=artifact_name, filename=artifact_name) url = f'{self._server}/api/v2/artifact/log/{json.loads(artifact_id.payload)["id"]}' From b551a6bf8e6de5093736cd089f8eba11c6068bea Mon Sep 17 00:00:00 2001 From: joao-voltarelli Date: Wed, 9 Jul 2025 16:52:27 -0300 Subject: [PATCH 2/2] TEST: Updating tests --- tests/integration/test_artifact.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_artifact.py b/tests/integration/test_artifact.py index 91c12e9..9b28281 100644 --- a/tests/integration/test_artifact.py +++ b/tests/integration/test_artifact.py @@ -4,16 +4,32 @@ import pytest -from botcity.maestro import AutomationTask, BotMaestroSDK +from botcity.maestro import Artifact, AutomationTask, BotMaestroSDK def test_post_artifact(maestro: BotMaestroSDK, file: str, task: AutomationTask): - maestro.post_artifact( + artifact_name = "My Artifact.txt" + response = maestro.post_artifact( task_id=task.id, - artifact_name="My Artifact", + artifact_name=artifact_name, filepath=file ) + artifact = Artifact.from_json(response.payload) + assert artifact.name == artifact_name + + +def test_post_artifact_without_file_extension(maestro: BotMaestroSDK, file: str, task: AutomationTask): + artifact_name = "My Artifact" + response = maestro.post_artifact( + task_id=task.id, + artifact_name=artifact_name, + filepath=file + ) + + artifact = Artifact.from_json(response.payload) + assert artifact.name == f"{artifact_name}.txt" + @pytest.mark.depends(name="test_post_artifact") def test_list_artifacts(maestro: BotMaestroSDK):