Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 14:15 UTC
dependabot/github_actions/actions/checkout-7
add-index-html-10623938925177053894
arena/094f314c-aram
arena/2d4eda07-aram
chatgpt-phase1b2-autopilot
codex/adr-future-connectors-pi-v1
codex/aram-account-note-source-trace-20261031
codex/aram-actions-node24-maintenance-20261031
codex/aram-analyst-review-workbook-20261031
codex/aram-bs-candidate-statement-20261031
codex/aram-cash-flow-direct-candidate-20261031
codex/aram-clean-reference-year-integrity-20261030
codex/aram-cross-statement-controls-20261031
codex/aram-equity-changes-candidate-20261031
codex/aram-five-statement-cli-20261031
codex/aram-five-statement-integration-20261031
codex/aram-five-statement-orchestrator-20261031
codex/aram-gate3-coverage-target-guard-20261030
codex/aram-gate3-hidden-xlsx-guard-20261030
codex/aram-gate3-integration-validation-20261030
codex/aram-gate3-mapping-change-preview-20261030
codex/aram-gate3-stale-note-guard-20261030
codex/aram-income-statement-candidate-20261031
codex/aram-manifest-referential-integrity-20261031
codex/aram-mapping-source-parser-20261101
codex/aram-multidimensional-mapping-20261101
codex/aram-multistatement-mapping-20261031
codex/aram-pipeline-manifest-schema-20261031
codex/aram-readonly-mapping-coverage-20261031
codex/aram-reconciliation-review-gate-20261031
codex/aram-same-flush-fiscal-lock-20261030
codex/aram-synthetic-windows-demo-20261031
codex/aram-trial-balance-diagnostic-20261031
codex/aram-windows-background-detail-search-20261031
codex/aram-windows-detail-review-20261031
codex/aram-windows-five-statement-pilot-20261031
codex/aram-windows-statement-figures-20261031
codex/gate-2a-pilot-workbook
codex/gate-2a-pilot-workbook-6864754244772568979
codex/gate3-authenticated-principal-boundary-20261030
codex/gate3-authored-draft-staging-20261030
codex/gate3-carry-forward-preview-20261023
codex/gate3-draft-staging-audit-20261030
codex/gate3-mapping-batch-freshness-20261030
codex/gate3-mapping-batch-review-20261030
codex/gate3-mapping-core
codex/gate3-mapping-coverage-20261023
codex/gate3-mapping-excel-20261023
codex/gate3-note-mapping-review-20261023
codex/gate3-signed-year-scope-20261030
codex/gate3-unapproved-proposal-storage-20261030
codex/payvast-mapping-discovery-20261023
codex/phase-2a-backend-foundation
codex/phase-2b-post-merge-record
codex/phase-2b-source-registration
codex/phase-2b-source-registration-12955190277775369594
codex/post-gate2a-control-reconciliation
codex/post-pr18-acceptance-record
codex/project-control-foundation
codex/t1-repo-hygiene-20261023
codex/t2-ci-hardening-20261023
codex/t3-explicit-migrations-20261023
codex/t6a-readonly-diagnostics-20261023
codex/v1-01-safety-gate-hardening
codex/v1-year-isolation-followup-20261023
codex/windows-native-pilot-shell-20261030
dependabot/github_actions/actions/checkout-7
dependabot/github_actions/actions/setup-node-6
dependabot/github_actions/actions/setup-python-7
dependabot/github_actions/actions/upload-artifact-7
dependabot/npm_and_yarn/frontend/eslint-plugin-react-hooks-7.1.1
dependabot/npm_and_yarn/frontend/globals-17.15.0
dependabot/npm_and_yarn/frontend/vite-8.4.0
dependabot/npm_and_yarn/frontend/vitest-5.1.2
dependabot/npm_and_yarn/frontend/vitest/coverage-v8-5.1.2
dependabot/pip/backend/mypy-gte-1.13-and-lt-3
dependabot/pip/backend/pytest-cov-gte-6.0-and-lt-8
dependabot/pip/backend/setuptools-gte-75-and-lt-85
docs/aram-master-control-plan-20261111
docs/aram-roadmap-dashboard-20261030
docs/financial-statement-reconciliation-1402-1404-20261110
feat/gate3-governed-mapping-20261101
feat/gate3-package9-1-security-20261103
feat/gate3-package9-isolated-20261103
fix/password-unicode-validation-20261111
governance/aram-5-1-3-controls-20261030
governance/role-based-operating-model
jules-1168663913887856558-73b8a885
jules-gate-2b-mapping-workflow-foundation-4137724387867065330
phase-1b1-audit-report-7365389436990903239
phase-2a-backend-foundation-10237597358138521261
phase1b2-postmerge-metadata-fix
refactor/drg-parent-year-id-15088443704684163304
source-data-cleanup
| 1 | import pytest |
| 2 | from fastapi.testclient import TestClient |
| 3 | from sqlalchemy.orm import Session, sessionmaker |
| 4 | |
| 5 | from aram_backend.config import Settings |
| 6 | from aram_backend.database import Base, build_engine, ensure_triggers, get_session |
| 7 | from aram_backend.main import app |
| 8 | |
| 9 | |
| 10 | @pytest.fixture |
| 11 | def session(tmp_path) -> Session: |
| 12 | engine = build_engine(f"sqlite:///{tmp_path / 'test.db'}") |
| 13 | Base.metadata.create_all(engine) |
| 14 | ensure_triggers(engine) |
| 15 | factory = sessionmaker(bind=engine, expire_on_commit=False) |
| 16 | with factory() as db: |
| 17 | yield db |
| 18 | Base.metadata.drop_all(engine) |
| 19 | engine.dispose() |
| 20 | |
| 21 | |
| 22 | @pytest.fixture |
| 23 | def client() -> TestClient: |
| 24 | return TestClient(app) |
| 25 | |
| 26 | |
| 27 | @pytest.fixture |
| 28 | def api_client(tmp_path, monkeypatch) -> TestClient: |
| 29 | """DB-backed API client, isolated DB + store, **logged in as an ADMIN**. |
| 30 | |
| 31 | R1 (booklet 2.1): every route needs a session, so the default fixture performs |
| 32 | the one-time first-admin bootstrap and a real login. Use ``anon_client`` for |
| 33 | unauthenticated behaviour and ``make_user`` for other roles. |
| 34 | """ |
| 35 | engine = build_engine(f"sqlite:///{tmp_path / 'api.db'}") |
| 36 | Base.metadata.create_all(engine) |
| 37 | ensure_triggers(engine) |
| 38 | factory = sessionmaker(bind=engine, expire_on_commit=False) |
| 39 | |
| 40 | def override_session(): |
| 41 | with factory() as db: |
| 42 | yield db |
| 43 | |
| 44 | app.dependency_overrides[get_session] = override_session |
| 45 | monkeypatch.setattr( |
| 46 | "aram_backend.statement_api.get_settings", |
| 47 | lambda: Settings(source_store_root=str(tmp_path / "store")), |
| 48 | ) |
| 49 | monkeypatch.setattr( |
| 50 | "aram_backend.admin_api.get_settings", |
| 51 | lambda: Settings(source_store_root=str(tmp_path / "store")), |
| 52 | ) |
| 53 | with TestClient(app) as test_client: |
| 54 | bootstrap = test_client.post( |
| 55 | "/api/v1/users", json={"username": "root", "password": "supersecret"} |
| 56 | ) |
| 57 | assert bootstrap.status_code == 200, bootstrap.text |
| 58 | login(test_client, "root", "supersecret") |
| 59 | yield test_client |
| 60 | app.dependency_overrides.clear() |
| 61 | Base.metadata.drop_all(engine) |
| 62 | engine.dispose() |
| 63 | |
| 64 | |
| 65 | @pytest.fixture |
| 66 | def anon_client(tmp_path, monkeypatch) -> TestClient: |
| 67 | """Same isolated app as ``api_client`` but with **no** session (R1 401 tests).""" |
| 68 | engine = build_engine(f"sqlite:///{tmp_path / 'anon.db'}") |
| 69 | Base.metadata.create_all(engine) |
| 70 | ensure_triggers(engine) |
| 71 | factory = sessionmaker(bind=engine, expire_on_commit=False) |
| 72 | |
| 73 | def override_session(): |
| 74 | with factory() as db: |
| 75 | yield db |
| 76 | |
| 77 | app.dependency_overrides[get_session] = override_session |
| 78 | monkeypatch.setattr( |
| 79 | "aram_backend.statement_api.get_settings", |
| 80 | lambda: Settings(source_store_root=str(tmp_path / "store")), |
| 81 | ) |
| 82 | monkeypatch.setattr( |
| 83 | "aram_backend.admin_api.get_settings", |
| 84 | lambda: Settings(source_store_root=str(tmp_path / "store")), |
| 85 | ) |
| 86 | with TestClient(app) as test_client: |
| 87 | yield test_client |
| 88 | app.dependency_overrides.clear() |
| 89 | Base.metadata.drop_all(engine) |
| 90 | engine.dispose() |
| 91 | |
| 92 | |
| 93 | def login(client: TestClient, username: str, password: str) -> str: |
| 94 | """Log in and return the bearer token (also sets the client's auth header).""" |
| 95 | response = client.post( |
| 96 | "/api/v1/auth/login", json={"username": username, "password": password} |
| 97 | ) |
| 98 | assert response.status_code == 200, response.text |
| 99 | token = response.json()["token"] |
| 100 | client.headers.update({"Authorization": f"Bearer {token}"}) |
| 101 | return token |
| 102 | |
| 103 | |
| 104 | def make_user(client: TestClient, username: str, role: str, password: str = "supersecret") -> str: |
| 105 | """Create a user as the authenticated admin and return a logged-in token.""" |
| 106 | response = client.post( |
| 107 | "/api/v1/users", |
| 108 | json={"username": username, "password": password, "role": role}, |
| 109 | ) |
| 110 | assert response.status_code == 200, response.text |
| 111 | admin_auth = client.headers.get("Authorization") |
| 112 | token = login(client, username, password) |
| 113 | if admin_auth: |
| 114 | client.headers.update({"Authorization": admin_auth}) |
| 115 | return token |
| 116 | |
| 117 | |
| 118 | @pytest.fixture |
| 119 | def pilot_client(tmp_path) -> TestClient: |
| 120 | """The legacy pilot router, mounted **only in this test app** and authenticated. |
| 121 | |
| 122 | R1 (booklet 2.1) removed the pilot workbench from the shipped app; these tests |
| 123 | keep covering its behaviour and prove it can never be anonymous if mounted. |
| 124 | """ |
| 125 | from fastapi import FastAPI |
| 126 | |
| 127 | from aram_backend.admin_api import public_router |
| 128 | from aram_backend.pilot_api import router as pilot_router |
| 129 | |
| 130 | engine = build_engine(f"sqlite:///{tmp_path / 'pilot.db'}") |
| 131 | Base.metadata.create_all(engine) |
| 132 | ensure_triggers(engine) |
| 133 | factory = sessionmaker(bind=engine, expire_on_commit=False) |
| 134 | |
| 135 | def override_session(): |
| 136 | with factory() as db: |
| 137 | yield db |
| 138 | |
| 139 | pilot_app = FastAPI() |
| 140 | pilot_app.include_router(public_router) |
| 141 | pilot_app.include_router(pilot_router) |
| 142 | pilot_app.dependency_overrides[get_session] = override_session |
| 143 | with TestClient(pilot_app) as test_client: |
| 144 | test_client.post("/api/v1/users", json={"username": "root", "password": "supersecret"}) |
| 145 | login(test_client, "root", "supersecret") |
| 146 | yield test_client |
| 147 | pilot_app.dependency_overrides.clear() |
| 148 | Base.metadata.drop_all(engine) |
| 149 | engine.dispose() |