Initial commit: Flask battery tracker app
- Flask + SQLAlchemy (MariaDB-compatible schema) battery tracking web app - 40 pre-seeded batteries (Eneloop, BONAI, Energizer NiMH) across 5 devices - Business rules: block retired assignment, brand-mix warnings, capacity checks - Mobile-friendly Jinja2 templates with inline CSS - waitress WSGI server via systemd user service (sbin/install-service.sh) - SQLite → MariaDB migration script (migrate_to_mariadb.py) - 26 passing acceptance tests (pytest + Flask test client) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
"""Create app with a temporary file-based SQLite DB, removed after the test."""
|
||||
db_fd, db_path = tempfile.mkstemp(suffix=".db")
|
||||
os.close(db_fd)
|
||||
|
||||
class TestConfig:
|
||||
SQLALCHEMY_DATABASE_URI = f"sqlite:///{db_path}"
|
||||
SECRET_KEY = "test-secret"
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
TESTING = True
|
||||
|
||||
from app import create_app
|
||||
flask_app = create_app(TestConfig)
|
||||
|
||||
yield flask_app
|
||||
|
||||
os.unlink(db_path)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def seeded_client(app):
|
||||
"""Test client pre-loaded with 2 devices and 3 batteries (2 available, 1 retired)."""
|
||||
with app.test_client() as c:
|
||||
c.post("/device/add", data={"name": "Device A", "battery_slots": "2"})
|
||||
c.post("/device/add", data={"name": "Device B", "battery_slots": "1"})
|
||||
c.post("/battery/add", data={"label": "TST-01", "brand": "BrandX", "status": "available"})
|
||||
c.post("/battery/add", data={"label": "TST-02", "brand": "BrandY", "status": "available"})
|
||||
c.post("/battery/add", data={"label": "TST-03", "brand": "BrandX", "status": "retired"})
|
||||
yield c
|
||||
Reference in New Issue
Block a user