Files
ImpTune/tests/conftest.py
T
kawa f9e13ba96f feat(05-02): icon upload endpoint with validation
- Create imptune/api/icons.py with POST /printers/{printer_id}/icon
- Validate PNG format, 256x256 dimensions, 750KB max size
- Store icons SHA256-addressed under cfg.DATA_DIR/icons/
- Replace existing Icon record on re-upload
- Register icons.router in main.py with ICONS_DIR makedirs
- Patch cfg.ICONS_DIR in conftest.py for tests
- All 6 icon upload tests pass
2026-04-10 15:05:36 +02:00

37 lines
947 B
Python

import os
import pytest
from fastapi.testclient import TestClient
@pytest.fixture
def client(tmp_data_dir):
from imptune.main import app
with TestClient(app) as c:
yield c
@pytest.fixture
def tmp_data_dir(tmp_path, monkeypatch):
"""Set DATA_DIR to a temp directory so tests don't write to /data."""
data_dir = tmp_path / "data"
data_dir.mkdir()
monkeypatch.setenv("DATA_DIR", str(data_dir))
# Patch config module so the app uses the temp dir
import imptune.config as cfg
cfg.DATA_DIR = str(data_dir)
cfg.DB_PATH = str(data_dir / "imptune.db")
cfg.DRIVERS_DIR = str(data_dir / "drivers")
cfg.ICONS_DIR = str(data_dir / "icons")
yield data_dir
# Close the test-thread's DB connection so the next test gets a fresh one
# pointing to its own tmp DB (Peewee connections are thread-local).
from imptune.db.database import db
if not db.is_closed():
db.close()