Add household support: multi-household isolation, each with own admin and users, 38 tests

This commit is contained in:
agentbox
2026-07-31 21:44:29 +00:00
parent d58828e0ef
commit c48cd265ca
10 changed files with 459 additions and 126 deletions
+32 -12
View File
@@ -6,7 +6,7 @@ import tempfile
import pytest
from app import create_app
from models import init_db, get_db
from models import init_db
@pytest.fixture
@@ -35,35 +35,55 @@ def client(app):
return app.test_client()
def _register_and_login(client, username, password, household_action="create",
household_name=None, join_household_id=None):
"""Helper: register (and auto-login) a user."""
if not household_name:
household_name = f"{username}-house"
resp = client.post("/register", data={
"username": username,
"password": password,
"confirm": password,
"household_action": household_action,
"new_household_name": household_name,
"household_id": str(join_household_id) if join_household_id else "",
}, follow_redirects=True)
return resp
@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")
"""Test client with a logged-in regular user in a 2-person household."""
# Admin creates household
client.post("/register", data={
"username": "alice",
"password": "alicepass",
"confirm": "alicepass",
"household_action": "create",
"new_household_name": "Test Household",
})
client.get("/logout")
# Log in as bob (second user, not admin)
client.post("/login", data={
# Bob joins the same household
from models import get_household_by_name
hh = get_household_by_name("Test Household")
client.post("/register", data={
"username": "bob",
"password": "bobpass",
"confirm": "bobpass",
"household_action": "join",
"household_id": str(hh["id"]),
})
return client
return client # Logged in as bob (regular user)
@pytest.fixture
def admin_client(client):
"""Test client with the admin user logged in."""
"""Test client with the admin user logged in (created their own household)."""
client.post("/register", data={
"username": "admin",
"password": "adminpass",
"confirm": "adminpass",
"household_action": "create",
"new_household_name": "Admin Household",
})
return client