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