mirror of
https://18126008609:longquanjian123@gitee.com/feigong123/aurask.git
synced 2026-04-19 15:00:35 +00:00
84 lines
3.3 KiB
Python
84 lines
3.3 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from aurask.app import create_app
|
|
from aurask.errors import QuotaError
|
|
|
|
|
|
class AuraskMVPTests(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self.app = create_app(None, reset=True)
|
|
|
|
def test_demo_bootstrap_creates_basic_plan_and_workspace(self) -> None:
|
|
demo = self.app.bootstrap_demo()
|
|
quota = self.app.quota.get_account(demo["tenant"]["id"])
|
|
self.assertEqual(quota["plan_code"], "basic_monthly")
|
|
self.assertEqual(quota["available_tbu"], 900)
|
|
self.assertEqual(quota["workflow_slots"], 3)
|
|
self.assertEqual(quota["knowledge_bases"], 3)
|
|
self.assertEqual(demo["workspace"]["tenant_id"], demo["tenant"]["id"])
|
|
|
|
def test_workflow_run_reserves_and_settles_tbu(self) -> None:
|
|
demo = self.app.bootstrap_demo()
|
|
run = self.app.orchestrator.run_template(
|
|
demo["tenant"]["id"],
|
|
demo["user"]["id"],
|
|
"tpl_knowledge_qa",
|
|
workspace_id=demo["workspace"]["id"],
|
|
inputs={"question": "Summarize onboarding steps"},
|
|
)
|
|
quota = self.app.quota.get_account(demo["tenant"]["id"])
|
|
self.assertEqual(run["status"], "completed")
|
|
self.assertGreater(run["actual_tbu"], 0)
|
|
self.assertEqual(quota["reserved_tbu"], 0)
|
|
self.assertLess(quota["available_tbu"], 900)
|
|
|
|
def test_tbu_package_payment_fulfills_order(self) -> None:
|
|
demo = self.app.bootstrap_demo()
|
|
order = self.app.billing.create_order(demo["tenant"]["id"], demo["user"]["id"], "tbu_1000")
|
|
payment = self.app.payments.match_trc20_payment(
|
|
demo["tenant"]["id"],
|
|
order["id"],
|
|
tx_hash="trx_hash_123",
|
|
amount_usdt=order["amount_usdt"],
|
|
confirmations=20,
|
|
)
|
|
quota = self.app.quota.get_account(demo["tenant"]["id"])
|
|
self.assertEqual(payment["status"], "matched")
|
|
self.assertEqual(self.app.store.get("orders", order["id"])["status"], "fulfilled")
|
|
self.assertEqual(quota["available_tbu"], 900 + 1100)
|
|
|
|
def test_document_upload_updates_storage(self) -> None:
|
|
demo = self.app.bootstrap_demo()
|
|
document = self.app.knowledge.upload_document(
|
|
demo["tenant"]["id"],
|
|
demo["user"]["id"],
|
|
demo["workspace"]["id"],
|
|
filename="manual.pdf",
|
|
size_bytes=1024 * 1024 * 2,
|
|
content_type="application/pdf",
|
|
content_preview="Aurask support guide",
|
|
)
|
|
quota = self.app.quota.get_account(demo["tenant"]["id"])
|
|
self.assertEqual(document["tenant_id"], demo["tenant"]["id"])
|
|
self.assertEqual(quota["used_storage_mb"], 2)
|
|
|
|
def test_insufficient_tbu_blocks_execution(self) -> None:
|
|
demo = self.app.bootstrap_demo()
|
|
quota = self.app.quota.get_account(demo["tenant"]["id"])
|
|
quota["available_tbu"] = 10
|
|
self.app.store.put("quota_accounts", demo["tenant"]["id"], quota)
|
|
with self.assertRaises(QuotaError):
|
|
self.app.orchestrator.run_template(
|
|
demo["tenant"]["id"],
|
|
demo["user"]["id"],
|
|
"tpl_customer_support",
|
|
workspace_id=demo["workspace"]["id"],
|
|
inputs={"question": "Very long request"},
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|