From 85aa0174c3af9a12b5cf85ecce687460af8a301f Mon Sep 17 00:00:00 2001 From: jo Date: Sat, 25 Feb 2023 18:52:22 +0100 Subject: [PATCH] test(playout): more entrypoint config test cases --- .../__snapshots__/entrypoint_test.ambr | 559 +++++++++++++++++- playout/tests/liquidsoap/entrypoint_test.py | 10 +- playout/tests/liquidsoap/fixtures/__init__.py | 86 +++ 3 files changed, 651 insertions(+), 4 deletions(-) create mode 100644 playout/tests/liquidsoap/fixtures/__init__.py diff --git a/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr b/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr index 05d1814eb..1287a53f7 100644 --- a/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr +++ b/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr @@ -1,5 +1,116 @@ # serializer version: 1 -# name: test_generate_entrypoint[1.4] +# name: test_generate_entrypoint[stream_config0-1.4] + ''' + # THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT! + ########################################################### + # The ignore() lines are to squash unused variable warnings + + # Inputs + input_main_mount = "main" + input_main_port = 8001 + input_show_mount = "show" + input_show_port = 8002 + + # Output s1 + s1_enable = false + s1_output = "icecast" + s1_host = "localhost" + s1_port = 8000 + s1_mount = "" + s1_user = "source" + s1_pass = "" + + s1_channels = "stereo" + s1_type = "ogg" + s1_bitrate = 256 + + s1_name = "" + s1_description = "" + s1_genre = "" + s1_url = "" + + # Output s2 + s2_enable = false + s2_output = "icecast" + s2_host = "localhost" + s2_port = 8000 + s2_mount = "" + s2_user = "source" + s2_pass = "" + + s2_channels = "stereo" + s2_type = "ogg" + s2_bitrate = 256 + + s2_name = "" + s2_description = "" + s2_genre = "" + s2_url = "" + + # Output s3 + s3_enable = false + s3_output = "icecast" + s3_host = "localhost" + s3_port = 8000 + s3_mount = "" + s3_user = "source" + s3_pass = "" + + s3_channels = "stereo" + s3_type = "ogg" + s3_bitrate = 256 + + s3_name = "" + s3_description = "" + s3_genre = "" + s3_url = "" + + # Output s4 + s4_enable = false + s4_output = "icecast" + s4_host = "localhost" + s4_port = 8000 + s4_mount = "" + s4_user = "source" + s4_pass = "" + + s4_channels = "stereo" + s4_type = "ogg" + s4_bitrate = 256 + + s4_name = "" + s4_description = "" + s4_genre = "" + s4_url = "" + + icecast_vorbis_metadata = false + + # System output + output_sound_device = false + output_sound_device_type = "alsa" + + # Settings + auth_path = "/fake/liquidsoap_auth.py" + + set("log.file.path", "/var/log/radio.log") + + set("server.telnet", true) + set("server.telnet.bind_addr", "127.0.0.1") + set("server.telnet.port", 1234) + + set("harbor.bind_addrs", ["0.0.0.0"]) + + station_name = interactive.string("station_name", "LibreTime") + + message_offline = interactive.string("message_offline", "LibreTime - offline") + message_format = interactive.string("message_format", "0") + input_fade_transition = interactive.float("input_fade_transition", 0.0) + + %include "/fake/1.4/ls_script.liq" + + ''' +# --- +# name: test_generate_entrypoint[stream_config1-1.4] ''' # THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT! ########################################################### @@ -30,7 +141,7 @@ s1_url = "https://libretime.org" # Output s2 - s2_enable = true + s2_enable = false s2_output = "icecast" s2_host = "localhost" s2_port = 8000 @@ -110,3 +221,447 @@ ''' # --- +# name: test_generate_entrypoint[stream_config2-1.4] + ''' + # THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT! + ########################################################### + # The ignore() lines are to squash unused variable warnings + + # Inputs + input_main_mount = "main" + input_main_port = 8001 + input_show_mount = "show" + input_show_port = 8002 + + # Output s1 + s1_enable = false + s1_output = "icecast" + s1_host = "localhost" + s1_port = 8000 + s1_mount = "" + s1_user = "source" + s1_pass = "" + + s1_channels = "stereo" + s1_type = "ogg" + s1_bitrate = 256 + + s1_name = "" + s1_description = "" + s1_genre = "" + s1_url = "" + + # Output s2 + s2_enable = false + s2_output = "icecast" + s2_host = "localhost" + s2_port = 8000 + s2_mount = "" + s2_user = "source" + s2_pass = "" + + s2_channels = "stereo" + s2_type = "ogg" + s2_bitrate = 256 + + s2_name = "" + s2_description = "" + s2_genre = "" + s2_url = "" + + # Output s3 + s3_enable = false + s3_output = "icecast" + s3_host = "localhost" + s3_port = 8000 + s3_mount = "" + s3_user = "source" + s3_pass = "" + + s3_channels = "stereo" + s3_type = "ogg" + s3_bitrate = 256 + + s3_name = "" + s3_description = "" + s3_genre = "" + s3_url = "" + + # Output s4 + s4_enable = true + s4_output = "shoutcast" + s4_host = "localhost" + s4_port = 8000 + s4_mount = "" + s4_user = "source" + s4_pass = "hackme" + + s4_channels = "stereo" + s4_type = "mp3" + s4_bitrate = 256 + + s4_name = "LibreTime!" + s4_description = "" + s4_genre = "various" + s4_url = "https://libretime.org" + + icecast_vorbis_metadata = false + + # System output + output_sound_device = false + output_sound_device_type = "alsa" + + # Settings + auth_path = "/fake/liquidsoap_auth.py" + + set("log.file.path", "/var/log/radio.log") + + set("server.telnet", true) + set("server.telnet.bind_addr", "127.0.0.1") + set("server.telnet.port", 1234) + + set("harbor.bind_addrs", ["0.0.0.0"]) + + station_name = interactive.string("station_name", "LibreTime") + + message_offline = interactive.string("message_offline", "LibreTime - offline") + message_format = interactive.string("message_format", "0") + input_fade_transition = interactive.float("input_fade_transition", 0.0) + + %include "/fake/1.4/ls_script.liq" + + ''' +# --- +# name: test_generate_entrypoint[stream_config3-1.4] + ''' + # THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT! + ########################################################### + # The ignore() lines are to squash unused variable warnings + + # Inputs + input_main_mount = "main" + input_main_port = 8001 + input_show_mount = "show" + input_show_port = 8002 + + # Output s1 + s1_enable = true + s1_output = "icecast" + s1_host = "localhost" + s1_port = 8000 + s1_mount = "main" + s1_user = "source" + s1_pass = "hackme" + + s1_channels = "stereo" + s1_type = "ogg" + s1_bitrate = 256 + + s1_name = "" + s1_description = "" + s1_genre = "" + s1_url = "" + + # Output s2 + s2_enable = false + s2_output = "icecast" + s2_host = "localhost" + s2_port = 8000 + s2_mount = "" + s2_user = "source" + s2_pass = "" + + s2_channels = "stereo" + s2_type = "ogg" + s2_bitrate = 256 + + s2_name = "" + s2_description = "" + s2_genre = "" + s2_url = "" + + # Output s3 + s3_enable = false + s3_output = "icecast" + s3_host = "localhost" + s3_port = 8000 + s3_mount = "" + s3_user = "source" + s3_pass = "" + + s3_channels = "stereo" + s3_type = "ogg" + s3_bitrate = 256 + + s3_name = "" + s3_description = "" + s3_genre = "" + s3_url = "" + + # Output s4 + s4_enable = true + s4_output = "shoutcast" + s4_host = "localhost" + s4_port = 8000 + s4_mount = "" + s4_user = "source" + s4_pass = "hackme" + + s4_channels = "stereo" + s4_type = "mp3" + s4_bitrate = 256 + + s4_name = "" + s4_description = "" + s4_genre = "" + s4_url = "" + + icecast_vorbis_metadata = false + + # System output + output_sound_device = false + output_sound_device_type = "alsa" + + # Settings + auth_path = "/fake/liquidsoap_auth.py" + + set("log.file.path", "/var/log/radio.log") + + set("server.telnet", true) + set("server.telnet.bind_addr", "127.0.0.1") + set("server.telnet.port", 1234) + + set("harbor.bind_addrs", ["0.0.0.0"]) + + station_name = interactive.string("station_name", "LibreTime") + + message_offline = interactive.string("message_offline", "LibreTime - offline") + message_format = interactive.string("message_format", "0") + input_fade_transition = interactive.float("input_fade_transition", 0.0) + + %include "/fake/1.4/ls_script.liq" + + ''' +# --- +# name: test_generate_entrypoint[stream_config4-1.4] + ''' + # THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT! + ########################################################### + # The ignore() lines are to squash unused variable warnings + + # Inputs + input_main_mount = "main" + input_main_port = 8001 + input_show_mount = "show" + input_show_port = 8002 + + # Output s1 + s1_enable = false + s1_output = "icecast" + s1_host = "localhost" + s1_port = 8000 + s1_mount = "" + s1_user = "source" + s1_pass = "" + + s1_channels = "stereo" + s1_type = "ogg" + s1_bitrate = 256 + + s1_name = "" + s1_description = "" + s1_genre = "" + s1_url = "" + + # Output s2 + s2_enable = false + s2_output = "icecast" + s2_host = "localhost" + s2_port = 8000 + s2_mount = "" + s2_user = "source" + s2_pass = "" + + s2_channels = "stereo" + s2_type = "ogg" + s2_bitrate = 256 + + s2_name = "" + s2_description = "" + s2_genre = "" + s2_url = "" + + # Output s3 + s3_enable = false + s3_output = "icecast" + s3_host = "localhost" + s3_port = 8000 + s3_mount = "" + s3_user = "source" + s3_pass = "" + + s3_channels = "stereo" + s3_type = "ogg" + s3_bitrate = 256 + + s3_name = "" + s3_description = "" + s3_genre = "" + s3_url = "" + + # Output s4 + s4_enable = false + s4_output = "icecast" + s4_host = "localhost" + s4_port = 8000 + s4_mount = "" + s4_user = "source" + s4_pass = "" + + s4_channels = "stereo" + s4_type = "ogg" + s4_bitrate = 256 + + s4_name = "" + s4_description = "" + s4_genre = "" + s4_url = "" + + icecast_vorbis_metadata = false + + # System output + output_sound_device = true + output_sound_device_type = "pulseaudio" + + # Settings + auth_path = "/fake/liquidsoap_auth.py" + + set("log.file.path", "/var/log/radio.log") + + set("server.telnet", true) + set("server.telnet.bind_addr", "127.0.0.1") + set("server.telnet.port", 1234) + + set("harbor.bind_addrs", ["0.0.0.0"]) + + station_name = interactive.string("station_name", "LibreTime") + + message_offline = interactive.string("message_offline", "LibreTime - offline") + message_format = interactive.string("message_format", "0") + input_fade_transition = interactive.float("input_fade_transition", 0.0) + + %include "/fake/1.4/ls_script.liq" + + ''' +# --- +# name: test_generate_entrypoint[stream_config5-1.4] + ''' + # THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT! + ########################################################### + # The ignore() lines are to squash unused variable warnings + + # Inputs + input_main_mount = "main" + input_main_port = 8001 + input_show_mount = "show" + input_show_port = 8002 + + # Output s1 + s1_enable = false + s1_output = "icecast" + s1_host = "localhost" + s1_port = 8000 + s1_mount = "" + s1_user = "source" + s1_pass = "" + + s1_channels = "stereo" + s1_type = "ogg" + s1_bitrate = 256 + + s1_name = "" + s1_description = "" + s1_genre = "" + s1_url = "" + + # Output s2 + s2_enable = false + s2_output = "icecast" + s2_host = "localhost" + s2_port = 8000 + s2_mount = "" + s2_user = "source" + s2_pass = "" + + s2_channels = "stereo" + s2_type = "ogg" + s2_bitrate = 256 + + s2_name = "" + s2_description = "" + s2_genre = "" + s2_url = "" + + # Output s3 + s3_enable = false + s3_output = "icecast" + s3_host = "localhost" + s3_port = 8000 + s3_mount = "" + s3_user = "source" + s3_pass = "" + + s3_channels = "stereo" + s3_type = "ogg" + s3_bitrate = 256 + + s3_name = "" + s3_description = "" + s3_genre = "" + s3_url = "" + + # Output s4 + s4_enable = false + s4_output = "icecast" + s4_host = "localhost" + s4_port = 8000 + s4_mount = "" + s4_user = "source" + s4_pass = "" + + s4_channels = "stereo" + s4_type = "ogg" + s4_bitrate = 256 + + s4_name = "" + s4_description = "" + s4_genre = "" + s4_url = "" + + icecast_vorbis_metadata = false + + # System output + output_sound_device = false + output_sound_device_type = "alsa" + + # Settings + auth_path = "/fake/liquidsoap_auth.py" + + set("log.file.path", "/var/log/radio.log") + + set("server.telnet", true) + set("server.telnet.bind_addr", "127.0.0.1") + set("server.telnet.port", 1234) + + set("harbor.bind_addrs", ["0.0.0.0"]) + + station_name = interactive.string("station_name", "LibreTime") + + message_offline = interactive.string("message_offline", "LibreTime - offline") + message_format = interactive.string("message_format", "0") + input_fade_transition = interactive.float("input_fade_transition", 0.0) + + %include "/fake/1.4/ls_script.liq" + + ''' +# --- diff --git a/playout/tests/liquidsoap/entrypoint_test.py b/playout/tests/liquidsoap/entrypoint_test.py index 3d16b1b2d..d0683523b 100644 --- a/playout/tests/liquidsoap/entrypoint_test.py +++ b/playout/tests/liquidsoap/entrypoint_test.py @@ -7,12 +7,18 @@ from libretime_playout.config import Config from libretime_playout.liquidsoap.entrypoint import generate_entrypoint from libretime_playout.liquidsoap.models import Info, StreamPreferences +from .fixtures import TEST_STREAM_CONFIGS + @pytest.mark.parametrize( "version", [pytest.param((1, 4, 4), id="1.4")], ) -def test_generate_entrypoint(tmp_path: Path, config: Config, version, snapshot): +@pytest.mark.parametrize( + "stream_config", + TEST_STREAM_CONFIGS, +) +def test_generate_entrypoint(tmp_path: Path, stream_config: Config, version, snapshot): entrypoint_filepath = tmp_path / "radio.liq" with mock.patch( @@ -22,7 +28,7 @@ def test_generate_entrypoint(tmp_path: Path, config: Config, version, snapshot): generate_entrypoint( entrypoint_filepath, log_filepath=Path("/var/log/radio.log"), - config=config, + config=stream_config, preferences=StreamPreferences( input_fade_transition=0.0, message_format=0, diff --git a/playout/tests/liquidsoap/fixtures/__init__.py b/playout/tests/liquidsoap/fixtures/__init__.py new file mode 100644 index 000000000..407feb418 --- /dev/null +++ b/playout/tests/liquidsoap/fixtures/__init__.py @@ -0,0 +1,86 @@ +from typing import List + +from libretime_playout.config import Config + + +def make_config_with_stream(**kwargs) -> Config: + return Config( + **{ + "general": { + "public_url": "http://localhost:8080", + "api_key": "some_api_key", + }, + "stream": kwargs, + } + ) + + +TEST_STREAM_CONFIGS: List[Config] = [ + make_config_with_stream(), + make_config_with_stream( + outputs={ + "icecast": [ + { + "enabled": True, + "mount": "main", + "source_password": "hackme", + "audio": {"format": "ogg", "bitrate": 256}, + "name": "LibreTime!", + "description": "LibreTime Radio! Stream #1", + "website": "https://libretime.org", + "genre": "various", + }, + { + "enabled": False, + "mount": "second", + "source_password": "hackme", + "audio": {"format": "mp3", "bitrate": 256}, + }, + ], + } + ), + make_config_with_stream( + outputs={ + "shoutcast": [ + { + "enabled": True, + "source_password": "hackme", + "audio": {"format": "mp3", "bitrate": 256}, + "name": "LibreTime!", + "description": "LibreTime Radio! Stream #1", + "website": "https://libretime.org", + "genre": "various", + }, + ], + } + ), + make_config_with_stream( + outputs={ + "icecast": [ + { + "enabled": True, + "mount": "main", + "source_password": "hackme", + "audio": {"format": "ogg", "bitrate": 256}, + }, + ], + "shoutcast": [ + { + "enabled": True, + "source_password": "hackme", + "audio": {"format": "mp3", "bitrate": 256}, + }, + ], + } + ), + make_config_with_stream( + outputs={ + "system": [{"enabled": True, "kind": "pulseaudio"}], + } + ), + make_config_with_stream( + outputs={ + "system": [{"enabled": False, "kind": "alsa"}], + } + ), +]