From 48201780de007c3eb1bb4c286015397b65fc474f Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 5 Mar 2024 17:31:56 +0100 Subject: [PATCH] tests: fix and update tests: - update code to newer version of `sh` - update code to newer version of `selenium` - update names of OMEMO algorithms - fix paths and names used to mount source to the test container - skip modules using `Gst` and `PyQt` when they are not available. --- tests/e2e/libervia-cli/conftest.py | 4 ++-- tests/e2e/libervia-cli/test_libervia-cli.py | 13 ++++++----- tests/e2e/libervia-web/conftest.py | 4 ++-- tests/e2e/libervia-web/test_libervia-web.py | 24 +++++++++++++++++---- tests/e2e/run_e2e.py | 24 ++++++++++----------- tests/unit/cli/test_calls.py | 9 +++++--- tests/unit/frontends/test_webrtc.py | 9 +++++++- 7 files changed, 58 insertions(+), 29 deletions(-) diff --git a/tests/e2e/libervia-cli/conftest.py b/tests/e2e/libervia-cli/conftest.py index e3fb988d..67b9ff7b 100644 --- a/tests/e2e/libervia-cli/conftest.py +++ b/tests/e2e/libervia-cli/conftest.py @@ -38,7 +38,7 @@ class LiberviaCliJson: kwargs['output'] = 'json-raw' kwargs['_tty_out'] = False cmd = li(*args, **kwargs) - return json.loads(cmd.stdout) + return json.loads(cmd) def __getattr__(self, name): if name.startswith('_'): @@ -63,7 +63,7 @@ class LiberviaCliElt(LiberviaCliJson): kwargs['output'] = 'xml-raw' kwargs['_tty_out'] = False cmd = li(*args, **kwargs) - return self.parser(cmd.stdout.decode().strip()) + return self.parser(cmd.strip()) class Editor: diff --git a/tests/e2e/libervia-cli/test_libervia-cli.py b/tests/e2e/libervia-cli/test_libervia-cli.py index 0762e198..976dbba9 100644 --- a/tests/e2e/libervia-cli/test_libervia-cli.py +++ b/tests/e2e/libervia-cli/test_libervia-cli.py @@ -376,17 +376,20 @@ class TestE2EEncryption: def test_jingle_encrypted_transport_jet(self, fake_file): """A file is sent and received properly with JET OMEMO""" - li.encryption.start("account1@server2.test", name="oldmemo") + # FIXME: transport should be checked to see if content is actually encrypted. + # Maybe we can use tcpdump? + li.encryption.start("account1@server2.test", name="omemo_legacy") source_file = fake_file.size(10240) source_file_hash = fake_file.get_source_hash(source_file) send_cmd = li.file.send( - source_file, "account1@server2.test", encrypt=True, _bg=True + source_file, "account1@server2.test", encrypt=True, _bg=True, ) dest_path = fake_file.dest_files / "test_send_receive" dest_path.mkdir() try: li.file.receive( - "account1@server1.test", profile="account1_s2", path=dest_path) + "account1@server1.test", profile="account1_s2", path=dest_path, + ) dest_file = dest_path / source_file.name dest_file_hash = fake_file.get_dest_hash(dest_file) finally: @@ -401,9 +404,9 @@ class TestE2EEncryption: secret_blog = "this is a secret blog post" node = "e2ee_blog" item = "test_pte" - li.encryption.start("account1@server2.test", name="twomemo") + li.encryption.start("account1@server2.test", name="omemo") li.encryption.start( - "account1@server1.test", name="twomemo", profile="account1_s2" + "account1@server1.test", name="omemo", profile="account1_s2" ) li.blog.set( _in=secret_blog, node="e2ee_blog", item=item, diff --git a/tests/e2e/libervia-web/conftest.py b/tests/e2e/libervia-web/conftest.py index f2ed0d02..e7594294 100644 --- a/tests/e2e/libervia-web/conftest.py +++ b/tests/e2e/libervia-web/conftest.py @@ -26,7 +26,7 @@ from pathlib import Path import helium -WEB_HOST = "libervia-web.test" +WEB_HOST = "web" WEB_PORT_HTTPS = 8443 BASE_URL = f"https://{WEB_HOST}:{WEB_PORT_HTTPS}" SIZE_DESKTOP = (1024, 728) @@ -54,7 +54,7 @@ def screenshot_on_failure(request): filename = f"{datetime.now().isoformat()}_{request.node.name}.png" dest_path = dest_dir/filename helium.get_driver().save_screenshot(str(dest_path)) - print(f"screenshot saved to {dest_path}") + print(f" 📸screenshot saved to {dest_path}") def wait_for_socket(host, port, retries=30): diff --git a/tests/e2e/libervia-web/test_libervia-web.py b/tests/e2e/libervia-web/test_libervia-web.py index af07e7bb..4d9a980a 100644 --- a/tests/e2e/libervia-web/test_libervia-web.py +++ b/tests/e2e/libervia-web/test_libervia-web.py @@ -18,11 +18,27 @@ import os import re + import pytest + from helium import ( - go_to, write, press, click, drag_file, find_all, wait_until, S, Text, Link, Button, - select, scroll_down, get_driver, ENTER + Button, + ENTER, + Link, + S, + Text, + click, + drag_file, + find_all, + get_driver, + go_to, + press, + scroll_down, + select, + wait_until, + write, ) +from selenium.webdriver.common.by import By if os.getenv("LIBERVIA_TEST_ENV_E2E_WEB") is None: @@ -214,8 +230,8 @@ class TestLists: assert Link("manage invitations").exists() item = Link("test item") assert item.exists() - labels_elt = item.web_element.find_element_by_class_name("xmlui_field__labels") - labels = [t.text for t in labels_elt.find_elements_by_tag_name("span")] + labels_elt = item.web_element.find_element(By.CLASS_NAME, "xmlui_field__labels") + labels = [t.text for t in labels_elt.find_elements(By.TAG_NAME, "span")] assert labels == ["label 1", "label 2"] @pytest.mark.dependency(depends=["create_generic_list_item"]) diff --git a/tests/e2e/run_e2e.py b/tests/e2e/run_e2e.py index be8e0334..fbab7edd 100755 --- a/tests/e2e/run_e2e.py +++ b/tests/e2e/run_e2e.py @@ -26,7 +26,7 @@ from datetime import datetime import sh import io import sat_templates -import libervia +from libervia import web from libervia.backend.core import exceptions from libervia.backend.tools.common import regex import yaml @@ -145,34 +145,34 @@ def use_e2e_env(): keep_containers = keep_profiles = keep_vnc = visual = True for p in Path.cwd().parents: - package_path = p / "sat" + package_path = p / "libervia" docker_path = p / "docker" if package_path.is_dir() and docker_path.is_dir(): backend_root_path = p break else: raise exceptions.NotFound( - "Can't find root of SàT code, are you sure that you are running the test " - "from the backend repository?" + "Can't find root of Libervia code, are you sure that you are running the " + "test from the backend repository?" ) - libervia_web_path = Path(libervia.__file__).parent.resolve() + libervia_web_path = Path(web.__file__).parent.resolve() libervia_web_root_path = libervia_web_path.parent if (libervia_web_root_path / ".hg").is_dir(): libervia_web_source = libervia_web_root_path libervia_web_target = "/src/libervia-web" else: libervia_web_source = libervia_web_path - libervia_web_target = "/src/libervia-web/libervia" + libervia_web_target = "/src/libervia-web/libervia/web" sat_templates_path = Path(sat_templates.__file__).parent.resolve() sat_templates_root_path = sat_templates_path.parent if (sat_templates_root_path / ".hg").is_dir(): - sat_templates_source = sat_templates_root_path - sat_templates_target = "/src/libervia-templates" + libervia_templates_source = sat_templates_root_path + libervia_templates_target = "/src/libervia-templates" else: - sat_templates_source = sat_templates_path - sat_templates_target = "/src/libervia-templates/sat_templates" + libervia_templates_source = sat_templates_path + libervia_templates_target = "/src/libervia-templates/sat_templates" compose_e2e_path = docker_path / "docker-compose-e2e.yml" if not compose_e2e_path.is_file(): @@ -201,8 +201,8 @@ def use_e2e_env(): target: {libervia_web_target} read_only: true - type: bind - source: {sat_templates_source} - target: {sat_templates_target} + source: {libervia_templates_source} + target: {libervia_templates_target} read_only: true """ ), diff --git a/tests/unit/cli/test_calls.py b/tests/unit/cli/test_calls.py index aa867619..69486155 100644 --- a/tests/unit/cli/test_calls.py +++ b/tests/unit/cli/test_calls.py @@ -17,11 +17,14 @@ # along with this program. If not, see . from unittest.mock import MagicMock, patch -from PyQt6.QtWidgets import QApplication import pytest -from libervia.cli.call_gui import AVCallUI -from libervia.frontends.tools import display_servers +try: + from libervia.cli.call_gui import AVCallUI + from libervia.frontends.tools import display_servers + from PyQt6.QtWidgets import QApplication +except ModuleNotFoundError: + pytest.skip("PyQt6 is not available.", allow_module_level=True) @pytest.fixture(scope="session") diff --git a/tests/unit/frontends/test_webrtc.py b/tests/unit/frontends/test_webrtc.py index 2a86fa25..97344b2f 100644 --- a/tests/unit/frontends/test_webrtc.py +++ b/tests/unit/frontends/test_webrtc.py @@ -17,9 +17,13 @@ # along with this program. If not, see . from unittest.mock import AsyncMock, MagicMock -from gi.repository import Gst import pytest +try: + from gi.repository import Gst +except ImportError: + pytest.skip("Gst not available.", allow_module_level=True) + from libervia.backend.core import exceptions from libervia.backend.tools.common import data_format from libervia.frontends.tools import webrtc as webrtc_mod @@ -158,6 +162,7 @@ class TestWebRtc: mock_pipeline.add.assert_called() mock_pad.link.assert_called() + @pytest.mark.skipif(Gst is None) @pytest.mark.asyncio async def test_setup_call_correct_role(self, host, webrtc, monkeypatch): """Roles are set in setup_call.""" @@ -191,6 +196,7 @@ class TestWebRtc: assert "v4l2src" in webrtc.gst_pipe_desc assert "pulsesrc" in webrtc.gst_pipe_desc + @pytest.mark.skipif(Gst is None) @pytest.mark.asyncio async def test_setup_call_with_stun_and_turn(self, host, webrtc, monkeypatch): """STUN and TURN server configurations are done in setup_call.""" @@ -231,6 +237,7 @@ class TestWebRtc: "add-turn-server", "turn://user:pass@turn.host:3478" ) + @pytest.mark.skipif(Gst is None) @pytest.mark.asyncio async def test_setup_call_gstreamer_pipeline_failure(self, webrtc, monkeypatch): """Test setup_call method handling Gstreamer pipeline failure."""