changeset 4227:dfccc90cacc6

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.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:56 +0100
parents 3f7ca590a5da
children 79a4870cfbdf
files tests/e2e/libervia-cli/conftest.py tests/e2e/libervia-cli/test_libervia-cli.py tests/e2e/libervia-web/conftest.py tests/e2e/libervia-web/test_libervia-web.py tests/e2e/run_e2e.py tests/unit/cli/test_calls.py tests/unit/frontends/test_webrtc.py
diffstat 7 files changed, 58 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/tests/e2e/libervia-cli/conftest.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/e2e/libervia-cli/conftest.py	Tue Mar 05 17:31:56 2024 +0100
@@ -38,7 +38,7 @@
         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 @@
         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:
--- a/tests/e2e/libervia-cli/test_libervia-cli.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/e2e/libervia-cli/test_libervia-cli.py	Tue Mar 05 17:31:56 2024 +0100
@@ -376,17 +376,20 @@
 
     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 @@
         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,
--- a/tests/e2e/libervia-web/conftest.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/e2e/libervia-web/conftest.py	Tue Mar 05 17:31:56 2024 +0100
@@ -26,7 +26,7 @@
 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 @@
             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):
--- a/tests/e2e/libervia-web/test_libervia-web.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/e2e/libervia-web/test_libervia-web.py	Tue Mar 05 17:31:56 2024 +0100
@@ -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 @@
         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"])
--- a/tests/e2e/run_e2e.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/e2e/run_e2e.py	Tue Mar 05 17:31:56 2024 +0100
@@ -26,7 +26,7 @@
 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 @@
         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 @@
                         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
                 """
                    ),
--- a/tests/unit/cli/test_calls.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/unit/cli/test_calls.py	Tue Mar 05 17:31:56 2024 +0100
@@ -17,11 +17,14 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 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")
--- a/tests/unit/frontends/test_webrtc.py	Tue Mar 05 17:31:56 2024 +0100
+++ b/tests/unit/frontends/test_webrtc.py	Tue Mar 05 17:31:56 2024 +0100
@@ -17,9 +17,13 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 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 @@
         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 @@
         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 @@
             "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."""