Refact: Tenant api (#14288)

### What problem does this PR solve?

Refact: Tenant api

### Type of change

- [x] Refactoring
This commit is contained in:
Magicbook1108
2026-04-22 20:00:32 +08:00
committed by GitHub
parent 1434f8ade8
commit d1c62fc19d
5 changed files with 96 additions and 56 deletions

View File

@@ -180,7 +180,7 @@ def _load_tenant_module(monkeypatch):
common_pkg.settings = settings_mod
sys.modules.pop("test_tenant_app_unit_module", None)
module_path = repo_root / "api" / "apps" / "tenant_app.py"
module_path = repo_root / "api" / "apps" / "restful_apis" / "tenant_api.py"
spec = importlib.util.spec_from_file_location("test_tenant_app_unit_module", module_path)
module = importlib.util.module_from_spec(spec)
module.manager = _DummyManager()
@@ -268,20 +268,21 @@ def test_rm_and_tenant_list_matrix_unit(monkeypatch):
module = _load_tenant_module(monkeypatch)
module.current_user.id = "outsider"
res = module.rm("tenant-1", "user-2")
_set_request_json(monkeypatch, module, {"user_id": "user-2"})
res = _run(module.rm("tenant-1"))
assert res["code"] == module.RetCode.AUTHENTICATION_ERROR, res
assert res["message"] == "No authorization.", res
module.current_user.id = "tenant-1"
deleted = []
monkeypatch.setattr(module.UserTenantService, "filter_delete", lambda conditions: deleted.append(conditions) or True)
res = module.rm("tenant-1", "user-2")
res = _run(module.rm("tenant-1"))
assert res["code"] == 0, res
assert res["data"] is True, res
assert deleted, "filter_delete should be called"
monkeypatch.setattr(module.UserTenantService, "filter_delete", lambda _conditions: (_ for _ in ()).throw(RuntimeError("rm boom")))
res = module.rm("tenant-1", "user-2")
res = _run(module.rm("tenant-1"))
assert res["code"] == 100, res
assert "rm boom" in res["message"], res