feat(suite): confirm AI writing cost before request
This commit is contained in:
@@ -8,6 +8,9 @@ from app import cmhub_models
|
||||
|
||||
|
||||
class CMHubModelDisplayTests(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
cmhub_models.clear_model_catalog_cache()
|
||||
|
||||
def test_alias_label_prefers_display_name_tier_and_points(self):
|
||||
label = cmhub_models.alias_label(
|
||||
{
|
||||
@@ -44,6 +47,72 @@ class CMHubModelDisplayTests(unittest.TestCase):
|
||||
self.assertIn("生图别名 image-hd", summary)
|
||||
self.assertIn("扣点以返回结果为准", summary)
|
||||
|
||||
def test_catalog_price_only_accepts_one_unconditional_matching_vision_model(self):
|
||||
models = [
|
||||
{
|
||||
"alias": "vision-standard",
|
||||
"operation_type": "vision",
|
||||
"requires_image": True,
|
||||
"pricing_status": "priced",
|
||||
"prices": [{"points_cost": 2}],
|
||||
}
|
||||
]
|
||||
|
||||
cmhub_models.cache_model_catalog("https://CMHUB.example.com/", models, now=100)
|
||||
cached = cmhub_models.cached_model_catalog(
|
||||
"https://cmhub.example.com",
|
||||
"vision-standard",
|
||||
now=120,
|
||||
)
|
||||
|
||||
self.assertEqual("2", cmhub_models.format_points_cost(
|
||||
cmhub_models.unambiguous_points_cost(
|
||||
cached,
|
||||
"vision-standard",
|
||||
"vision",
|
||||
requires_image=True,
|
||||
)
|
||||
))
|
||||
|
||||
def test_catalog_price_rejects_conditional_missing_or_ambiguous_prices(self):
|
||||
base = {
|
||||
"alias": "vision-standard",
|
||||
"operation_type": "vision",
|
||||
"requires_image": True,
|
||||
"pricing_status": "priced",
|
||||
}
|
||||
cases = [
|
||||
dict(base, prices=[{"resolution": "1K", "points_cost": 2}]),
|
||||
dict(base, prices=[{"points_cost": 2}, {"points_cost": 3}]),
|
||||
dict(base, pricing_status="unpriced", prices=[{"points_cost": 2}]),
|
||||
dict(base, requires_image=False, prices=[{"points_cost": 2}]),
|
||||
dict(base, prices=[{}]),
|
||||
]
|
||||
for model in cases:
|
||||
with self.subTest(model=model):
|
||||
self.assertIsNone(
|
||||
cmhub_models.unambiguous_points_cost(
|
||||
[model],
|
||||
"vision-standard",
|
||||
"vision",
|
||||
requires_image=True,
|
||||
)
|
||||
)
|
||||
|
||||
cmhub_models.cache_model_catalog(
|
||||
"https://cmhub.example.com",
|
||||
[dict(base, prices=[{"points_cost": 2}])],
|
||||
now=100,
|
||||
)
|
||||
self.assertIsNone(
|
||||
cmhub_models.cached_model_catalog(
|
||||
"https://cmhub.example.com",
|
||||
"vision-standard",
|
||||
max_age_seconds=20,
|
||||
now=121,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user