- BUG-02: cancel_session bei mehrstufiger Auth (z.B. TOTP) - BUG-03: CalledProcessError bei reboot/shutdown abfangen - M-1+EH-01: configparser interpolation=None + Error-Handling - H-1: Exec-Cmd Validierung (absoluter Pfad erforderlich) - PERF: Theme-Guard, Default-Avatar-Cache, Avatar-Cache per User - Mutable Default Arguments in sessions.py (list → tuple) - Ungenutzten Gio-Import entfernt
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
# ABOUTME: Tests for power actions — reboot and shutdown via loginctl.
|
|
# ABOUTME: Uses mocking to avoid actually calling system commands.
|
|
|
|
import subprocess
|
|
from unittest.mock import patch, call
|
|
|
|
import pytest
|
|
|
|
from moongreet.power import reboot, shutdown
|
|
|
|
|
|
class TestReboot:
|
|
"""Tests for the reboot power action."""
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_calls_loginctl_reboot(self, mock_run) -> None:
|
|
reboot()
|
|
|
|
mock_run.assert_called_once_with(
|
|
["loginctl", "reboot"], check=True
|
|
)
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_raises_on_failure(self, mock_run) -> None:
|
|
mock_run.side_effect = subprocess.CalledProcessError(1, "loginctl")
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
reboot()
|
|
|
|
|
|
class TestShutdown:
|
|
"""Tests for the shutdown power action."""
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_calls_loginctl_poweroff(self, mock_run) -> None:
|
|
shutdown()
|
|
|
|
mock_run.assert_called_once_with(
|
|
["loginctl", "poweroff"], check=True
|
|
)
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_raises_on_failure(self, mock_run) -> None:
|
|
mock_run.side_effect = subprocess.CalledProcessError(1, "loginctl")
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
shutdown()
|