feat: 接入远程订阅策略门禁 T-705
Tests / Python 3.11 / Windows (push) Has been cancelled

This commit is contained in:
chengma
2026-07-28 15:42:19 +08:00
parent 593c6f77cb
commit df9da63841
15 changed files with 925 additions and 73 deletions
+34 -2
View File
@@ -42,6 +42,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
"account": {"display_name": "主账号"},
"plan": {"code": "pro", "display_name": "专业版"},
"status": "active",
"real_entitlement_allowed": True,
"expires_at": "2026-08-20T23:59:59+08:00",
"grace_expires_at": None,
"manage_url": "https://cm.example.com/user/subscriptions/cmshopee",
@@ -79,6 +80,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
"account": {"display_name": "新账号"},
"plan": {"display_name": "测试套餐"},
"status": "active",
"real_entitlement_allowed": True,
"expires_at": "2026-08-20T23:59:59+08:00",
}
@@ -104,6 +106,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
"account": {"display_name": "主账号"},
"plan": {"display_name": "专业版"},
"status": "grace",
"real_entitlement_allowed": True,
"expires_at": "2026-08-20T23:59:59+08:00",
"grace_expires_at": "2026-08-23T23:59:59+08:00",
}
@@ -118,6 +121,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
"account": {"display_name": "主账号"},
"plan": {"display_name": "专业版"},
"status": "expired",
"real_entitlement_allowed": False,
"expires_at": "2026-08-20T23:59:59+08:00",
"manage_url": "https://cm.example.com/user/subscriptions/cmshopee",
}
@@ -130,7 +134,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
expired.manage_url,
)
def test_legacy_404_keeps_existing_workflows_available(self):
def test_legacy_404_does_not_claim_real_entitlement(self):
with self.make_temp_dir() as temp_dir:
def request_json(*args, **kwargs):
raise ai.CMHubError("not_found", "接口不存在", status=404)
@@ -141,7 +145,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
)
self.assertEqual(subscription.STATUS_LEGACY, result.state)
self.assertTrue(result.allows_product_workflows)
self.assertFalse(result.allows_product_workflows)
self.assertFalse(result.interface_available)
def test_auth_error_and_network_failure_have_different_states(self):
@@ -180,6 +184,7 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
"account": {"display_name": "主账号"},
"plan": {"display_name": "专业版"},
"status": "required",
"real_entitlement_allowed": False,
"manage_url": "https://other.example.com/account",
}
@@ -187,6 +192,33 @@ class SubscriptionTests(TempDirMixin, unittest.TestCase):
self.assertEqual(subscription.STATUS_REQUIRED, result.state)
self.assertEqual("", result.manage_url)
def test_real_entitlement_field_is_required_and_consistent(self):
with self.make_temp_dir() as temp_dir:
config = self._config(temp_dir)
common = {
"product_code": "cmshopee",
"account": {"display_name": "主账号"},
"plan": {"display_name": "专业版"},
"status": "active",
"expires_at": "2026-08-20T23:59:59+08:00",
}
missing = subscription.check_status(
config,
request_json=lambda *args, **kwargs: dict(common),
)
inconsistent = subscription.check_status(
config,
request_json=lambda *args, **kwargs: {
**common,
"real_entitlement_allowed": False,
},
)
self.assertEqual(subscription.STATUS_UNAVAILABLE, missing.state)
self.assertEqual(subscription.STATUS_UNAVAILABLE, inconsistent.state)
self.assertFalse(missing.allows_product_workflows)
if __name__ == "__main__":
unittest.main()