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.
This commit is contained in:
parent
e42b27897c
commit
59eceb6b48
@ -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/<repo>`` for a client; returns the repo name.
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user