Add meal tracker app: Flask + SQLite with auth, dashboard, 31 passing tests, Docker Compose

This commit is contained in:
agentbox
2026-07-31 21:25:59 +00:00
parent aabc83281b
commit d58828e0ef
17 changed files with 1214 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
"""Shared test fixtures for the meal tracker."""
import os
import tempfile
import pytest
from app import create_app
from models import init_db, get_db
@pytest.fixture
def app():
"""Create a Flask app with a temporary database."""
db_fd, db_path = tempfile.mkstemp(suffix=".db")
os.environ["DB_PATH"] = db_path
app = create_app()
app.config["SECRET_KEY"] = "test-secret"
app.config["TESTING"] = True
with app.app_context():
init_db()
yield app
os.close(db_fd)
os.unlink(db_path)
os.environ.pop("DB_PATH", None)
@pytest.fixture
def client(app):
"""Flask test client."""
return app.test_client()
@pytest.fixture
def auth_client(client):
"""Test client with a logged-in regular user."""
client.post("/register", data={
"username": "bob",
"password": "bobpass",
"confirm": "bobpass",
})
client.get("/logout")
client.post("/register", data={
"username": "alice",
"password": "alicepass",
"confirm": "alicepass",
})
client.get("/logout")
# Log in as bob (second user, not admin)
client.post("/login", data={
"username": "bob",
"password": "bobpass",
})
return client
@pytest.fixture
def admin_client(client):
"""Test client with the admin user logged in."""
client.post("/register", data={
"username": "admin",
"password": "adminpass",
"confirm": "adminpass",
})
return client