PaiGram/tests/unit/test_hyperion_bbs.py

73 lines
2.4 KiB
Python
Raw Normal View History

2022-10-08 00:59:08 +00:00
"""Test Url
https://bbs.mihoyo.com/ys/article/29023709
"""
import logging
import pytest
import pytest_asyncio
from bs4 import BeautifulSoup
from flaky import flaky
2022-12-10 12:37:43 +00:00
from modules.apihelper.client.components.hyperion import Hyperion
from modules.apihelper.models.genshin.hyperion import PostInfo
2022-10-08 00:59:08 +00:00
LOGGER = logging.getLogger(__name__)
@pytest_asyncio.fixture
async def hyperion():
_hyperion = Hyperion()
yield _hyperion
await _hyperion.close()
# noinspection PyShadowingNames
@pytest.mark.asyncio
@flaky(3, 1)
async def test_get_post_info(hyperion):
post_info = await hyperion.get_post_info(2, 29023709)
assert post_info
assert isinstance(post_info, PostInfo)
assert post_info["post"]["post"]["post_id"] == "29023709"
2022-10-08 00:59:08 +00:00
assert post_info.post_id == 29023709
assert post_info["post"]["post"]["subject"] == "《原神》长期项目启动·概念PV"
assert post_info.subject == "《原神》长期项目启动·概念PV"
assert len(post_info["post"]["post"]["images"]) == 1
post_soup = BeautifulSoup(post_info["post"]["post"]["content"], features="html.parser")
assert post_soup.find_all("p")
2022-10-08 00:59:08 +00:00
2023-02-18 07:41:10 +00:00
# noinspection PyShadowingNames
@pytest.mark.asyncio
@flaky(3, 1)
async def test_get_video_post_info(hyperion):
post_info = await hyperion.get_post_info(2, 33846648)
assert post_info
assert isinstance(post_info, PostInfo)
assert post_info["post"]["post"]["post_id"] == "33846648"
assert post_info.post_id == 33846648
assert post_info["post"]["post"]["subject"] == "当然是原神了"
assert post_info.subject == "当然是原神了"
assert len(post_info.video_urls) == 1
2022-10-08 00:59:08 +00:00
# noinspection PyShadowingNames
@pytest.mark.asyncio
@flaky(3, 1)
async def test_get_images_by_post_id(hyperion):
post_images = await hyperion.get_images_by_post_id(2, 29023709)
assert len(post_images) == 1
# noinspection PyShadowingNames
@pytest.mark.asyncio
@flaky(3, 1)
async def test_official_recommended_posts(hyperion):
official_recommended_posts = await hyperion.get_official_recommended_posts(2)
assert len(official_recommended_posts["list"]) > 0
for data_list in official_recommended_posts["list"]:
post_info = await hyperion.get_post_info(2, data_list["post_id"])
assert post_info.post_id
assert post_info.subject
LOGGER.info("official_recommended_posts: post_id[%s] subject[%s]", post_info.post_id, post_info.subject)