From c10d7547349c951b4a7ab623234183c08428751c Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Fri, 16 Feb 2024 15:07:18 +0100 Subject: [PATCH] [files] add new function gazu.files.remove_preview_file --- gazu/files.py | 14 ++++++++++++++ tests/test_files.py | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/gazu/files.py b/gazu/files.py index a84bd69d..b36cfb48 100644 --- a/gazu/files.py +++ b/gazu/files.py @@ -147,6 +147,20 @@ def get_preview_file(preview_file_id, client=default): return raw.fetch_one("preview-files", preview_file_id, client=client) +def remove_preview_file(preview_file, client=default): + """ + Remove given preview file from database. + + Args: + preview_file (str / dict): The preview_file dict or ID. + """ + preview_file = normalize_model_parameter(preview_file) + return raw.delete( + "data/preview-files/%s" % preview_file["id"], + client=client, + ) + + @cache def get_all_preview_files_for_task(task, client=default): """ diff --git a/tests/test_files.py b/tests/test_files.py index 966cb74f..a8c585d7 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -1067,6 +1067,16 @@ def test_get_preview_file(self): ) self.assertEqual(preview_file["name"], "preview-file-1") + def test_remove_preview_file(self): + with requests_mock.mock() as mock: + mock_route( + mock, + "DELETE", + "data/preview-files/%s" % fakeid("preview-file-1"), + status_code=204, + ) + gazu.files.remove_preview_file(fakeid("preview-file-1")) + def test_get_all_preview_files_for_task(self): with requests_mock.mock() as mock: text = [