1616from go2rtc_client .rest import (
1717 _API_PREFIX ,
1818 _ApplicationClient ,
19+ _PreloadClient ,
1920 _SchemesClient ,
2021 _StreamClient ,
2122 _WebRTCClient ,
@@ -135,7 +136,7 @@ async def test_streams_add_str(
135136 )
136137
137138
138- VERSION_ERR = "server version '{}' not >= 1.9.12 and < 2.0.0"
139+ VERSION_ERR = "server version '{}' not >= 1.9.13 and < 2.0.0"
139140
140141
141142@pytest .mark .parametrize (
@@ -144,8 +145,8 @@ async def test_streams_add_str(
144145 ("0.0.0" , pytest .raises (Go2RtcVersionError , match = VERSION_ERR .format ("0.0.0" ))),
145146 ("1.9.5" , pytest .raises (Go2RtcVersionError , match = VERSION_ERR .format ("1.9.5" ))),
146147 ("1.9.6" , pytest .raises (Go2RtcVersionError , match = VERSION_ERR .format ("1.9.6" ))),
147- ("1.9.12" , does_not_raise ()),
148148 ("1.9.13" , does_not_raise ()),
149+ ("1.9.14" , does_not_raise ()),
149150 ("2.0.0" , pytest .raises (Go2RtcVersionError , match = VERSION_ERR .format ("2.0.0" ))),
150151 ("BLAH" , pytest .raises (Go2RtcVersionError , match = VERSION_ERR .format ("BLAH" ))),
151152 ],
@@ -237,3 +238,135 @@ async def test_schemes(
237238 )
238239 resp = await rest_client .schemes .list ()
239240 assert resp == snapshot
241+
242+
243+ @pytest .mark .parametrize (
244+ "filename" ,
245+ ["preload_list_one.json" , "streams_none.json" ],
246+ ids = [
247+ "one stream preloaded" ,
248+ "no stream preloaded" ,
249+ ],
250+ )
251+ async def test_preload_list (
252+ responses : aioresponses ,
253+ rest_client : Go2RtcRestClient ,
254+ snapshot : SnapshotAssertion ,
255+ filename : str ,
256+ ) -> None :
257+ """Test preload list."""
258+ responses .get (
259+ f"{ URL } { _PreloadClient .PATH } " ,
260+ status = 200 ,
261+ body = load_fixture_str (filename ),
262+ )
263+ resp = await rest_client .preload .list ()
264+ assert resp == snapshot
265+
266+
267+ async def test_preload_enable_no_filters (
268+ responses : aioresponses ,
269+ rest_client : Go2RtcRestClient ,
270+ ) -> None :
271+ """Test enable preload without codec filters."""
272+ url = f"{ URL } { _PreloadClient .PATH } "
273+ camera = "camera.12mp_fluent"
274+ params = {"src" : camera }
275+ responses .put (url + f"?src={ camera } " , status = 200 )
276+ await rest_client .preload .enable (camera )
277+
278+ responses .assert_called_once_with (
279+ url , method = METH_PUT , params = params , timeout = ClientTimeout (total = 10 )
280+ )
281+
282+
283+ @pytest .mark .parametrize (
284+ (
285+ "video_codecs" ,
286+ "audio_codecs" ,
287+ "microphone_codecs" ,
288+ "query_string" ,
289+ "expected_params" ,
290+ ),
291+ [
292+ (
293+ ["h264" ],
294+ None ,
295+ None ,
296+ "?src=camera.12mp_fluent&video_codec_filter=h264" ,
297+ {"src" : "camera.12mp_fluent" , "video_codec_filter" : "h264" },
298+ ),
299+ (
300+ None ,
301+ ["opus" ],
302+ None ,
303+ "?src=camera.12mp_fluent&audio_codec_filter=opus" ,
304+ {"src" : "camera.12mp_fluent" , "audio_codec_filter" : "opus" },
305+ ),
306+ (
307+ None ,
308+ None ,
309+ ["pcmu" ],
310+ "?src=camera.12mp_fluentµphone_codec_filter=pcmu" ,
311+ {"src" : "camera.12mp_fluent" , "microphone_codec_filter" : "pcmu" },
312+ ),
313+ (
314+ ["h264" , "h265" ],
315+ ["opus" , "pcma" ],
316+ ["pcmu" ],
317+ "?src=camera.12mp_fluent&video_codec_filter=h264%2Ch265&audio_codec_filter=opus%2Cpcmaµphone_codec_filter=pcmu" ,
318+ {
319+ "src" : "camera.12mp_fluent" ,
320+ "video_codec_filter" : "h264,h265" ,
321+ "audio_codec_filter" : "opus,pcma" ,
322+ "microphone_codec_filter" : "pcmu" ,
323+ },
324+ ),
325+ ],
326+ ids = [
327+ "video filter only" ,
328+ "audio filter only" ,
329+ "microphone filter only" ,
330+ "all filters" ,
331+ ],
332+ )
333+ async def test_preload_enable_with_filters (
334+ responses : aioresponses ,
335+ rest_client : Go2RtcRestClient ,
336+ video_codecs : list [str ] | None ,
337+ audio_codecs : list [str ] | None ,
338+ microphone_codecs : list [str ] | None ,
339+ query_string : str ,
340+ expected_params : dict [str , str ],
341+ ) -> None :
342+ """Test enable preload with codec filters."""
343+ url = f"{ URL } { _PreloadClient .PATH } "
344+ camera = "camera.12mp_fluent"
345+
346+ responses .put (url + query_string , status = 200 )
347+ await rest_client .preload .enable (
348+ camera ,
349+ video_codec_filter = video_codecs ,
350+ audio_codec_filter = audio_codecs ,
351+ microphone_codec_filter = microphone_codecs ,
352+ )
353+
354+ responses .assert_called_once_with (
355+ url , method = METH_PUT , params = expected_params , timeout = ClientTimeout (total = 10 )
356+ )
357+
358+
359+ async def test_preload_disable (
360+ responses : aioresponses ,
361+ rest_client : Go2RtcRestClient ,
362+ ) -> None :
363+ """Test disable preload."""
364+ url = f"{ URL } { _PreloadClient .PATH } "
365+ camera = "camera.12mp_fluent"
366+ params = {"src" : camera }
367+ responses .delete (url + f"?src={ camera } " , status = 200 )
368+ await rest_client .preload .disable (camera )
369+
370+ responses .assert_called_once_with (
371+ url , method = "DELETE" , params = params , timeout = ClientTimeout (total = 10 )
372+ )
0 commit comments