Mercurial > libervia-desktop-kivy
annotate tests/unit/test_plugin_calls.py @ 507:f6b8300e8234
tests (calls): add tests for the "Calls" class:
rel 425
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Oct 2023 15:29:12 +0200 |
parents | b0f70be331c5 |
children | f0ce49b360c8 |
rev | line source |
---|---|
500 | 1 #!/usr/bin/env python3 |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
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/>. | |
18 | |
19 from unittest.mock import AsyncMock, MagicMock | |
20 | |
21 from gi.repository import Gst | |
22 from libervia.backend.core import exceptions | |
23 from libervia.backend.tools.common import data_format | |
24 import pytest | |
25 | |
26 from libervia.desktop_kivy import G | |
27 from libervia.desktop_kivy.plugins import plugin_wid_calls | |
28 | |
29 | |
30 @pytest.fixture | |
31 def host(monkeypatch): | |
32 host = MagicMock() | |
33 host.a_bridge = AsyncMock() | |
507
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
34 host.app.expand = lambda s: s |
500 | 35 monkeypatch.setattr(G, "_host", host, raising=False) |
36 return host | |
37 | |
38 | |
39 @pytest.fixture(scope="function") | |
40 def webrtc(): | |
41 """Fixture for WebRTC instantiation.""" | |
42 host_mock = MagicMock() | |
43 profile = "test_profile" | |
44 instance = plugin_wid_calls.WebRTC(host_mock, profile) | |
45 | |
46 instance._set_media_types = MagicMock() | |
47 instance.start_pipeline = MagicMock() | |
48 instance.webrtc = MagicMock() | |
49 instance.webrtc.emit = MagicMock() | |
50 | |
51 instance.GstSdp_SDPMessage_new_from_text = MagicMock() | |
52 instance.GstWebRTC_WebRTCSessionDescription_new = MagicMock() | |
53 instance.Gst_Promise_new_with_change_func = MagicMock() | |
54 | |
55 return instance | |
56 | |
57 | |
507
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
58 @pytest.fixture |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
59 def calls(monkeypatch, host): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
60 """Fixture for Call UI instantiation.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
61 for attr in ("header_box", "local_video", "remote_video", "screen_manager"): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
62 monkeypatch.setattr( |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
63 plugin_wid_calls.Calls, |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
64 attr, |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
65 MagicMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
66 ) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
67 calls = plugin_wid_calls.Calls( |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
68 host, |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
69 "test_peer@example.org", |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
70 ["test_profile"] |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
71 ) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
72 calls.jid_selector = MagicMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
73 calls.header_input = MagicMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
74 calls.header_input.text = "fake_jid@domain" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
75 calls.webrtc = MagicMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
76 calls.webrtc.setup_call = AsyncMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
77 calls.webrtc.start_pipeline = MagicMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
78 calls.end_call = AsyncMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
79 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
80 return calls |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
81 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
82 |
500 | 83 class TestWebRtc: |
84 def test_get_payload_types(self, webrtc): | |
85 """The method can identify the correct payload types for video and audio.""" | |
86 fake_sdpmsg = MagicMock() | |
87 fake_media = MagicMock() | |
88 fake_caps = MagicMock() | |
89 fake_structure = MagicMock() | |
90 | |
91 # This side effect will return 'fake_video_encoding' first, then | |
92 # 'fake_audio_encoding'. | |
93 fake_structure.__getitem__.side_effect = [ | |
94 "fake_video_encoding", | |
95 "fake_audio_encoding", | |
96 ] | |
97 fake_caps.get_structure.return_value = fake_structure | |
98 fake_media.get_format.side_effect = ["webrtc-datachannel", "10", "20"] | |
99 fake_media.get_caps_from_media.return_value = fake_caps | |
100 fake_sdpmsg.get_media.return_value = fake_media | |
101 fake_sdpmsg.medias_len.return_value = 1 | |
102 fake_media.formats_len.return_value = 3 | |
103 | |
104 result = webrtc.get_payload_types( | |
105 fake_sdpmsg, "fake_video_encoding", "fake_audio_encoding" | |
106 ) | |
107 expected_result = {"fake_video_encoding": 10, "fake_audio_encoding": 20} | |
108 | |
109 assert result == expected_result | |
110 | |
111 def test_on_accepted_call(self, webrtc): | |
112 """The method correctly sets the remote SDP upon acceptance of an outgoing call.""" | |
113 sdp_str = "mock_sdp_string" | |
114 profile_str = "test_profile" | |
115 | |
116 webrtc.on_accepted_call(sdp_str, profile_str) | |
117 | |
118 # remote description must be set | |
119 assert webrtc.webrtc.emit.call_count == 1 | |
120 assert webrtc.webrtc.emit.call_args[0][0] == "set-remote-description" | |
121 | |
122 @pytest.mark.asyncio | |
123 async def test_answer_call(self, webrtc, monkeypatch): | |
124 """The method correctly answers an incoming call.""" | |
125 mock_setup_call = AsyncMock() | |
126 | |
127 def mock_get_payload_types(sdpmsg, video_encoding, audio_encoding): | |
128 return {"VP8": 96, "OPUS": 97} | |
129 | |
130 monkeypatch.setattr(webrtc, "setup_call", mock_setup_call) | |
131 monkeypatch.setattr(webrtc, "get_payload_types", mock_get_payload_types) | |
132 | |
133 sdp_str = "mock_sdp_string" | |
134 profile_str = "mock_profile" | |
135 | |
136 await webrtc.answer_call(sdp_str, profile_str) | |
137 | |
138 mock_setup_call.assert_called_once_with("responder", audio_pt=97, video_pt=96) | |
139 | |
140 # remote description must be set | |
141 assert webrtc.webrtc.emit.call_count == 1 | |
142 assert webrtc.webrtc.emit.call_args[0][0] == "set-remote-description" | |
143 | |
144 def test_on_remote_decodebin_stream_video(self, webrtc, monkeypatch): | |
145 """The method correctly handles video streams from the remote decodebin.""" | |
146 mock_pipeline = MagicMock() | |
147 monkeypatch.setattr(webrtc, "pipeline", mock_pipeline) | |
148 | |
149 mock_pad = MagicMock() | |
150 mock_caps = MagicMock() | |
151 mock_structure = MagicMock() | |
152 | |
153 mock_pad.has_current_caps.return_value = True | |
154 mock_pad.get_current_caps.return_value = mock_caps | |
155 mock_caps.__len__.return_value = 1 | |
156 mock_caps.__getitem__.return_value = mock_structure | |
157 mock_structure.get_name.return_value = "video/x-h264" | |
158 # We use non-standard resolution as example to trigger the workaround | |
159 mock_structure.get_int.side_effect = lambda x: MagicMock( | |
160 value=990 if x == "width" else 557 | |
161 ) | |
162 | |
163 webrtc.on_remote_decodebin_stream(None, mock_pad) | |
164 | |
165 assert webrtc._remote_video_pad == mock_pad | |
166 mock_pipeline.add.assert_called() | |
167 mock_pipeline.set_state.assert_called() | |
168 mock_pad.link.assert_called() | |
169 | |
170 def test_on_remote_decodebin_stream_audio(self, webrtc, monkeypatch): | |
171 """The method correctly handles audio streams from the remote decodebin.""" | |
172 mock_pipeline = MagicMock() | |
173 monkeypatch.setattr(webrtc, "pipeline", mock_pipeline) | |
174 | |
175 mock_pad = MagicMock() | |
176 mock_caps = MagicMock() | |
177 mock_structure = MagicMock() | |
178 | |
179 mock_pad.has_current_caps.return_value = True | |
180 mock_pad.get_current_caps.return_value = mock_caps | |
181 mock_caps.__len__.return_value = 1 | |
182 mock_caps.__getitem__.return_value = mock_structure | |
183 mock_structure.get_name.return_value = "audio/x-raw" | |
184 | |
185 webrtc.on_remote_decodebin_stream(None, mock_pad) | |
186 | |
187 mock_pipeline.add.assert_called() | |
188 mock_pipeline.set_state.assert_called() | |
189 mock_pad.link.assert_called() | |
190 | |
191 @pytest.mark.asyncio | |
192 async def test_setup_call_correct_role(self, host, webrtc, monkeypatch): | |
193 """Roles are set in setup_call.""" | |
194 monkeypatch.setattr(Gst, "parse_launch", MagicMock()) | |
195 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[])) | |
196 | |
197 await webrtc.setup_call("initiator") | |
198 assert webrtc.role == "initiator" | |
199 | |
200 await webrtc.setup_call("responder") | |
201 assert webrtc.role == "responder" | |
202 | |
203 with pytest.raises(AssertionError): | |
204 await webrtc.setup_call("invalid_role") | |
205 | |
206 @pytest.mark.asyncio | |
207 async def test_setup_call_test_mode(self, host, webrtc, monkeypatch): | |
208 """Test mode use fake video and audio in setup_call.""" | |
209 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[])) | |
210 monkeypatch.setattr(webrtc, "test_mode", True) | |
211 await webrtc.setup_call("initiator") | |
212 assert "videotestsrc" in webrtc.gst_pipe_desc | |
213 assert "audiotestsrc" in webrtc.gst_pipe_desc | |
214 | |
215 @pytest.mark.asyncio | |
216 async def test_setup_call_normal_mode(self, host, webrtc, monkeypatch): | |
217 """Normal mode use real video and audio in setup_call.""" | |
218 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[])) | |
219 monkeypatch.setattr(webrtc, "test_mode", False) | |
220 await webrtc.setup_call("initiator") | |
221 assert "v4l2src" in webrtc.gst_pipe_desc | |
222 assert "pulsesrc" in webrtc.gst_pipe_desc | |
223 | |
224 @pytest.mark.asyncio | |
225 async def test_setup_call_with_stun_and_turn(self, host, webrtc, monkeypatch): | |
226 """STUN and TURN server configurations are done in setup_call.""" | |
227 mock_pipeline = MagicMock() | |
228 mock_parse_launch = MagicMock() | |
229 mock_parse_launch.return_value = mock_pipeline | |
230 monkeypatch.setattr(Gst, "parse_launch", mock_parse_launch) | |
231 | |
232 mock_pipeline.get_by_name.return_value = webrtc.webrtc | |
233 | |
234 mock_external_disco = [ | |
235 {"type": "stun", "transport": "udp", "host": "stun.host", "port": "3478"}, | |
236 { | |
237 "type": "turn", | |
238 "transport": "udp", | |
239 "host": "turn.host", | |
240 "port": "3478", | |
241 "username": "user", | |
242 "password": "pass", | |
243 }, | |
244 ] | |
245 | |
246 monkeypatch.setattr( | |
247 data_format, "deserialise", MagicMock(return_value=mock_external_disco) | |
248 ) | |
249 | |
250 mock_emit = AsyncMock() | |
251 monkeypatch.setattr(webrtc.webrtc, "emit", mock_emit) | |
252 | |
253 mock_set_property = AsyncMock() | |
254 monkeypatch.setattr(webrtc.webrtc, "set_property", mock_set_property) | |
255 | |
256 await webrtc.setup_call("initiator") | |
257 | |
258 G.host.a_bridge.external_disco_get.assert_called_once_with("", webrtc.profile) | |
259 mock_set_property.assert_any_call("stun-server", "stun://stun.host:3478") | |
260 mock_emit.assert_called_once_with( | |
261 "add-turn-server", "turn://user:pass@turn.host:3478" | |
262 ) | |
263 | |
264 @pytest.mark.asyncio | |
265 async def test_setup_call_gstreamer_pipeline_failure(self, webrtc, monkeypatch): | |
266 """Test setup_call method handling Gstreamer pipeline failure.""" | |
267 monkeypatch.setattr(Gst, "parse_launch", lambda _: None) | |
268 with pytest.raises(exceptions.InternalError): | |
269 await webrtc.setup_call("initiator") | |
507
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
270 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
271 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
272 class TestCalls: |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
273 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
274 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
275 async def test_toggle_call_sid_none(self, monkeypatch, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
276 """Call is started when there is not sid set.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
277 monkeypatch.setattr(calls.webrtc, "sid", None) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
278 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
279 await calls.toggle_call() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
280 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
281 calls.webrtc.setup_call.assert_called_once_with("initiator") |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
282 calls.webrtc.start_pipeline.assert_called_once() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
283 assert calls.in_call == True |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
284 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
285 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
286 async def test_toggle_call_sid_set(self, monkeypatch, host, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
287 """Call is ended when a sid is set""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
288 monkeypatch.setattr(calls.webrtc, "sid", "test_sid") |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
289 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
290 await calls.toggle_call() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
291 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
292 calls.end_call.assert_called_once_with({"reason": "terminated"}, calls.profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
293 host.a_bridge.call_end.assert_called_once_with("test_sid", "", calls.profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
294 assert calls.in_call == False |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
295 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
296 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
297 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
298 async def test_on_incoming_call_sid_none(self, monkeypatch, host, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
299 """Incoming call is accepted if no ongoing call.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
300 monkeypatch.setattr(calls.webrtc, "sid", None) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
301 fake_action_id = "fake_action_id" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
302 fake_action_data = {"session_id": "test_sid"} |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
303 fake_profile = "fake_profile" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
304 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
305 await calls.on_incoming_call(fake_action_data, fake_action_id, fake_profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
306 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
307 assert calls.in_call == True |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
308 assert calls.webrtc.sid == "test_sid" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
309 host.a_bridge.action_launch.assert_called_once_with( |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
310 fake_action_id, |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
311 data_format.serialise({"cancelled": False}), |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
312 fake_profile |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
313 ) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
314 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
315 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
316 async def test_on_incoming_call_sid_set(self, monkeypatch, host, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
317 """Incoming call is ignored if there's an ongoing call.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
318 monkeypatch.setattr(calls.webrtc, "sid", "fake_old_sid") |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
319 fake_action_id = "fake_action_id" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
320 fake_action_data = {"session_id": "test_sid_new"} |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
321 fake_profile = "fake_profile" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
322 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
323 await calls.on_incoming_call(fake_action_data, fake_action_id, fake_profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
324 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
325 # Ensuring the state hasn't been changed to True |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
326 assert calls.in_call == False |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
327 host.a_bridge.action_launch.assert_not_called() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
328 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
329 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
330 async def test_on_call_setup_initiator(self, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
331 """Correct method called if role is 'initiator'.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
332 setup_data = { |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
333 "role": "initiator", |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
334 "sdp": "fake_sdp" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
335 } |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
336 profile = "fake_profile" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
337 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
338 await calls.on_call_setup(setup_data, profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
339 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
340 calls.webrtc.on_accepted_call.assert_called_once_with(setup_data["sdp"], profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
341 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
342 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
343 async def test_on_call_setup_responder(self, monkeypatch, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
344 """Correct method called if role is 'responder'.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
345 monkeypatch.setattr( |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
346 calls.webrtc, |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
347 "answer_call", |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
348 AsyncMock() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
349 ) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
350 setup_data = { |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
351 "role": "responder", |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
352 "sdp": "fake_sdp" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
353 } |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
354 profile = "fake_profile" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
355 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
356 await calls.on_call_setup(setup_data, profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
357 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
358 calls.webrtc.answer_call.assert_called_once_with(setup_data["sdp"], profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
359 calls.webrtc.on_accepted_call.assert_not_called() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
360 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
361 @pytest.mark.asyncio |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
362 async def test_on_call_setup_invalid_role(self, calls): |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
363 """Nothing is called if role is neither 'initiator' nor 'responder'.""" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
364 setup_data = { |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
365 "role": "invalid_role", |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
366 "sdp": "fake_sdp" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
367 } |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
368 profile = "fake_profile" |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
369 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
370 await calls.on_call_setup(setup_data, profile) |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
371 |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
372 calls.webrtc.answer_call.assert_not_called() |
f6b8300e8234
tests (calls): add tests for the "Calls" class:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
373 calls.webrtc.on_accepted_call.assert_not_called() |