Initial import: Music_Server, MusicFree, catalog-sync

This commit is contained in:
2026-05-23 16:51:14 +08:00
commit 069af30dba
847 changed files with 179878 additions and 0 deletions
@@ -0,0 +1,58 @@
import unittest
from pathlib import Path
from music_server.services.local_streaming import (
RangeNotSatisfiable,
guess_audio_media_type,
parse_single_range,
)
class GuessAudioMediaTypeTests(unittest.TestCase):
def test_guess_audio_media_type_supported_extensions(self):
self.assertEqual("audio/flac", guess_audio_media_type("a.flac"))
self.assertEqual("audio/mpeg", guess_audio_media_type("a.mp3"))
self.assertEqual("audio/mp4", guess_audio_media_type(Path("a.m4a")))
self.assertEqual("audio/wav", guess_audio_media_type("a.wav"))
self.assertEqual("audio/ogg", guess_audio_media_type("a.ogg"))
self.assertEqual("audio/ape", guess_audio_media_type("a.ape"))
def test_guess_audio_media_type_falls_back_to_octet_stream(self):
self.assertEqual("application/octet-stream", guess_audio_media_type("a.bin"))
class ParseSingleRangeTests(unittest.TestCase):
def test_parse_single_range_returns_none_for_missing_header(self):
self.assertIsNone(parse_single_range(None, 10))
def test_parse_single_range_explicit_start_end(self):
self.assertEqual((2, 5), parse_single_range("bytes=2-5", 10))
def test_parse_single_range_clamps_out_of_bounds_end(self):
self.assertEqual((0, 9), parse_single_range("bytes=0-999", 10))
def test_parse_single_range_suffix(self):
self.assertEqual((6, 9), parse_single_range("bytes=-4", 10))
def test_parse_single_range_open_ended(self):
self.assertEqual((2, 9), parse_single_range("bytes=2-", 10))
def test_parse_single_range_rejects_out_of_bounds(self):
with self.assertRaises(RangeNotSatisfiable):
parse_single_range("bytes=10-12", 10)
def test_parse_single_range_rejects_reverse_range(self):
with self.assertRaises(RangeNotSatisfiable):
parse_single_range("bytes=7-2", 10)
def test_parse_single_range_rejects_multi_range(self):
with self.assertRaises(RangeNotSatisfiable):
parse_single_range("bytes=0-1,3-4", 10)
def test_parse_single_range_rejects_non_bytes_unit(self):
with self.assertRaises(RangeNotSatisfiable):
parse_single_range("items=0-1", 10)
if __name__ == "__main__":
unittest.main()