From 59eceb6b48d97f12a6fb62fa7e8fe2bfcd4ee3c1 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 25 Aug 2026 11:15:40 -0500 Subject: [PATCH] gitea-saas-core#4: adapt to billing core client id rename (#16) after rebase main (#16) flattened get_client records and renamed create_client's returned identifier to 'id'. Read create_client(...)['id'] in the real-core composition test, and make _default_repo_name accept the flat record (top-level name / id) as well as the historical nested shape. 46 tests pass on top of origin/main. --- gitea_saas/intake_factory.py | 16 +++++++++++++--- tests/test_intake_factory.py | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/gitea_saas/intake_factory.py b/gitea_saas/intake_factory.py index e635d15..8a33b21 100644 --- a/gitea_saas/intake_factory.py +++ b/gitea_saas/intake_factory.py @@ -200,10 +200,20 @@ class IntakeFactory: @staticmethod def _default_repo_name(client_record: Dict[str, Any]) -> str: - """Derive a repo name from the client record (client name slug).""" - name = (client_record.get("client") or {}).get("name") or "" + """Derive a repo name from the client record (client name slug). + + Accepts both the historical nested shape (``{client: {...}}``) and + the flat record now returned by :meth:`BillingCore.get_client` + (issue #16: ``{id, name, tier, status, meta, created_at, balance}``) + -- the factory composes with whichever contract the core exposes. + """ + name = (client_record.get("client") or {}).get("name") or client_record.get("name") or "" slug = re.sub(r"[^A-Za-z0-9._-]+", "-", name.strip().lower()).strip("-") - return slug[:60] or f"client-{client_record.get('client_id')}" + cid_fallback = (client_record.get("client_id") + or client_record.get("id") + or (client_record.get("client") or {}).get("id") + or "") + return slug[:60] or f"client-{cid_fallback}" def provision_client(self, client_id: int, repo_name: Optional[str] = None) -> str: """Provision ``owner/`` for a client; returns the repo name. diff --git a/tests/test_intake_factory.py b/tests/test_intake_factory.py index f453fc6..f8144e5 100644 --- a/tests/test_intake_factory.py +++ b/tests/test_intake_factory.py @@ -509,7 +509,7 @@ def test_real_billing_core_composition(tmp_path: Path): ok, details = core.create_client("Acme Corp") assert ok - cid = details["client_id"] + cid = details["id"] assert core.credit(cid, 10_000, "idem-1")[0] is True assert factory.provision_client(cid) == "acme-corp" result = factory.submit_issue(cid, "acme-corp", "Funded with real core", "body") @@ -517,7 +517,7 @@ def test_real_billing_core_composition(tmp_path: Path): ok, details2 = core.create_client("Poor Corp") assert ok - cid2 = details2["client_id"] + cid2 = details2["id"] assert factory.provision_client(cid2) == "poor-corp" queued = factory.submit_issue(cid2, "poor-corp", "Queued", "body") assert queued["delivered"] is False and queued["reason"] == "unfunded"