Add isRinging query to check alarm state via API

Features:
- New GraphQL query 'isRinging' returns true/false if wecker is active
- Checks the wecker process via PID file (PID_FILE in common.py)

DRY refactoring:
- Extract PID_FILE into shared common.py module
- Both wecker.py and api/schema.py import from common
- DRY enforcement tests verify identity (is) not just equality

Tests:
- test_is_ringing_returns_false_when_not_running
- test_is_ringing_returns_true_when_running
- test_pid_file_defined_once_across_modules (DRY enforcement)
- test_pid_file_same_shared_constant_in_api (DRY enforcement)
- Cleaned up unused imports in test_single_instance.py

Docs:
- Updated README.md with isRinging query documentation
This commit is contained in:
Markus Graf
2026-05-19 15:15:05 +02:00
parent 29aff04e33
commit 558c4ff5b6
6 changed files with 98 additions and 5 deletions
+17 -3
View File
@@ -1,7 +1,7 @@
import os
import sys
import pytest
from unittest.mock import MagicMock, patch
from unittest.mock import patch
import common
import wecker
# We need to mock the PID file existence and os.kill to test the logic
@@ -80,3 +80,17 @@ def test_remove_pid_file_wrong_pid(mock_pid_file):
wecker.remove_pid_file()
assert mock_pid_file.exists()
def test_pid_file_defined_once_across_modules():
"""
DRY principle: PID_FILE must be defined in common.py and imported by
both wecker.py and api/schema.py — not redefined in each.
"""
# wecker.py imports PID_FILE from common — verify it's the same object
assert wecker.PID_FILE is common.PID_FILE, (
"wecker.PID_FILE must reference common.PID_FILE, not redefine it"
)
# Verify the path ends with "wecker.pid"
assert common.PID_FILE.endswith("wecker.pid")