|
11 | 11 | from awesomeversion import AwesomeVersion |
12 | 12 | import pytest |
13 | 13 |
|
14 | | -from go2rtc_client.exceptions import Go2RtcVersionError |
15 | | -from go2rtc_client.models import WebRTCSdpOffer |
| 14 | +from go2rtc_client.exceptions import Go2RtcClientError, Go2RtcVersionError |
| 15 | +from go2rtc_client.models import Stream, WebRTCSdpOffer |
16 | 16 | from go2rtc_client.rest import _ApplicationClient, _StreamClient, _WebRTCClient |
17 | 17 | from tests import load_fixture |
18 | 18 |
|
@@ -146,3 +146,74 @@ async def test_webrtc_offer( |
146 | 146 | WebRTCSdpOffer("v=0..."), |
147 | 147 | ) |
148 | 148 | assert resp == snapshot |
| 149 | + |
| 150 | + |
| 151 | +async def _test_probe( |
| 152 | + responses: aioresponses, |
| 153 | + rest_client: Go2RtcRestClient, |
| 154 | + filename: str, |
| 155 | + status_code: int, |
| 156 | + additional_params: dict[str, str], |
| 157 | +) -> Stream: |
| 158 | + """Test probing a stream.""" |
| 159 | + camera = "camera.test" |
| 160 | + params = [f"{k}={v}" for k, v in additional_params.items()] |
| 161 | + responses.get( |
| 162 | + f"{URL}{_StreamClient.PATH}?src={camera}&{'&'.join(params)}", |
| 163 | + status=status_code, |
| 164 | + body=load_fixture(filename), |
| 165 | + ) |
| 166 | + return await rest_client.streams.probe(camera, **additional_params) |
| 167 | + |
| 168 | + |
| 169 | +@pytest.mark.parametrize( |
| 170 | + "additional_params", |
| 171 | + [ |
| 172 | + {"audio": "all", "video": "all"}, |
| 173 | + {"audio": "all"}, |
| 174 | + {"video": "all"}, |
| 175 | + ], |
| 176 | + ids=[ |
| 177 | + "audio and video", |
| 178 | + "audio only", |
| 179 | + "video only", |
| 180 | + ], |
| 181 | +) |
| 182 | +async def test_probe_success( |
| 183 | + responses: aioresponses, |
| 184 | + rest_client: Go2RtcRestClient, |
| 185 | + snapshot: SnapshotAssertion, |
| 186 | + additional_params: dict[str, str], |
| 187 | +) -> None: |
| 188 | + """Test probing a stream.""" |
| 189 | + resp = await _test_probe( |
| 190 | + responses, rest_client, "probe_success.json", 200, additional_params |
| 191 | + ) |
| 192 | + assert resp == snapshot(name="deserialized") |
| 193 | + assert isinstance(resp, Stream) |
| 194 | + assert resp.to_json() == snapshot(name="serialized") |
| 195 | + |
| 196 | + |
| 197 | +@pytest.mark.parametrize( |
| 198 | + "additional_params", |
| 199 | + [ |
| 200 | + {"audio": "all", "video": "all"}, |
| 201 | + {"audio": "all"}, |
| 202 | + {"video": "all"}, |
| 203 | + ], |
| 204 | + ids=[ |
| 205 | + "audio and video", |
| 206 | + "audio only", |
| 207 | + "video only", |
| 208 | + ], |
| 209 | +) |
| 210 | +async def test_probe_camera_offline( |
| 211 | + responses: aioresponses, |
| 212 | + rest_client: Go2RtcRestClient, |
| 213 | + additional_params: dict[str, str], |
| 214 | +) -> None: |
| 215 | + """Test probing a stream, where the camera is offline.""" |
| 216 | + with pytest.raises(Go2RtcClientError): |
| 217 | + await _test_probe( |
| 218 | + responses, rest_client, "probe_camera_offline.txt", 500, additional_params |
| 219 | + ) |
0 commit comments