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
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()
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
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 monkeypatch.setattr(G, "_host", host, raising=False)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 return host
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
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 @pytest.fixture(scope="function")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def webrtc():
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """Fixture for WebRTC instantiation."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 host_mock = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 profile = "test_profile"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 instance = plugin_wid_calls.WebRTC(host_mock, profile)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 instance._set_media_types = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 instance.start_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 instance.webrtc = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 instance.webrtc.emit = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 instance.GstSdp_SDPMessage_new_from_text = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 instance.GstWebRTC_WebRTCSessionDescription_new = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 instance.Gst_Promise_new_with_change_func = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 return instance
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
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
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 class TestWebRtc:
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def test_get_payload_types(self, webrtc):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 """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
86 fake_sdpmsg = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 fake_media = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 fake_caps = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 fake_structure = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 # This side effect will return 'fake_video_encoding' first, then
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 # 'fake_audio_encoding'.
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 fake_structure.__getitem__.side_effect = [
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 "fake_video_encoding",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 "fake_audio_encoding",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 ]
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 fake_caps.get_structure.return_value = fake_structure
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 fake_media.get_format.side_effect = ["webrtc-datachannel", "10", "20"]
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 fake_media.get_caps_from_media.return_value = fake_caps
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 fake_sdpmsg.get_media.return_value = fake_media
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 fake_sdpmsg.medias_len.return_value = 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 fake_media.formats_len.return_value = 3
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 result = webrtc.get_payload_types(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 fake_sdpmsg, "fake_video_encoding", "fake_audio_encoding"
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 expected_result = {"fake_video_encoding": 10, "fake_audio_encoding": 20}
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 assert result == expected_result
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def test_on_accepted_call(self, webrtc):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 """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
113 sdp_str = "mock_sdp_string"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 profile_str = "test_profile"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 webrtc.on_accepted_call(sdp_str, profile_str)
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 # remote description must be set
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 assert webrtc.webrtc.emit.call_count == 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 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
121
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 async def test_answer_call(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 """The method correctly answers an incoming call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 mock_setup_call = AsyncMock()
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 def mock_get_payload_types(sdpmsg, video_encoding, audio_encoding):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 return {"VP8": 96, "OPUS": 97}
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
129
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 monkeypatch.setattr(webrtc, "setup_call", mock_setup_call)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 monkeypatch.setattr(webrtc, "get_payload_types", mock_get_payload_types)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 sdp_str = "mock_sdp_string"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 profile_str = "mock_profile"
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 await webrtc.answer_call(sdp_str, profile_str)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
137
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 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
139
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 # remote description must be set
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 assert webrtc.webrtc.emit.call_count == 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 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
143
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def test_on_remote_decodebin_stream_video(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 """The method correctly handles video 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 = "video/x-h264"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 # 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
159 mock_structure.get_int.side_effect = lambda x: MagicMock(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 value=990 if x == "width" else 557
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
162
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 webrtc.on_remote_decodebin_stream(None, mock_pad)
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 assert webrtc._remote_video_pad == mock_pad
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 mock_pipeline.add.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 mock_pipeline.set_state.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 mock_pad.link.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
169
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 def test_on_remote_decodebin_stream_audio(self, webrtc, monkeypatch):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 """The method correctly handles audio streams from the remote decodebin."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 mock_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 monkeypatch.setattr(webrtc, "pipeline", mock_pipeline)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
174
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 mock_pad = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 mock_caps = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 mock_structure = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
178
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 mock_pad.has_current_caps.return_value = True
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 mock_pad.get_current_caps.return_value = mock_caps
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 mock_caps.__len__.return_value = 1
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 mock_caps.__getitem__.return_value = mock_structure
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 mock_structure.get_name.return_value = "audio/x-raw"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 webrtc.on_remote_decodebin_stream(None, mock_pad)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 mock_pipeline.add.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 mock_pipeline.set_state.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 mock_pad.link.assert_called()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
190
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 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
193 """Roles are set in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 monkeypatch.setattr(Gst, "parse_launch", MagicMock())
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 assert webrtc.role == "initiator"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
199
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 await webrtc.setup_call("responder")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 assert webrtc.role == "responder"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
202
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 with pytest.raises(AssertionError):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 await webrtc.setup_call("invalid_role")
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 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 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
208 """Test mode use fake video and audio in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 monkeypatch.setattr(webrtc, "test_mode", True)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 assert "videotestsrc" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 assert "audiotestsrc" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
214
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 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
217 """Normal mode use real video and audio in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 monkeypatch.setattr(data_format, "deserialise", MagicMock(return_value=[]))
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 monkeypatch.setattr(webrtc, "test_mode", False)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 assert "v4l2src" in webrtc.gst_pipe_desc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 assert "pulsesrc" in webrtc.gst_pipe_desc
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 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 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
226 """STUN and TURN server configurations are done in setup_call."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 mock_pipeline = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 mock_parse_launch = MagicMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 mock_parse_launch.return_value = mock_pipeline
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 monkeypatch.setattr(Gst, "parse_launch", mock_parse_launch)
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 mock_pipeline.get_by_name.return_value = webrtc.webrtc
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
233
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 mock_external_disco = [
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 {"type": "stun", "transport": "udp", "host": "stun.host", "port": "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 "type": "turn",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 "transport": "udp",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 "host": "turn.host",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 "port": "3478",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 "username": "user",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 "password": "pass",
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 },
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 ]
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
245
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 monkeypatch.setattr(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 data_format, "deserialise", MagicMock(return_value=mock_external_disco)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
249
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 mock_emit = AsyncMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 monkeypatch.setattr(webrtc.webrtc, "emit", mock_emit)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
252
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 mock_set_property = AsyncMock()
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 monkeypatch.setattr(webrtc.webrtc, "set_property", mock_set_property)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
255
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 await webrtc.setup_call("initiator")
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
257
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 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
259 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
260 mock_emit.assert_called_once_with(
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 "add-turn-server", "turn://user:pass@turn.host:3478"
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 )
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
263
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 @pytest.mark.asyncio
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 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
266 """Test setup_call method handling Gstreamer pipeline failure."""
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 monkeypatch.setattr(Gst, "parse_launch", lambda _: None)
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 with pytest.raises(exceptions.InternalError):
b0f70be331c5 tests: unit test for "Calls" plugins:
Goffi <goffi@goffi.org>
parents:
diff changeset
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()