From e11bdc6d28e3f7b9ec13d835c33104c58cff4473 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Fri, 8 Nov 2024 16:49:05 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20update=20is=5Fsav?= =?UTF-8?q?able=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A recording is savable only if it's active or stopped. In other status (error, already saved, etc.) it won't be possible. I might iterate on this piece of code. Let's ship it. --- src/backend/core/models.py | 8 ++++---- src/backend/core/tests/test_models_recording.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 1e302b01..29d80963 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -540,10 +540,10 @@ class Recording(BaseModel): def is_savable(self) -> bool: """Determine if the recording can be saved based on its current status.""" - is_unsuccessful = RecordingStatusChoices.is_unsuccessful(self.status) - is_already_saved = self.status == RecordingStatusChoices.SAVED - - return not is_unsuccessful and not is_already_saved + return self.status in { + RecordingStatusChoices.ACTIVE, + RecordingStatusChoices.STOPPED, + } class RecordingAccess(BaseAccess): diff --git a/src/backend/core/tests/test_models_recording.py b/src/backend/core/tests/test_models_recording.py index 8b71bd08..065694e4 100644 --- a/src/backend/core/tests/test_models_recording.py +++ b/src/backend/core/tests/test_models_recording.py @@ -173,6 +173,12 @@ def test_models_recording_is_savable_already_saved(): assert recording.is_savable() is False +def test_models_recording_is_savable_only_initiated(): + """Test is_savable for only initiated recording.""" + recording = RecordingFactory(status=RecordingStatusChoices.INITIATED) + assert recording.is_savable() is False + + # Test few corner cases