comparison tests/unit/frontends/test_webrtc.py @ 4227:dfccc90cacc6

tests: fix and update tests: - update code to newer version of `sh` - update code to newer version of `selenium` - update names of OMEMO algorithms - fix paths and names used to mount source to the test container - skip modules using `Gst` and `PyQt` when they are not available.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:56 +0100
parents 13dd5660c28f
children 0fbe5c605eb6
comparison
equal deleted inserted replaced
4226:3f7ca590a5da 4227:dfccc90cacc6
15 15
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from unittest.mock import AsyncMock, MagicMock 18 from unittest.mock import AsyncMock, MagicMock
19 19
20 from gi.repository import Gst
21 import pytest 20 import pytest
21
22 try:
23 from gi.repository import Gst
24 except ImportError:
25 pytest.skip("Gst not available.", allow_module_level=True)
22 26
23 from libervia.backend.core import exceptions 27 from libervia.backend.core import exceptions
24 from libervia.backend.tools.common import data_format 28 from libervia.backend.tools.common import data_format
25 from libervia.frontends.tools import webrtc as webrtc_mod 29 from libervia.frontends.tools import webrtc as webrtc_mod
26 30
156 webrtc.on_remote_decodebin_stream(None, mock_pad) 160 webrtc.on_remote_decodebin_stream(None, mock_pad)
157 161
158 mock_pipeline.add.assert_called() 162 mock_pipeline.add.assert_called()
159 mock_pad.link.assert_called() 163 mock_pad.link.assert_called()
160 164
165 @pytest.mark.skipif(Gst is None)
161 @pytest.mark.asyncio 166 @pytest.mark.asyncio
162 async def test_setup_call_correct_role(self, host, webrtc, monkeypatch): 167 async def test_setup_call_correct_role(self, host, webrtc, monkeypatch):
163 """Roles are set in setup_call.""" 168 """Roles are set in setup_call."""
164 monkeypatch.setattr(Gst, "parse_launch", MagicMock()) 169 monkeypatch.setattr(Gst, "parse_launch", MagicMock())
165 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[])) 170 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
189 monkeypatch.setattr(webrtc, "sources", webrtc_mod.SOURCES_AUTO) 194 monkeypatch.setattr(webrtc, "sources", webrtc_mod.SOURCES_AUTO)
190 await webrtc.setup_call("initiator") 195 await webrtc.setup_call("initiator")
191 assert "v4l2src" in webrtc.gst_pipe_desc 196 assert "v4l2src" in webrtc.gst_pipe_desc
192 assert "pulsesrc" in webrtc.gst_pipe_desc 197 assert "pulsesrc" in webrtc.gst_pipe_desc
193 198
199 @pytest.mark.skipif(Gst is None)
194 @pytest.mark.asyncio 200 @pytest.mark.asyncio
195 async def test_setup_call_with_stun_and_turn(self, host, webrtc, monkeypatch): 201 async def test_setup_call_with_stun_and_turn(self, host, webrtc, monkeypatch):
196 """STUN and TURN server configurations are done in setup_call.""" 202 """STUN and TURN server configurations are done in setup_call."""
197 mock_pipeline = MagicMock() 203 mock_pipeline = MagicMock()
198 mock_parse_launch = MagicMock() 204 mock_parse_launch = MagicMock()
229 mock_set_property.assert_any_call("stun-server", "stun://stun.host:3478") 235 mock_set_property.assert_any_call("stun-server", "stun://stun.host:3478")
230 mock_emit.assert_called_once_with( 236 mock_emit.assert_called_once_with(
231 "add-turn-server", "turn://user:pass@turn.host:3478" 237 "add-turn-server", "turn://user:pass@turn.host:3478"
232 ) 238 )
233 239
240 @pytest.mark.skipif(Gst is None)
234 @pytest.mark.asyncio 241 @pytest.mark.asyncio
235 async def test_setup_call_gstreamer_pipeline_failure(self, webrtc, monkeypatch): 242 async def test_setup_call_gstreamer_pipeline_failure(self, webrtc, monkeypatch):
236 """Test setup_call method handling Gstreamer pipeline failure.""" 243 """Test setup_call method handling Gstreamer pipeline failure."""
237 monkeypatch.setattr(Gst, "parse_launch", lambda _: None) 244 monkeypatch.setattr(Gst, "parse_launch", lambda _: None)
238 with pytest.raises(exceptions.InternalError): 245 with pytest.raises(exceptions.InternalError):