diff --git a/meorg_client/cli.py b/meorg_client/cli.py index 6ae9267..2f38fad 100644 --- a/meorg_client/cli.py +++ b/meorg_client/cli.py @@ -191,6 +191,21 @@ def file_attach(file_id: str, output_id: str): click.echo("SUCCESS") +@click.command("detach_all") +@click.argument("output_id") +def file_detach_all(output_id: str): + """Detach all files from a model output. + + Parameters + ---------- + output_id : str + Model output ID. + """ + client = _get_client() + _ = _call(client.detach_all_files_from_model_output, id=output_id) + click.echo("SUCCESS") + + @click.command("start") @click.argument("id") def analysis_start(id: str): diff --git a/meorg_client/client.py b/meorg_client/client.py index edd082a..397a5ad 100644 --- a/meorg_client/client.py +++ b/meorg_client/client.py @@ -375,6 +375,30 @@ def attach_files_to_model_output( json=new_files, ) + def detach_all_files_from_model_output( + self, id: str + ) -> Union[dict, requests.Response]: + """Detach all files from a model output. + + Parameters + ---------- + id : str + Model output ID. + + Returns + ------- + Union[dict, requests.Response] + Response from ME.org + """ + + # Update the resource with an empty file list + return self._make_request( + mcc.HTTP_PATCH, + endpoint=endpoints.FILE_LIST, + url_params=dict(id=id), + json=[], + ) + def start_analysis(self, id: str) -> Union[dict, requests.Response]: """Start the analysis chain. diff --git a/meorg_client/tests/test_cli.py b/meorg_client/tests/test_cli.py index 35423c0..d58ff7c 100644 --- a/meorg_client/tests/test_cli.py +++ b/meorg_client/tests/test_cli.py @@ -108,3 +108,13 @@ def test_file_upload_parallel_with_attach(runner, test_filepath): [test_filepath, test_filepath, "--attach_to", model_output_id], ) assert result.exit_code == 0 + + +def test_detach_all(runner): + """Test detaching all files from a model output.""" + model_output_id = store.get("model_output_id") + result = runner.invoke( + cli.file_detach_all, + [model_output_id], + ) + assert result.exit_code == 0 diff --git a/meorg_client/tests/test_client.py b/meorg_client/tests/test_client.py index b2a964a..a17793e 100644 --- a/meorg_client/tests/test_client.py +++ b/meorg_client/tests/test_client.py @@ -186,6 +186,17 @@ def test_upload_file_parallel_with_attach(client: Client, test_filepath: str): ) +def test_detach_all_files_from_model_output(client: Client): + """Test detaching all files from a model output.""" + + # Remove them all + _ = client.detach_all_files_from_model_output(client._model_output_id) + detached_files = client.list_files(client._model_output_id) + + assert client.last_response.ok + assert len(detached_files.get("data").get("files")) == 0 + + def test_logout(client: Client): """Test logout.""" client.logout()