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"]}' 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):