v1.3 - client and admin scaffolding

This commit is contained in:
2026-04-25 22:51:36 +12:00
parent bc211ffcc8
commit 8cf9bfb441
54 changed files with 8882 additions and 1248 deletions
+94 -6
View File
@@ -8,9 +8,11 @@ from app.core.config import settings
from app.db.session import Base
from app.main import app
from app.models.assumption import FreightCostRule, PackagingCostRule, ProcessCostRule
from app.models.client_access import ClientAccount, ClientFeatureAccess, ClientUser
from app.models.mix import Mix, MixIngredient
from app.models.product import Product
from app.models.raw_material import RawMaterial, RawMaterialPriceVersion
from app.services.client_access_service import build_client_access_export, serialize_client_account
from app.services.costing_engine import calculate_mix_cost, calculate_product_cost, calculate_raw_material_cost
@@ -85,11 +87,97 @@ def test_root_and_login_endpoints():
root_response = client.get("/")
assert root_response.status_code == 200
assert root_response.json()["endpoints"]["login"] == "/api/auth/login"
assert root_response.json()["endpoints"]["client_login"] == "/api/auth/client/login"
assert root_response.json()["endpoints"]["admin_login"] == "/api/auth/admin/login"
login_response = client.post(
"/api/auth/login",
json={"email": settings.operator_email, "password": settings.operator_password},
client_login_response = client.post(
"/api/auth/client/login",
json={"email": settings.client_email, "password": settings.client_password},
)
assert login_response.status_code == 200
assert login_response.json()["email"] == settings.operator_email
assert client_login_response.status_code == 200
assert client_login_response.json()["email"] == settings.client_email
assert client_login_response.json()["tenant_id"] == settings.client_tenant_id
admin_login_response = client.post(
"/api/auth/admin/login",
json={"email": settings.admin_email, "password": settings.admin_password},
)
assert admin_login_response.status_code == 200
assert admin_login_response.json()["email"] == settings.admin_email
def test_client_access_export_helpers():
db = build_session()
client = ClientAccount(
tenant_id="specialty-feeds",
name="Specialty Feeds",
client_code="SPEC",
status="active",
powerbi_workspace="farm-ops-prod",
)
client.users.extend(
[
ClientUser(
full_name="Amelia Hart",
email="amelia.hart@specialtyfeeds.example",
role="admin",
status="active",
is_new_user=False,
),
ClientUser(
full_name="Ethan Cole",
email="ethan.cole@specialtyfeeds.example",
role="operator",
status="invited",
is_new_user=True,
),
]
)
client.features.extend(
[
ClientFeatureAccess(
feature_key="dashboard",
feature_name="Dashboard",
feature_group="workspace",
enabled=True,
),
ClientFeatureAccess(
feature_key="products",
feature_name="Products",
feature_group="pricing",
enabled=False,
),
]
)
db.add(client)
db.commit()
db.refresh(client)
serialized = serialize_client_account(client)
export = build_client_access_export([client])
assert serialized["active_user_count"] == 1
assert serialized["new_user_count"] == 1
assert serialized["enabled_feature_count"] == 1
assert export["client_rows"][0]["client_code"] == "SPEC"
assert export["user_rows"][0]["client_name"] == "Specialty Feeds"
assert len(export["feature_rows"]) == 2
def test_client_access_endpoints():
with TestClient(app) as client:
login_response = client.post(
"/api/auth/admin/login",
json={"email": settings.admin_email, "password": settings.admin_password},
)
token = login_response.json()["token"]
headers = {"Authorization": f"Bearer {token}"}
access_response = client.get("/api/client-access", headers=headers)
assert access_response.status_code == 200
assert len(access_response.json()) >= 1
export_response = client.get("/api/powerbi/client-access", headers=headers)
assert export_response.status_code == 200
assert "client_rows" in export_response.json()