✨(backend) add property to check if recording file is saved
Introduce new property that verifies if a recording file has a saved status. While the implementation is straightforward, it improves code readability and provides a clear, semantic way to check file status.
This commit is contained in:
committed by
aleb_the_flash
parent
3671f2a0dd
commit
20aceb1932
@@ -578,6 +578,11 @@ class Recording(BaseModel):
|
|||||||
RecordingStatusChoices.STOPPED,
|
RecordingStatusChoices.STOPPED,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_saved(self) -> bool:
|
||||||
|
"""Check if the recording is in a saved state."""
|
||||||
|
return self.status == RecordingStatusChoices.SAVED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extension(self):
|
def extension(self):
|
||||||
"""Get recording extension based on its mode."""
|
"""Get recording extension based on its mode."""
|
||||||
|
|||||||
@@ -250,3 +250,38 @@ def test_models_recording_key_for_unknown_mode(settings):
|
|||||||
recording.mode = "unknown_mode"
|
recording.mode = "unknown_mode"
|
||||||
expected_path = f"/custom/path/{recording.id}.{FileExtension.MP4.value}"
|
expected_path = f"/custom/path/{recording.id}.{FileExtension.MP4.value}"
|
||||||
assert recording.key == expected_path
|
assert recording.key == expected_path
|
||||||
|
|
||||||
|
|
||||||
|
# Test is_saved method
|
||||||
|
|
||||||
|
|
||||||
|
def test_models_recording_is_saved_true():
|
||||||
|
"""Test is_saved property returns True for SAVED status."""
|
||||||
|
recording = RecordingFactory(status=RecordingStatusChoices.SAVED)
|
||||||
|
assert recording.is_saved is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_models_recording_is_saved_false_active():
|
||||||
|
"""Test is_saved property returns False for ACTIVE status."""
|
||||||
|
recording = RecordingFactory(status=RecordingStatusChoices.ACTIVE)
|
||||||
|
assert recording.is_saved is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_models_recording_is_saved_false_initiated():
|
||||||
|
"""Test is_saved property returns False for INITIATED status."""
|
||||||
|
recording = RecordingFactory(status=RecordingStatusChoices.INITIATED)
|
||||||
|
assert recording.is_saved is False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"status",
|
||||||
|
[
|
||||||
|
RecordingStatusChoices.FAILED_TO_STOP,
|
||||||
|
RecordingStatusChoices.FAILED_TO_START,
|
||||||
|
RecordingStatusChoices.ABORTED,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_models_recording_is_saved_false_error_states(status):
|
||||||
|
"""Test is_saved property returns False for error statuses."""
|
||||||
|
recording = RecordingFactory(status=status)
|
||||||
|
assert recording.is_saved is False
|
||||||
|
|||||||
Reference in New Issue
Block a user