Files
jimmyandClaude Opus 5.5 4b3e5f0932 Move to FastAPI with accounts, SQLite books, export and tax returns
Storage and export
- Keep books and transactions in SQLite (data/cashbook.db) instead of
  .ods files; existing .ods books are migrated once at startup
- Export a book as the cashbook spreadsheet (.xlsx/.ods, built from the
  template via LibreOffice) or as CSV
- GST rounded per transaction to match the spreadsheet

Tax
- GST return page with IRD GST101A boxes 5-15 per six-monthly,
  two-monthly or monthly period, due dates, and a Zero-rated GST type
- Income tax page with IR10 (financial statements summary) and IR4
  (company return) boxes, from the cashbook plus year-end amounts typed
  in and saved per book

FastAPI and accounts (following led-editor)
- Replace the stdlib server with a FastAPI app (src/cashbook_app) run by
  uvicorn; dependencies in Pipfile
- Cookie sessions with bcrypt passwords, first-run admin setup or
  BOOTSTRAP_ADMIN_*, invites (link or email), sign-in throttling,
  password change that signs out other sessions
- Users page for administrators: rename, reset password, promote or
  demote, delete, list and revoke invites; last admin is protected
- Replaces the shared CASHBOOK_PASSWORD basic auth; AUTH_* settings in
  .env (see .env.example)
- Docker image uses a venv with system site packages for python3-uno
- pytest suite for auth, user management, imports, GST and tax figures

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:43:18 +13:00

51 lines
2.0 KiB
Python

import pytest
from fastapi.testclient import TestClient
CSV_HEADER = "Type,Details,Particulars,Code,Reference,Amount,Date,ForeignCurrencyAmount,ConversionCharge\n"
SAMPLE_CSV = CSV_HEADER + (
"Bank Fee,Monthly A/C Fee,,,,-8.50,30/04/2026,,\n"
"Visa Purchase,4835-****-****-7294 Df,,Jaycar Chris,,-115.00,13/04/2026,,\n"
"Direct Credit,Client Ltd,Inv 101,,,1150.00,20/04/2026,,\n"
"Transfer,01-0822-0082180-30,Credit,Transfer,123,500.00,02/05/2026,,\n"
"Visa Purchase,4835-****-****-7294 If, 0.58,Hetzner.Com, 0.07,-5.53,06/05/2026,EUR 3.20 converted at 0.58,\n"
)
def make_client(tmp_path, monkeypatch, **env):
"""A TestClient for a fresh app using tmp_path as the data folder."""
defaults = {"AUTH_ENABLED": "true", "AUTH_REGISTER_OPEN": "true", "AUTH_INVITE_ONLY": "true"}
for k in ("BOOTSTRAP_ADMIN_USERNAME", "BOOTSTRAP_ADMIN_PASSWORD", "CASHBOOK_STATEMENTS",
"CASHBOOK_ALLOWED_HOSTS", "PUBLIC_BASE_URL", "SMTP_HOST"):
monkeypatch.delenv(k, raising=False)
monkeypatch.setenv("CASHBOOK_DATA", str(tmp_path))
monkeypatch.setenv("HOME", str(tmp_path / "home")) # so ~/Downloads/anz isn't listed
for k, v in {**defaults, **env}.items():
monkeypatch.setenv(k, v)
from cashbook_app.db import session
from cashbook_app.main import create_app
from cashbook_app.services import accounts
session.reset_engine()
accounts._failures.clear()
return TestClient(create_app())
@pytest.fixture
def client(tmp_path, monkeypatch):
with make_client(tmp_path, monkeypatch) as c:
yield c
@pytest.fixture
def admin(client):
"""client signed in as the first (admin) account."""
r = client.post("/api/auth/register", json={"username": "admin", "password": "admin-pass-1"})
assert r.status_code == 200, r.text
return client
def invite(client, **body):
r = client.post("/api/users/invites", json=body)
assert r.status_code == 200, r.text
return r.json()["invite_url"].split("invite=")[1]