annotate tests/unit/test_plugin_calls.py @ 504:fe0bdc476576

install: update `plyer` version
author Goffi <goffi@goffi.org>
date Wed, 25 Oct 2023 15:22:19 +0200
parents b0f70be331c5
children f6b8300e8234
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
500
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from unittest.mock import AsyncMock, MagicMock
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from gi.repository import Gst
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from libervia.backend.core import exceptions
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from libervia.backend.tools.common import data_format
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import pytest
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from libervia.desktop_kivy import G
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from libervia.desktop_kivy.plugins import plugin_wid_calls
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 @pytest.fixture
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def host(monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 host = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 host.a_bridge = AsyncMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 monkeypatch.setattr(G, "_host", host, raising=False)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 return host
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 @pytest.fixture(scope="function")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def webrtc():
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 """Fixture for WebRTC instantiation."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 host_mock = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 profile = "test_profile"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 instance = plugin_wid_calls.WebRTC(host_mock, profile)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 instance._set_media_types = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 instance.start_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 instance.webrtc = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 instance.webrtc.emit = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 instance.GstSdp_SDPMessage_new_from_text = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 instance.GstWebRTC_WebRTCSessionDescription_new = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 instance.Gst_Promise_new_with_change_func = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 return instance
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 class TestWebRtc:
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def test_get_payload_types(self, webrtc):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 """The method can identify the correct payload types for video and audio."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 fake_sdpmsg = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 fake_media = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 fake_caps = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 fake_structure = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 # This side effect will return 'fake_video_encoding' first, then
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 # 'fake_audio_encoding'.
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 fake_structure.__getitem__.side_effect = [
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 "fake_video_encoding",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 "fake_audio_encoding",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 ]
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 fake_caps.get_structure.return_value = fake_structure
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 fake_media.get_format.side_effect = ["webrtc-datachannel", "10", "20"]
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 fake_media.get_caps_from_media.return_value = fake_caps
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 fake_sdpmsg.get_media.return_value = fake_media
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 fake_sdpmsg.medias_len.return_value = 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 fake_media.formats_len.return_value = 3
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 result = webrtc.get_payload_types(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 fake_sdpmsg, "fake_video_encoding", "fake_audio_encoding"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 expected_result = {"fake_video_encoding": 10, "fake_audio_encoding": 20}
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 assert result == expected_result
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
84
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 def test_on_accepted_call(self, webrtc):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 """The method correctly sets the remote SDP upon acceptance of an outgoing call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 sdp_str = "mock_sdp_string"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 profile_str = "test_profile"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 webrtc.on_accepted_call(sdp_str, profile_str)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
91
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 # remote description must be set
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 assert webrtc.webrtc.emit.call_count == 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 assert webrtc.webrtc.emit.call_args[0][0] == "set-remote-description"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 async def test_answer_call(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 """The method correctly answers an incoming call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 mock_setup_call = AsyncMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 def mock_get_payload_types(sdpmsg, video_encoding, audio_encoding):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 return {"VP8": 96, "OPUS": 97}
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 monkeypatch.setattr(webrtc, "setup_call", mock_setup_call)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 monkeypatch.setattr(webrtc, "get_payload_types", mock_get_payload_types)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 sdp_str = "mock_sdp_string"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 profile_str = "mock_profile"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 await webrtc.answer_call(sdp_str, profile_str)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 mock_setup_call.assert_called_once_with("responder", audio_pt=97, video_pt=96)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
113
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 # remote description must be set
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 assert webrtc.webrtc.emit.call_count == 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 assert webrtc.webrtc.emit.call_args[0][0] == "set-remote-description"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def test_on_remote_decodebin_stream_video(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 """The method correctly handles video streams from the remote decodebin."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 mock_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 monkeypatch.setattr(webrtc, "pipeline", mock_pipeline)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
122
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 mock_pad = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 mock_caps = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 mock_structure = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 mock_pad.has_current_caps.return_value = True
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 mock_pad.get_current_caps.return_value = mock_caps
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 mock_caps.__len__.return_value = 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 mock_caps.__getitem__.return_value = mock_structure
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 mock_structure.get_name.return_value = "video/x-h264"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 # We use non-standard resolution as example to trigger the workaround
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 mock_structure.get_int.side_effect = lambda x: MagicMock(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 value=990 if x == "width" else 557
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 webrtc.on_remote_decodebin_stream(None, mock_pad)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
138
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 assert webrtc._remote_video_pad == mock_pad
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 mock_pipeline.add.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 mock_pipeline.set_state.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 mock_pad.link.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
143
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def test_on_remote_decodebin_stream_audio(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 """The method correctly handles audio streams from the remote decodebin."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 mock_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 monkeypatch.setattr(webrtc, "pipeline", mock_pipeline)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 mock_pad = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 mock_caps = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 mock_structure = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 mock_pad.has_current_caps.return_value = True
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 mock_pad.get_current_caps.return_value = mock_caps
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 mock_caps.__len__.return_value = 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 mock_caps.__getitem__.return_value = mock_structure
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 mock_structure.get_name.return_value = "audio/x-raw"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
158
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 webrtc.on_remote_decodebin_stream(None, mock_pad)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
160
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 mock_pipeline.add.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 mock_pipeline.set_state.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 mock_pad.link.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 async def test_setup_call_correct_role(self, host, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 """Roles are set in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 monkeypatch.setattr(Gst, "parse_launch", MagicMock())
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 assert webrtc.role == "initiator"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
173
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 await webrtc.setup_call("responder")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 assert webrtc.role == "responder"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
176
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 with pytest.raises(AssertionError):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 await webrtc.setup_call("invalid_role")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
179
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 async def test_setup_call_test_mode(self, host, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 """Test mode use fake video and audio in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 monkeypatch.setattr(webrtc, "test_mode", True)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 assert "videotestsrc" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 assert "audiotestsrc" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
188
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 async def test_setup_call_normal_mode(self, host, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 """Normal mode use real video and audio in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 monkeypatch.setattr(webrtc, "test_mode", False)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 assert "v4l2src" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 assert "pulsesrc" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 async def test_setup_call_with_stun_and_turn(self, host, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 """STUN and TURN server configurations are done in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 mock_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 mock_parse_launch = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 mock_parse_launch.return_value = mock_pipeline
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 monkeypatch.setattr(Gst, "parse_launch", mock_parse_launch)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
205
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 mock_pipeline.get_by_name.return_value = webrtc.webrtc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
207
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 mock_external_disco = [
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 {"type": "stun", "transport": "udp", "host": "stun.host", "port": "3478"},
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 {
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 "type": "turn",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 "transport": "udp",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 "host": "turn.host",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 "port": "3478",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 "username": "user",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 "password": "pass",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 },
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 ]
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
219
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 monkeypatch.setattr(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 data_format, "deserialise", MagicMock(return_value=mock_external_disco)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
223
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 mock_emit = AsyncMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 monkeypatch.setattr(webrtc.webrtc, "emit", mock_emit)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
226
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 mock_set_property = AsyncMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 monkeypatch.setattr(webrtc.webrtc, "set_property", mock_set_property)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
229
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
231
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 G.host.a_bridge.external_disco_get.assert_called_once_with("", webrtc.profile)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 mock_set_property.assert_any_call("stun-server", "stun://stun.host:3478")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 mock_emit.assert_called_once_with(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 "add-turn-server", "turn://user:pass@turn.host:3478"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
237
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 async def test_setup_call_gstreamer_pipeline_failure(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 """Test setup_call method handling Gstreamer pipeline failure."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 monkeypatch.setattr(Gst, "parse_launch", lambda _: None)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 with pytest.raises(exceptions.InternalError):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 await webrtc.setup_call("initiator")