添加单元测试 test_game

添加单元测试 `test_game` 以便提前发现收藏夹失效问题
删除 `service.game` 无效注释
This commit is contained in:
洛水.山岭居室 2022-05-30 17:21:21 +08:00
parent 1e94d3197e
commit 19cf972094
2 changed files with 38 additions and 1 deletions

View File

@ -18,7 +18,7 @@ class GetGameInfo:
return url_info[-1]
async def get_post_id(collection_id: int) -> int:
post_full_in_collection = await self.mihoyo.get_post_full_in_collection(collection_id) # 642956
post_full_in_collection = await self.mihoyo.get_post_full_in_collection(collection_id)
if post_full_in_collection.error:
await self.cache.set_str_list(qname, [""], 3600)
return -1

37
test/service/test_game.py Normal file
View File

@ -0,0 +1,37 @@
import unittest
from unittest import IsolatedAsyncioTestCase
from model.genshinhelper import Mihoyo
class TestGame(IsolatedAsyncioTestCase):
def setUp(self):
self.mihoyo = Mihoyo()
async def test_get_strategy(self):
test_collection_id_list = [839176, 839179, 839181]
test_result = ["温迪", "胡桃", "雷电将军"]
async def get_post_id(_collection_id: int, character_name: str) -> str:
post_full_in_collection = await self.mihoyo.get_post_full_in_collection(_collection_id)
if post_full_in_collection.error:
raise RuntimeError(f"获取收藏信息错误,错误信息为:{post_full_in_collection.message}")
for post_data in post_full_in_collection.data["posts"]:
topics = post_data["topics"]
for topic in topics:
if character_name == topic["name"]:
return topic["name"]
return ""
for index in range(len(test_collection_id_list)):
second = test_result[index]
first = await get_post_id(test_collection_id_list[index], second)
self.assertEqual(first, second)
async def asyncTearDown(self) -> None:
await self.mihoyo.close()
if __name__ == "__main__":
unittest.main("TestGame")