Files
KX-Bridge-Release/tests/conftest.py
viewit b9594d4a22
All checks were successful
Nightly Build / build (push) Successful in 13m35s
feat(dashboard): free drag+resize grid with custom presets (Issue #89)
Replace the fixed dashboard layout with a fully customizable GridStack.js
grid (12-col snap grid, vendored + inlined so it also works in OrcaSlicer's
embedded webview). Cards can be dragged, resized, hidden and rearranged;
layout persists per browser. Includes two built-in presets (Standard,
Wide desktop per the original Issue #89 proposal) plus the ability to
save/apply/delete named custom presets.

fix(camera): stream freeze after ~15-30min from non-monotonic FLV
timestamps — ffmpeg's realtime pacing stalls on PTS jumps in the printer's
stream. Fixed with -use_wallclock_as_timestamps on both ffmpeg call sites
(CameraCache._input_args, _run_h264_loop). Issue #90.

test: fix tests/conftest.py referencing a stale bridge/ subfolder path and
missing args.data_dir (pre-existing breakage, unrelated to this feature);
rewrite the two test_settings.py cases that still mocked the removed
_find_env_path from the old .env-based settings storage.
2026-07-16 11:34:34 +02:00

71 lines
2.6 KiB
Python

"""
Shared fixtures für KX-Bridge Tests.
Startet die Bridge in-process mit einem Mock-MQTT-Client (kein Drucker nötig).
"""
import sys, types, argparse, tempfile, pytest, pytest_asyncio
from unittest.mock import MagicMock
from aiohttp.test_utils import TestClient, TestServer
# ── Pfad ──────────────────────────────────────────────────────────────────────
# Flat repo layout (no bridge/ subfolder anymore) — point at the repo root.
sys.path.insert(0, str(__import__("pathlib").Path(__file__).parent.parent))
# ── env_loader mocken (keine .env nötig) ──────────────────────────────────────
env_mod = types.ModuleType("env_loader")
env_mod.PRINTER_IP = ""
env_mod.MQTT_PORT = 9883
env_mod.USERNAME = ""
env_mod.PASSWORD = ""
env_mod.MODE_ID = "20030"
env_mod.DEVICE_ID = ""
sys.modules["env_loader"] = env_mod
# ── Bridge + App importieren ───────────────────────────────────────────────────
from kobrax_moonraker_bridge import KobraXBridge, build_app # noqa: E402
def make_mock_client():
"""Minimaler Mock-MQTT-Client — keine Verbindung, keine Threads."""
c = MagicMock()
c.callbacks = {}
c.connected = False
return c
def make_args(**overrides):
args = argparse.Namespace(
printer_ip = "",
mqtt_port = 9883,
username = "",
password = "",
mode_id = "20030",
device_id = "",
host = "127.0.0.1",
port = 7125,
data_dir = tempfile.mkdtemp(prefix="kxtest-"),
)
for k, v in overrides.items():
setattr(args, k, v)
return args
@pytest_asyncio.fixture
async def client():
"""TestClient mit frischer Bridge-Instanz, ohne MQTT-Verbindung."""
mock_client = make_mock_client()
bridge = KobraXBridge(mock_client, args=make_args())
app = build_app(bridge)
async with TestClient(TestServer(app)) as c:
yield c, bridge
@pytest_asyncio.fixture
async def client_configured():
"""TestClient mit bereits konfigurierten Zugangsdaten."""
mock_client = make_mock_client()
args = make_args(printer_ip="192.168.1.100", device_id="abc123deadbeef")
bridge = KobraXBridge(mock_client, args=args)
app = build_app(bridge)
async with TestClient(TestServer(app)) as c:
yield c, bridge