Update tests/test_utils_dbusnotify.py
Run CI Tests / test (push) Has been cancelled

This commit is contained in:
2025-08-17 12:32:30 +02:00
parent 9a78d33e2b
commit 4c54ccdb20
+23 -6
View File
@@ -2,15 +2,32 @@ import os
import time
import subprocess
import pytest
from dbusmock import DBusTestCase
from slic.utils.dbusnotify import *
import dbus
class TestDBusNotify(DBusTestCase):
"""Tests pour DBusNotify en utilisant le mock intégré de python-dbusmock."""
@classmethod
def setUpClass(cls):
# Démarrer un bus de session isolé pour les tests
cls.start_session_bus()
# Démarrer le mock automatique du service Notifications
cls.mock = cls.spawn_server(
bus_name='org.freedesktop.Notifications',
object_path='/org/freedesktop/Notifications',
interface='org.freedesktop.Notifications',
system_bus=False
)
@pytest.fixture
def notifier():
"""Création de l'objet DBusNotify pour les tests."""
return DBusNotify()
def test_notify_create(notifier):
def test_notify_create(self, notifier):
"""Test la création d'une notification."""
notification = notifier.notify("Test Notification", "This is a test notification.")
@@ -20,7 +37,7 @@ def test_notify_create(notifier):
assert notification.body == "This is a test notification."
def test_notify_update(notifier):
def test_notify_update(self, notifier):
"""Test la mise à jour d'une notification."""
notification = notifier.notify("Test Notification", "This is a test notification.")
@@ -31,7 +48,7 @@ def test_notify_update(notifier):
assert notification.summary == "Updated Test"
assert notification.body == "This notification has been updated."
def test_get_server_info(notifier):
def test_get_server_info(self, notifier):
"""Test l'obtention des informations du serveur."""
server_info = notifier.get_server_info()
@@ -41,7 +58,7 @@ def test_get_server_info(notifier):
assert "version" in server_info and server_info["version"], "Server version is empty"
assert "spec" in server_info and server_info["spec"], "Server spec is empty"
def test_get_capabilities(notifier):
def test_get_capabilities(self, notifier):
"""Test l'obtention des capacités du serveur."""
capabilities = notifier.get_capabilities()
@@ -55,7 +72,7 @@ def test_get_capabilities(notifier):
for cap in capabilities:
assert isinstance(cap, str), f"Each capability should be a string, but found {type(cap)}."
def test_notify_and_close(notifier):
def test_notify_and_close(self, notifier):
"""Test l'envoi d'une notification et sa fermeture."""
notification = notifier.notify("Test Close", "This notification will be closed.")
@@ -66,7 +83,7 @@ def test_notify_and_close(notifier):
printed_lines = notification.dbn.interface._prints
assert not any(f"Notification {notification.nid} is still visible" in line for line in printed_lines), "Notification was not closed properly."
def test_notify_invalid_value(notifier):
def test_notify_invalid_value(self, notifier):
with pytest.raises(Exception): # On attend une exception si la valeur est incorrecte
notifier.notify("Invalid Test", 1234) # Passage d'un type non valide pour `body`