mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
🐛 替换为pyd兼容性写法
This commit is contained in:
parent
36b2c2c3aa
commit
2a49effbba
@ -1,9 +1,10 @@
|
||||
from typing import Any
|
||||
from functools import partial
|
||||
|
||||
from yarl import URL
|
||||
from httpx import AsyncClient
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from pydantic import Field, AnyUrl, BaseModel
|
||||
from pydantic import Field, BaseModel
|
||||
from nonebot.compat import type_validate_python
|
||||
|
||||
from ..post import Post
|
||||
@ -113,11 +114,7 @@ class Arknights(NewMessage):
|
||||
title=title,
|
||||
nickname="明日方舟游戏内公告",
|
||||
images=[data.banner_image_url] if data.banner_image_url else None,
|
||||
url=(
|
||||
url.unicode_string()
|
||||
if data.jump_link and (url := AnyUrl(data.jump_link)).scheme.startswith("http")
|
||||
else None
|
||||
),
|
||||
url=(url.human_repr() if (url := URL(data.jump_link)).scheme.startswith("http") else None),
|
||||
timestamp=data.updated_at,
|
||||
compress=True,
|
||||
)
|
||||
|
@ -139,4 +139,4 @@ defineConstant = { PYDANTIC_V2 = true }
|
||||
[[tool.poetry.source]]
|
||||
name = "offical-source"
|
||||
url = "https://pypi.org/simple/"
|
||||
priority = "primary"
|
||||
priority = "primary"
|
||||
|
@ -4,6 +4,7 @@ import respx
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
from nonebot.compat import model_dump, type_validate_python
|
||||
|
||||
from .utils import get_file, get_json
|
||||
|
||||
@ -51,18 +52,21 @@ async def test_url_parse(app: App):
|
||||
cid_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletin/1")
|
||||
|
||||
def make_bulletin_obj(jump_link: str):
|
||||
return BulletinData.model_validate({
|
||||
"cid": "1",
|
||||
"displayType": 1,
|
||||
"title": "title",
|
||||
"category": 1,
|
||||
"header": "header",
|
||||
"content": "content",
|
||||
"jumpLink": jump_link,
|
||||
"bannerImageUrl": "https://www.baidu.com",
|
||||
"displayTime": "2021-08-01",
|
||||
"updatedAt": 1627795200,
|
||||
})
|
||||
return type_validate_python(
|
||||
BulletinData,
|
||||
{
|
||||
"cid": "1",
|
||||
"displayType": 1,
|
||||
"title": "title",
|
||||
"category": 1,
|
||||
"header": "header",
|
||||
"content": "content",
|
||||
"jumpLink": jump_link,
|
||||
"bannerImageUrl": "https://www.baidu.com",
|
||||
"displayTime": "2021-08-01",
|
||||
"updatedAt": 1627795200,
|
||||
},
|
||||
)
|
||||
|
||||
def make_bulletin_list_item_obj():
|
||||
return BulletinListItem(
|
||||
@ -75,7 +79,7 @@ async def test_url_parse(app: App):
|
||||
)
|
||||
|
||||
def make_response(b: BulletinData):
|
||||
return Response(200, json=ArkBulletinResponse(code=0, msg="", data=b).model_dump(by_alias=True))
|
||||
return Response(200, json=model_dump(ArkBulletinResponse(code=0, msg="", data=b), by_alias=True))
|
||||
|
||||
b1 = make_bulletin_obj("")
|
||||
assert b1.jump_link == ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user