🐛 又忘记改单测了(

This commit is contained in:
suyiiyii 2024-10-13 21:30:08 +08:00
parent f3d8b7d5bc
commit b6ba904a68
Signed by: suyiiyii
GPG Key ID: 044704CB29B8AD85
4 changed files with 161 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import json import json
from typing import cast from typing import cast
from datetime import datetime from datetime import datetime
from unittest.mock import patch
import pytest import pytest
from nonebug import App from nonebug import App
@ -33,10 +34,11 @@ async def test_cookie(app: App, init_scheduler):
cookies = await config.get_cookie(site_name=site.name) cookies = await config.get_cookie(site_name=site.name)
assert len(cookies) == 1 assert len(cookies) == 1
with patch("nonebot_bison.platform.weibo.WeiboSite._get_current_user_name") as mock:
# 添加用户cookie mock.return_value = "test_name"
await client_mgr.add_user_cookie(json.dumps({"test_cookie": "1"})) # 添加用户cookie
await client_mgr.add_user_cookie(json.dumps({"test_cookie": "2"})) await client_mgr.add_user_cookie(json.dumps({"test_cookie": "1"}))
await client_mgr.add_user_cookie(json.dumps({"test_cookie": "2"}))
cookies = await config.get_cookie(site_name=site.name) cookies = await config.get_cookie(site_name=site.name)
assert len(cookies) == 3 assert len(cookies) == 3
@ -67,7 +69,10 @@ async def test_cookie(app: App, init_scheduler):
cats=[], cats=[],
tags=[], tags=[],
) )
await client_mgr.add_user_cookie(json.dumps({"test_cookie": "3"}))
with patch("nonebot_bison.platform.weibo.WeiboSite._get_current_user_name") as mock:
mock.return_value = "test_name"
await client_mgr.add_user_cookie(json.dumps({"test_cookie": "3"}))
cookies = await config.get_cookie(site_name=site.name, is_anonymous=False) cookies = await config.get_cookie(site_name=site.name, is_anonymous=False)
# 多个target多个cookie # 多个target多个cookie

View File

@ -0,0 +1,138 @@
{
"ok": 1,
"data": {
"config": {
"code": 11000,
"text": "<p>非微博会员不可多次修改昵称。自2024年1月1日至今您已成功修改1次目前无法继续修改。如需继续改名可开通微博会员。</p>",
"guide": {
"title": "开通微博会员",
"desc": "<p>本年度<span>增加最多8次</span>改名机会</p>",
"button_text": "开通会员",
"button_url": "https://m.weibo.cn/c/upgrade"
}
},
"data": {
"config": {
"title": "修改昵称次数扣除明细"
}
},
"user": {
"id": 114514,
"idstr": "114514",
"class": 1,
"screen_name": "suyiiyii",
"name": "suyiiyii",
"province": "44",
"city": "1",
"location": "广东 广州",
"description": "",
"url": "",
"profile_image_url": "https://tvax1.sinaimg.cn/default/images/default_avatar_male_50.gif?KID=imgbed,tva&Expires=1728833531&ssig=jURhYal3%2BR",
"light_ring": false,
"profile_url": "u/114514",
"domain": "",
"weihao": "",
"gender": "m",
"followers_count": 1,
"followers_count_str": "1",
"friends_count": 6,
"pagefriends_count": 0,
"statuses_count": 1,
"video_status_count": 0,
"video_play_count": 0,
"super_topic_not_syn_count": 0,
"favourites_count": 0,
"created_at": "Tue Sep 03 00:07:59 +0800 2024",
"following": false,
"allow_all_act_msg": false,
"geo_enabled": true,
"verified": false,
"verified_type": -1,
"remark": "",
"insecurity": {
"sexual_content": false
},
"ptype": 0,
"allow_all_comment": true,
"avatar_large": "https://tvax1.sinaimg.cn/default/images/default_avatar_male_180.gif?KID=imgbed,tva&Expires=1728833531&ssig=cornnikInk",
"avatar_hd": "https://tvax1.sinaimg.cn/default/images/default_avatar_male_180.gif?KID=imgbed,tva&Expires=1728833531&ssig=cornnikInk",
"verified_reason": "",
"verified_trade": "",
"verified_reason_url": "",
"verified_source": "",
"verified_source_url": "",
"follow_me": false,
"like": false,
"like_me": false,
"online_status": 0,
"bi_followers_count": 0,
"lang": "zh-cn",
"star": 0,
"mbtype": 0,
"mbrank": 0,
"svip": 0,
"vvip": 0,
"mb_expire_time": 0,
"block_word": 0,
"block_app": 0,
"chaohua_ability": 0,
"brand_ability": 0,
"nft_ability": 0,
"vplus_ability": 0,
"wenda_ability": 0,
"live_ability": 0,
"gongyi_ability": 0,
"paycolumn_ability": 0,
"newbrand_ability": 0,
"ecommerce_ability": 0,
"hardfan_ability": 0,
"wbcolumn_ability": 0,
"interaction_user": 0,
"audio_ability": 0,
"place_ability": 0,
"credit_score": 80,
"user_ability": 0,
"urank": 0,
"story_read_state": -1,
"vclub_member": 0,
"is_teenager": 0,
"is_guardian": 0,
"is_teenager_list": 0,
"pc_new": 0,
"special_follow": false,
"planet_video": 0,
"video_mark": 0,
"live_status": 0,
"user_ability_extend": 0,
"status_total_counter": {
"total_cnt": 0,
"repost_cnt": 0,
"comment_cnt": 0,
"like_cnt": 0,
"comment_like_cnt": 0
},
"video_total_counter": {
"play_cnt": -1
},
"brand_account": 0,
"hongbaofei": 0,
"green_mode": 0,
"urisk": 524288,
"unfollowing_recom_switch": 1,
"block": 0,
"block_me": 0,
"avatar_type": 0,
"is_big": 0,
"auth_status": 1,
"auth_realname": null,
"auth_career": null,
"auth_career_name": null,
"show_auth": 0,
"is_auth": 0,
"is_punish": 0,
"like_display": 0
},
"submit": true,
"having_count": 0
}
}

View File

@ -217,3 +217,11 @@ async def test_parse_target(weibo: "Weibo"):
assert res == "6441489862" assert res == "6441489862"
with pytest.raises(Platform.ParseTargetException): with pytest.raises(Platform.ParseTargetException):
await weibo.parse_target("https://weibo.com/arknights") await weibo.parse_target("https://weibo.com/arknights")
@respx.mock
async def test_get_cookie_name(weibo: "Weibo"):
router = respx.get("https://m.weibo.cn/setup/nick/detail")
router.mock(return_value=Response(200, json=get_json("weibo_get-cookie-name.json")))
name = await weibo.site.get_cookie_name("{}")
assert name == "weibo: [suyiiyii]"

View File

@ -134,7 +134,7 @@ async def test_add_cookie(app: App):
ctx.receive_event(bot, event_4_ok) ctx.receive_event(bot, event_4_ok)
ctx.should_pass_rule() ctx.should_pass_rule()
ctx.should_call_send( ctx.should_call_send(
event_4_ok, '已添加 Cookie: {"cookie": "test"} 到平台 weibo\n请使用“关联cookie”为 Cookie 关联订阅', True event_4_ok, "已添加 Cookie: weibo: [suyiiyii] 到平台 weibo\n请使用“关联cookie”为 Cookie 关联订阅", True
) )
async with app.test_matcher(add_cookie_target_matcher) as ctx: async with app.test_matcher(add_cookie_target_matcher) as ctx:
@ -179,7 +179,9 @@ async def test_add_cookie(app: App):
) )
ctx.receive_event(bot, event_2_ok) ctx.receive_event(bot, event_2_ok)
ctx.should_pass_rule() ctx.should_pass_rule()
ctx.should_call_send(event_2_ok, '请选择一个 Cookie已关联的 Cookie 不会显示\n1. weibo.com [{"cookie":]', True) ctx.should_call_send(
event_2_ok, "请选择一个 Cookie已关联的 Cookie 不会显示\n1. weibo.com weibo: [suyiiyii]", True
)
event_3_err = fake_private_message_event( event_3_err = fake_private_message_event(
message=Message("2"), sender=fake_superuser, to_me=True, user_id=fake_superuser.user_id message=Message("2"), sender=fake_superuser, to_me=True, user_id=fake_superuser.user_id
) )
@ -191,7 +193,7 @@ async def test_add_cookie(app: App):
) )
ctx.receive_event(bot, event_3_ok) ctx.receive_event(bot, event_3_ok)
ctx.should_pass_rule() ctx.should_pass_rule()
ctx.should_call_send(event_3_ok, '已关联 Cookie: weibo.com [{"cookie":] 到订阅 weibo.com weibo_id', True) ctx.should_call_send(event_3_ok, "已关联 Cookie: weibo.com weibo: [suyiiyii] 到订阅 weibo.com weibo_id", True)
async def test_add_cookie_target_no_target(app: App, mocker: MockerFixture): async def test_add_cookie_target_no_target(app: App, mocker: MockerFixture):