chore: auto release commit (2026-06-19 09:53:29)
All checks were successful
技能自动化发布 / release (push) Successful in 7s
All checks were successful
技能自动化发布 / release (push) Successful in 7s
This commit is contained in:
76
tests/test_platform_dynamic.py
Normal file
76
tests/test_platform_dynamic.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""resolve_platform_key_dynamic 与 JSON 解析边界。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestResolvePlatformKeyDynamicParsing:
|
||||
def test_builtin_still_works_without_db_row(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("马士基", conn=clean_db)
|
||||
assert result.platform_key == "maersk"
|
||||
|
||||
def test_disabled_platform_returns_disabled(self, clean_db):
|
||||
from db.accounts_repo import upsert_platform
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
upsert_platform(
|
||||
clean_db,
|
||||
key="custom_off",
|
||||
display_name="Off",
|
||||
default_url="",
|
||||
)
|
||||
clean_db.execute(
|
||||
"UPDATE platforms SET enabled = 0 WHERE platform_key = ?",
|
||||
("custom_off",),
|
||||
)
|
||||
clean_db.commit()
|
||||
result = resolve_platform_key_dynamic("custom_off", conn=clean_db)
|
||||
assert result.error_code == "PLATFORM_DISABLED"
|
||||
|
||||
def test_get_platform_spec_from_db(self, clean_db):
|
||||
from db.accounts_repo import upsert_platform
|
||||
from util.platforms import get_platform_spec
|
||||
|
||||
upsert_platform(
|
||||
clean_db,
|
||||
key="jiangchang",
|
||||
display_name="匠厂后台",
|
||||
default_url="https://jc2009.com/admin/index.html",
|
||||
)
|
||||
spec = get_platform_spec("jiangchang", conn=clean_db)
|
||||
assert spec["display_name"] == "匠厂后台"
|
||||
assert spec["default_url"] == "https://jc2009.com/admin/index.html"
|
||||
|
||||
def test_malformed_aliases_json_does_not_crash(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
import time
|
||||
|
||||
now = int(time.time())
|
||||
clean_db.execute(
|
||||
"""
|
||||
INSERT INTO platforms (
|
||||
platform_key, display_name, domain, provider_code,
|
||||
default_url, aliases_json, capabilities_json,
|
||||
enabled, default_auth_strategy, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, 1, NULL, ?, ?)
|
||||
""",
|
||||
(
|
||||
"bad_alias",
|
||||
"Bad",
|
||||
"generic",
|
||||
"bad_alias",
|
||||
"",
|
||||
"not-json",
|
||||
"{}",
|
||||
now,
|
||||
now,
|
||||
),
|
||||
)
|
||||
clean_db.commit()
|
||||
result = resolve_platform_key_dynamic("bad_alias", conn=clean_db)
|
||||
assert result.platform_key == "bad_alias"
|
||||
Reference in New Issue
Block a user