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