Mercurial > libervia-backend
annotate tests/unit/cli/test_calls.py @ 4216:1a7a3e4b52a4
core (memory/migration):
Update XEP-0384 and `fe3a02cb4bec_convert_legacypickle_columns_to_json.py` migration to
properly handle (de)serialisation of `TrustMessageCacheEntry`.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Mar 2024 17:31:12 +0100 |
parents | 716dd791be46 |
children | dfccc90cacc6 |
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 from PyQt6.QtWidgets import QApplication |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import pytest |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 |
4213 | 23 from libervia.cli.call_gui import AVCallUI |
4207
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from libervia.frontends.tools import display_servers |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 @pytest.fixture(scope="session") |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 def qapplication(): |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 # 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
|
30 return QApplication([]) |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 @pytest.fixture |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 def av_call_gui(qapplication): |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 host = MagicMock() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 icons_path = MagicMock() |
4213 | 37 gui = AVCallUI(host, icons_path) |
4207
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 gui.webrtc_call = MagicMock() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 return gui |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 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
|
43 """``toggle_fullscreen`` changes window state.""" |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 initial_state = av_call_gui.isFullScreen() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 av_call_gui.toggle_fullscreen() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 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
|
47 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 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
|
50 """``toggle_video`` actually toggles video state.""" |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 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
|
52 av_call_gui.toggle_video() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 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
|
54 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 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
|
57 """``toggle_audio`` actually toggles audio state.""" |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 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
|
59 av_call_gui.toggle_audio() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 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
|
61 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 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
|
64 """``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
|
65 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
|
66 # 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
|
67 with patch( |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 "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
|
69 return_value=display_servers.WAYLAND, |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 ): |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 av_call_gui.share_desktop() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 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
|
73 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 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
|
76 """Hang-up button triggers window close.""" |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 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
|
78 av_call_gui.hang_up() |
2865e70b0b2c
tests (unit/cli/calls): unit tests for CLI call GUI:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 mock_close.assert_called_once() |