mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-21 13:48:20 +00:00
✅ Update test
- Test multiple clients - Load testing configuration file using load_dotenv - Add `requirements.dev.txt` file
This commit is contained in:
parent
72542c9676
commit
2a86d10640
3
requirements.dev.txt
Normal file
3
requirements.dev.txt
Normal file
@ -0,0 +1,3 @@
|
||||
pytest
|
||||
pytest-asyncio
|
||||
python-dotenv
|
4
tests/.env.example
Normal file
4
tests/.env.example
Normal file
@ -0,0 +1,4 @@
|
||||
COOKIES=
|
||||
ACCOUNT_ID=
|
||||
GENSHIN_PLAYER_ID=
|
||||
STARRAIL_PLAYER_ID=
|
@ -1,14 +1,17 @@
|
||||
import asyncio
|
||||
import os
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from simnet.client.cookies import Cookies
|
||||
from simnet.client.starrail import StarRailClient
|
||||
from simnet.utils.cookies import parse_cookie
|
||||
from simnet.utils.enum_ import Region
|
||||
|
||||
env_path = Path(".env")
|
||||
if env_path.exists():
|
||||
load_dotenv()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@ -34,10 +37,18 @@ def cookies() -> "Cookies": # skipcq: PY-D0003
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def player_id() -> int: # skipcq: PY-D0003
|
||||
_player_id = os.environ.get("PLAYER_ID")
|
||||
def genshin_player_id() -> int: # skipcq: PY-D0003
|
||||
_player_id = os.environ.get("GENSHIN_PLAYER_ID")
|
||||
if not _player_id:
|
||||
pytest.exit("No player id set", 1)
|
||||
pytest.exit("No genshin player id set", 1)
|
||||
return int(_player_id)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def starrail_player_id() -> int: # skipcq: PY-D0003
|
||||
_player_id = os.environ.get("STARRAIL_PLAYER_ID")
|
||||
if not _player_id:
|
||||
pytest.exit("No genshin player id set", 1)
|
||||
return int(_player_id)
|
||||
|
||||
|
||||
@ -45,18 +56,5 @@ def player_id() -> int: # skipcq: PY-D0003
|
||||
def account_id() -> int: # skipcq: PY-D0003
|
||||
_account_id = os.environ.get("ACCOUNT_ID")
|
||||
if not _account_id:
|
||||
pytest.exit("No player id set", 1)
|
||||
pytest.exit("No account id set", 1)
|
||||
return int(_account_id)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def starrail_client( # skipcq: PY-D0003
|
||||
player_id: int, account_id: int, cookies: "Cookies" # skipcq: PYL-W0621
|
||||
):
|
||||
async with StarRailClient(
|
||||
player_id=player_id,
|
||||
cookies=cookies,
|
||||
account_id=account_id,
|
||||
region=Region.CHINESE,
|
||||
) as client_instance:
|
||||
yield client_instance
|
||||
|
30
tests/test_base_chronicle_client.py
Normal file
30
tests/test_base_chronicle_client.py
Normal file
@ -0,0 +1,30 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from simnet.client.components.chronicle.base import BaseChronicleClient
|
||||
from simnet.utils.enum_ import Region
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from simnet.client.cookies import Cookies
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def base_chronicle_client(account_id: int, cookies: "Cookies"):
|
||||
async with BaseChronicleClient(
|
||||
cookies=cookies,
|
||||
account_id=account_id,
|
||||
region=Region.CHINESE,
|
||||
) as client_instance:
|
||||
yield client_instance
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestBaseChronicleClient:
|
||||
@staticmethod
|
||||
async def test_get_record_cards(base_chronicle_client: "BaseChronicleClient"):
|
||||
record_cards = await base_chronicle_client.get_record_cards()
|
||||
assert len(record_cards) > 0
|
||||
record_card = record_cards[0]
|
||||
assert record_card.uid
|
30
tests/test_genshin.py
Normal file
30
tests/test_genshin.py
Normal file
@ -0,0 +1,30 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from simnet.client.genshin import GenshinClient
|
||||
from simnet.utils.enum_ import Region, Game
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from simnet.client.cookies import Cookies
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def genshin_client(
|
||||
genshin_player_id: int, account_id: int, cookies: "Cookies"
|
||||
): # skipcq: PY-D0003 # skipcq: PYL-W0621
|
||||
async with GenshinClient(
|
||||
player_id=genshin_player_id,
|
||||
cookies=cookies,
|
||||
account_id=account_id,
|
||||
region=Region.CHINESE,
|
||||
) as client_instance:
|
||||
yield client_instance
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestGenshinClient:
|
||||
@staticmethod
|
||||
async def test_game(genshin_client: "GenshinClient"):
|
||||
assert genshin_client.game == Game.GENSHIN
|
43
tests/test_genshin_battle_chronicle_client.py
Normal file
43
tests/test_genshin_battle_chronicle_client.py
Normal file
@ -0,0 +1,43 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from simnet.client.components.chronicle.genshin import GenshinBattleChronicleClient
|
||||
from simnet.models.genshin.chronicle.stats import FullGenshinUserStats, Stats
|
||||
from simnet.utils.enum_ import Region
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from simnet.client.cookies import Cookies
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def genshin_client(genshin_player_id: int, account_id: int, cookies: "Cookies"):
|
||||
async with GenshinBattleChronicleClient(
|
||||
player_id=genshin_player_id,
|
||||
cookies=cookies,
|
||||
account_id=account_id,
|
||||
region=Region.CHINESE,
|
||||
) as client_instance:
|
||||
yield client_instance
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestGenshinBattleChronicleClient:
|
||||
@staticmethod
|
||||
async def test_get_battle_chronicle(genshin_client: GenshinBattleChronicleClient):
|
||||
user = await genshin_client.get_genshin_user()
|
||||
assert user.stats.days_active >= 0
|
||||
|
||||
@staticmethod
|
||||
async def test_get_full_genshin_user(genshin_client: GenshinBattleChronicleClient):
|
||||
user = await genshin_client.get_full_genshin_user()
|
||||
assert isinstance(user, FullGenshinUserStats)
|
||||
assert isinstance(user.stats, Stats)
|
||||
|
||||
@staticmethod
|
||||
async def test_get_partial_genshin_user(
|
||||
genshin_client: GenshinBattleChronicleClient,
|
||||
):
|
||||
user = await genshin_client.get_partial_genshin_user()
|
||||
assert user.stats.days_active >= 0
|
@ -1,30 +1,30 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from simnet.client.starrail import StarRailClient
|
||||
from simnet.utils.enum_ import Region, Game
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from simnet.client.starrail import StarRailClient
|
||||
from simnet.client.cookies import Cookies
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def starrail_client(
|
||||
starrail_player_id: int, account_id: int, cookies: "Cookies"
|
||||
): # skipcq: PY-D0003 # skipcq: PYL-W0621
|
||||
async with StarRailClient(
|
||||
player_id=starrail_player_id,
|
||||
cookies=cookies,
|
||||
account_id=account_id,
|
||||
region=Region.CHINESE,
|
||||
) as client_instance:
|
||||
yield client_instance
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestStarRailClient:
|
||||
@staticmethod
|
||||
async def test_get_starrail_user(starrail_client: "StarRailClient"):
|
||||
user = await starrail_client.get_starrail_user()
|
||||
assert user is not None
|
||||
assert user.stats.chest_num > 0
|
||||
assert len(user.characters) > 0
|
||||
character = user.characters[-1]
|
||||
assert character.id > 0
|
||||
|
||||
@staticmethod
|
||||
async def test_get_starrail_notes(starrail_client: "StarRailClient"):
|
||||
notes = await starrail_client.get_starrail_notes()
|
||||
assert notes is not None
|
||||
|
||||
@staticmethod
|
||||
async def test_get_starrail_characters(starrail_client: "StarRailClient"):
|
||||
characters = await starrail_client.get_starrail_characters()
|
||||
assert len(characters.avatar_list) > 0
|
||||
character = characters.avatar_list[-1]
|
||||
assert character.id > 0
|
||||
async def test_game(starrail_client: "StarRailClient"):
|
||||
assert starrail_client.game == Game.STARRAIL
|
||||
|
47
tests/test_starrail_battle_chronicle_client.py
Normal file
47
tests/test_starrail_battle_chronicle_client.py
Normal file
@ -0,0 +1,47 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from simnet.client.components.chronicle.starrail import StarRailBattleChronicleClient
|
||||
from simnet.utils.enum_ import Region
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from simnet.client.cookies import Cookies
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def starrail_client(starrail_player_id: int, account_id: int, cookies: "Cookies"):
|
||||
async with StarRailBattleChronicleClient(
|
||||
player_id=starrail_player_id,
|
||||
cookies=cookies,
|
||||
account_id=account_id,
|
||||
region=Region.CHINESE,
|
||||
) as client_instance:
|
||||
yield client_instance
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestStarrailBattleChronicleClient:
|
||||
@staticmethod
|
||||
async def test_get_starrail_user(starrail_client: "StarRailBattleChronicleClient"):
|
||||
user = await starrail_client.get_starrail_user()
|
||||
assert user is not None
|
||||
assert user.stats.chest_num > 0
|
||||
assert len(user.characters) > 0
|
||||
character = user.characters[-1]
|
||||
assert character.id > 0
|
||||
|
||||
@staticmethod
|
||||
async def test_get_starrail_notes(starrail_client: "StarRailBattleChronicleClient"):
|
||||
notes = await starrail_client.get_starrail_notes()
|
||||
assert notes is not None
|
||||
|
||||
@staticmethod
|
||||
async def test_get_starrail_characters(
|
||||
starrail_client: "StarRailBattleChronicleClient",
|
||||
):
|
||||
characters = await starrail_client.get_starrail_characters()
|
||||
assert len(characters.avatar_list) > 0
|
||||
character = characters.avatar_list[-1]
|
||||
assert character.id > 0
|
Loading…
Reference in New Issue
Block a user