Skip to content

Commit 5886f21

Browse files
authored
fix(store_test): 修复商店测试时标签验证出错的问题 (#277)
* fix(store_test): 修复商店测试时标签验证出错的问题 * test: 为了在 Windows 上能正常测试 * refactor: 调整 to_jsonable_python 的使用位置
1 parent 9353245 commit 5886f21

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- 修复商店测试时标签验证出错的问题
13+
1014
## [4.0.4] - 2024-11-20
1115

1216
### Fixed

src/plugins/github/plugins/publish/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def strip_ansi(text: str | None) -> str:
4343

4444
def add_step_summary(summary: str):
4545
"""添加作业摘要"""
46-
with plugin_config.github_step_summary.open("a") as f:
46+
with plugin_config.github_step_summary.open("a", encoding="utf-8") as f:
4747
f.write(summary + "\n")
4848

4949

src/providers/validation/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
from pydantic import ValidationError
6-
from pydantic_core import ErrorDetails, to_jsonable_python
6+
from pydantic_core import ErrorDetails
77

88
from .models import (
99
AdapterPublishInfo,
@@ -61,7 +61,7 @@ def validate_info(
6161
return ValidationDict(
6262
type=publish_type,
6363
raw_data=raw_data,
64-
valid_data=to_jsonable_python(context.get("valid_data", {})),
64+
valid_data=context.get("valid_data", {}),
6565
info=info,
6666
errors=errors,
6767
)

src/providers/validation/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def homepage_validator(cls, v: str) -> str:
187187
@classmethod
188188
def tags_validator(cls, v: str | list[Any]) -> list[dict[str, str]]:
189189
if not isinstance(v, str):
190-
return v
190+
# 将值转成 Python dict,避免 model_type 报错
191+
return to_jsonable_python(v)
191192

192193
try:
193194
return load_json(v)

tests/github/publish/utils/test_validate_info_from_issue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def test_validate_info_from_issue_plugin(
100100

101101
assert result.valid
102102
assert mocked_api["homepage"].called
103-
assert plugin_config.github_step_summary.read_text() == snapshot(
103+
assert plugin_config.github_step_summary.read_text(encoding="utf-8") == snapshot(
104104
"""\
105105
# 📃 插件 project_link (1.0.0)
106106

tests/utils/store_test/test_validate_plugin.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def test_validate_plugin_with_previous(
104104
需要能够正常更新 author_id, tags 和 is_official 等信息
105105
"""
106106
from src.providers.docker_test import Metadata
107-
from src.providers.models import RegistryPlugin, StoreTestResult
107+
from src.providers.models import Color, RegistryPlugin, StoreTestResult, Tag
108108
from src.providers.store_test.validation import StorePlugin, validate_plugin
109109

110110
mock_datetime = mocker.patch("src.providers.models.datetime")
@@ -119,7 +119,7 @@ async def test_validate_plugin_with_previous(
119119
module_name="module_name",
120120
project_link="project_link",
121121
author_id=1,
122-
tags=[],
122+
tags=[Tag(label="test", color=Color("ffffff"))],
123123
is_official=True,
124124
)
125125

@@ -167,23 +167,23 @@ async def test_validate_plugin_with_previous(
167167
)
168168
)
169169

170-
assert new_plugin == snapshot(
171-
RegistryPlugin(
172-
author="he0119",
173-
desc="订阅牛客/CF/AT平台的比赛信息",
174-
homepage="https://nonebot.dev/",
175-
is_official=True,
176-
module_name="module_name",
177-
name="TREEHELP",
178-
project_link="project_link",
179-
skip_test=False,
180-
supported_adapters=None,
181-
tags=[],
182-
time="2023-09-01T00:00:00+00:00Z",
183-
type="application",
184-
valid=True,
185-
version="0.2.0",
186-
)
170+
assert new_plugin.model_dump() == snapshot(
171+
{
172+
"module_name": "module_name",
173+
"project_link": "project_link",
174+
"name": "TREEHELP",
175+
"desc": "订阅牛客/CF/AT平台的比赛信息",
176+
"author": "he0119",
177+
"homepage": "https://nonebot.dev/",
178+
"tags": [{"label": "test", "color": "#ffffff"}],
179+
"is_official": True,
180+
"type": "application",
181+
"supported_adapters": None,
182+
"valid": True,
183+
"time": "2023-09-01T00:00:00+00:00Z",
184+
"version": "0.2.0",
185+
"skip_test": False,
186+
}
187187
)
188188

189189
assert mocked_api["homepage"].called

0 commit comments

Comments
 (0)