From 6fe61cd5e3b185730038399d87440a99f8abf7a1 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 6 Dec 2023 17:10:48 +0100 Subject: [PATCH] fix transcript delete --- server/reflector/db/transcripts.py | 5 ++++- server/tests/test_transcripts_audio_download.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/reflector/db/transcripts.py b/server/reflector/db/transcripts.py index 78e34a1c..310f97e3 100644 --- a/server/reflector/db/transcripts.py +++ b/server/reflector/db/transcripts.py @@ -1,4 +1,5 @@ import json +import os from contextlib import asynccontextmanager from datetime import datetime from pathlib import Path @@ -188,7 +189,9 @@ class Transcript(BaseModel): return [participant.model_dump(mode=mode) for participant in self.participants] def unlink(self): - self.data_path.unlink(missing_ok=True) + for filename in os.listdir(self.data_path): + if os.path.isfile(os.path.join("directory_path", filename)): + os.remove(os.path.join("directory_path", filename)) @property def data_path(self): diff --git a/server/tests/test_transcripts_audio_download.py b/server/tests/test_transcripts_audio_download.py index 28f83fff..efedeb59 100644 --- a/server/tests/test_transcripts_audio_download.py +++ b/server/tests/test_transcripts_audio_download.py @@ -118,3 +118,16 @@ async def test_transcript_audio_download_range_with_seek( assert response.status_code == 206 assert response.headers["content-type"] == content_type assert response.headers["content-range"].startswith("bytes 100-") + + +@pytest.mark.asyncio +async def test_transcript_delete_with_audio(fake_transcript): + from reflector.app import app + + ac = AsyncClient(app=app, base_url="http://test/v1") + response = await ac.delete(f"/transcripts/{fake_transcript.id}") + assert response.status_code == 200 + assert response.json()["status"] == "ok" + + response = await ac.get(f"/transcripts/{fake_transcript.id}") + assert response.status_code == 404