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