NhanNguyen1309/audio-separation-api
0
1import unittest2from unittest import mock3 4from app.errors import ApiError5from app.chord_validation import ensure_chord_duration6from app.validation import ensure_duration, ensure_supported_extension, ensure_supported_stem_mode7 8 9class ValidationTests(unittest.TestCase):10 def test_accepts_supported_audio_extensions(self):11 self.assertEqual(ensure_supported_extension("song.mp3"), ".mp3")12 self.assertEqual(ensure_supported_extension("mix.WAV"), ".wav")13 self.assertEqual(ensure_supported_extension("voice.m4a"), ".m4a")14 15 def test_rejects_unsupported_audio_extension(self):16 with self.assertRaises(ApiError) as exc_info:17 ensure_supported_extension("archive.zip")18 19 self.assertEqual(exc_info.exception.code, "unsupported_file_type")20 self.assertEqual(exc_info.exception.status_code, 400)21 22 def test_rejects_unsupported_stem_mode(self):23 with self.assertRaises(ApiError) as exc_info:24 ensure_supported_stem_mode("9-stem")25 26 self.assertEqual(exc_info.exception.code, "unsupported_file_type")27 self.assertEqual(exc_info.exception.status_code, 400)28 29 def test_duration_limit_is_ten_minutes(self):30 with mock.patch("app.validation.probe_duration_seconds", return_value=600):31 self.assertEqual(ensure_duration("song.wav"), 600)32 33 with mock.patch("app.validation.probe_duration_seconds", return_value=600.1):34 with self.assertRaises(ApiError) as exc_info:35 ensure_duration("song.wav")36 37 self.assertEqual(exc_info.exception.code, "duration_too_long")38 39 def test_chord_duration_limit_is_ten_minutes(self):40 with mock.patch("app.chord_validation.probe_duration_seconds", return_value=600):41 self.assertEqual(ensure_chord_duration("song.wav"), 600)42 43 with mock.patch("app.chord_validation.probe_duration_seconds", return_value=600.1):44 with self.assertRaises(ApiError) as exc_info:45 ensure_chord_duration("song.wav")46 47 self.assertEqual(exc_info.exception.code, "chord_duration_too_long")48 49 50if __name__ == "__main__":51 unittest.main()52 