furtka-gateway/tests/test_accounts.py

29 lines
985 B
Python
Raw Permalink Normal View History

from control_plane import accounts
from control_plane.db import Database
def test_ensure_single_tenant_account_is_idempotent(tmp_path):
db = Database(db_path=tmp_path / "gateway.db")
account_id1 = accounts.ensure_single_tenant_account(db, box_limit=5, route_limit_per_box=5)
account_id2 = accounts.ensure_single_tenant_account(db, box_limit=5, route_limit_per_box=5)
assert account_id1 == account_id2 == accounts.SINGLE_TENANT_ACCOUNT_ID
rows = db.query_all("SELECT id FROM accounts")
assert len(rows) == 1
def test_get_account(tmp_path):
db = Database(db_path=tmp_path / "gateway.db")
account_id = accounts.ensure_single_tenant_account(db, box_limit=7, route_limit_per_box=3)
row = accounts.get_account(db, account_id)
assert row["box_limit"] == 7
assert row["route_limit_per_box"] == 3
def test_get_account_missing(tmp_path):
db = Database(db_path=tmp_path / "gateway.db")
assert accounts.get_account(db, "nope") is None