Mercurial > libervia-backend
comparison tests/unit/cli/test_calls.py @ 4207:2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
rel 427
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 11 Feb 2024 23:21:07 +0100 |
parents | |
children | 716dd791be46 |
comparison
equal
deleted
inserted
replaced
4206:0f8ea0768a3b | 4207:2865e70b0b2c |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 from unittest.mock import MagicMock, patch | |
19 | |
20 from PyQt6.QtWidgets import QApplication | |
21 import pytest | |
22 | |
23 from libervia.cli.call_gui import AVCallGUI | |
24 from libervia.frontends.tools import display_servers | |
25 | |
26 | |
27 @pytest.fixture(scope="session") | |
28 def qapplication(): | |
29 # QApplication is needed to instantiate any QWidget | |
30 return QApplication([]) | |
31 | |
32 | |
33 @pytest.fixture | |
34 def av_call_gui(qapplication): | |
35 host = MagicMock() | |
36 icons_path = MagicMock() | |
37 gui = AVCallGUI(host, icons_path) | |
38 gui.webrtc_call = MagicMock() | |
39 return gui | |
40 | |
41 | |
42 def test_toggle_fullscreen(av_call_gui): | |
43 """``toggle_fullscreen`` changes window state.""" | |
44 initial_state = av_call_gui.isFullScreen() | |
45 av_call_gui.toggle_fullscreen() | |
46 assert av_call_gui.isFullScreen() != initial_state | |
47 | |
48 | |
49 def test_toggle_video(av_call_gui): | |
50 """``toggle_video`` actually toggles video state.""" | |
51 av_call_gui.webrtc_call.webrtc = MagicMock(video_muted=False) | |
52 av_call_gui.toggle_video() | |
53 assert av_call_gui.webrtc_call.webrtc.video_muted is True | |
54 | |
55 | |
56 def test_toggle_audio(av_call_gui): | |
57 """``toggle_audio`` actually toggles audio state.""" | |
58 av_call_gui.webrtc_call.webrtc = MagicMock(audio_muted=False) | |
59 av_call_gui.toggle_audio() | |
60 assert av_call_gui.webrtc_call.webrtc.audio_muted is True | |
61 | |
62 | |
63 def test_share_desktop(av_call_gui): | |
64 """``share_desktop`` changes WebRTC ``desktop_sharing`` state.""" | |
65 av_call_gui.webrtc_call.webrtc = MagicMock(desktop_sharing=False) | |
66 # We test WAYLAND as it is a direct change of ``desktop_sharing`` state. | |
67 with patch( | |
68 "libervia.cli.call_gui.display_servers.detect", | |
69 return_value=display_servers.WAYLAND, | |
70 ): | |
71 av_call_gui.share_desktop() | |
72 assert av_call_gui.webrtc_call.webrtc.desktop_sharing is True | |
73 | |
74 | |
75 def test_hang_up(av_call_gui): | |
76 """Hang-up button triggers window close.""" | |
77 with patch.object(av_call_gui, "close") as mock_close: | |
78 av_call_gui.hang_up() | |
79 mock_close.assert_called_once() |