generated from unai/python_boilerplate
feat: add tests for _write_m3u handling of epg_channel_id presence and absence
This commit is contained in:
parent
545958028d
commit
34420e6758
@ -304,6 +304,104 @@ class TestPlaylistManager:
|
||||
# Verificar URL
|
||||
assert lines[2] == "http://iptv.com/live/user/pass/123.ts"
|
||||
|
||||
def test_write_m3u_uses_epg_channel_id_when_present(self, temp_dir):
|
||||
"""Test: _write_m3u usa epg_channel_id en tvg-id cuando está presente."""
|
||||
channel = [
|
||||
{
|
||||
"name": "Test Channel",
|
||||
"stream_id": 123,
|
||||
"stream_icon": "http://icon.com/test.png",
|
||||
"category_id": "5",
|
||||
"epg_channel_id": "test.channel.epg",
|
||||
}
|
||||
]
|
||||
|
||||
with patch("m3u_list_builder.playlist.PUBLIC_DIR", temp_dir):
|
||||
with patch("m3u_list_builder.playlist.settings") as mock_settings:
|
||||
mock_settings.host = "http://iptv.com"
|
||||
mock_settings.username = "user"
|
||||
mock_settings.password = "pass"
|
||||
mock_settings.output_file = "playlist.m3u"
|
||||
mock_settings.include_text = []
|
||||
mock_settings.exclude_text = []
|
||||
|
||||
from m3u_list_builder.playlist import PlaylistManager
|
||||
|
||||
manager = PlaylistManager()
|
||||
manager._write_m3u(channel)
|
||||
|
||||
output_file = temp_dir / "playlist.m3u"
|
||||
content = output_file.read_text()
|
||||
|
||||
# Debe usar epg_channel_id en tvg-id
|
||||
assert 'tvg-id="test.channel.epg"' in content
|
||||
# El nombre debe seguir apareciendo al final de EXTINF
|
||||
assert ",Test Channel" in content
|
||||
|
||||
def test_write_m3u_falls_back_to_name_when_epg_channel_id_empty(self, temp_dir):
|
||||
"""Test: _write_m3u usa name como tvg-id cuando epg_channel_id está vacío."""
|
||||
channel = [
|
||||
{
|
||||
"name": "Fallback Channel",
|
||||
"stream_id": 456,
|
||||
"stream_icon": "",
|
||||
"category_id": "1",
|
||||
"epg_channel_id": "",
|
||||
}
|
||||
]
|
||||
|
||||
with patch("m3u_list_builder.playlist.PUBLIC_DIR", temp_dir):
|
||||
with patch("m3u_list_builder.playlist.settings") as mock_settings:
|
||||
mock_settings.host = "http://iptv.com"
|
||||
mock_settings.username = "user"
|
||||
mock_settings.password = "pass"
|
||||
mock_settings.output_file = "playlist.m3u"
|
||||
mock_settings.include_text = []
|
||||
mock_settings.exclude_text = []
|
||||
|
||||
from m3u_list_builder.playlist import PlaylistManager
|
||||
|
||||
manager = PlaylistManager()
|
||||
manager._write_m3u(channel)
|
||||
|
||||
output_file = temp_dir / "playlist.m3u"
|
||||
content = output_file.read_text()
|
||||
|
||||
# Debe usar name como fallback en tvg-id
|
||||
assert 'tvg-id="Fallback Channel"' in content
|
||||
|
||||
def test_write_m3u_falls_back_to_name_when_epg_channel_id_missing(self, temp_dir):
|
||||
"""Test: _write_m3u usa name como tvg-id cuando epg_channel_id no existe."""
|
||||
channel = [
|
||||
{
|
||||
"name": "No EPG Channel",
|
||||
"stream_id": 789,
|
||||
"stream_icon": "",
|
||||
"category_id": "2",
|
||||
# No epg_channel_id field at all
|
||||
}
|
||||
]
|
||||
|
||||
with patch("m3u_list_builder.playlist.PUBLIC_DIR", temp_dir):
|
||||
with patch("m3u_list_builder.playlist.settings") as mock_settings:
|
||||
mock_settings.host = "http://iptv.com"
|
||||
mock_settings.username = "user"
|
||||
mock_settings.password = "pass"
|
||||
mock_settings.output_file = "playlist.m3u"
|
||||
mock_settings.include_text = []
|
||||
mock_settings.exclude_text = []
|
||||
|
||||
from m3u_list_builder.playlist import PlaylistManager
|
||||
|
||||
manager = PlaylistManager()
|
||||
manager._write_m3u(channel)
|
||||
|
||||
output_file = temp_dir / "playlist.m3u"
|
||||
content = output_file.read_text()
|
||||
|
||||
# Debe usar name como fallback en tvg-id
|
||||
assert 'tvg-id="No EPG Channel"' in content
|
||||
|
||||
def test_write_m3u_missing_fields_uses_defaults(self, temp_dir, minimal_channel):
|
||||
"""Test: _write_m3u usa valores por defecto para campos faltantes."""
|
||||
with patch("m3u_list_builder.playlist.PUBLIC_DIR", temp_dir):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user