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)
|
2022-10-10 11:07:28 +00:00
|
|
|
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")
|
2022-10-10 11:07:28 +00:00
|
|
|
assert post_soup.find_all("p")
|
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
|
2022-10-13 07:38:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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)
|