diff --git a/tests/.env.example b/tests/.env.example index 60a0511..c310ba2 100644 --- a/tests/.env.example +++ b/tests/.env.example @@ -2,6 +2,7 @@ COOKIES= ACCOUNT_ID= GENSHIN_PLAYER_ID= STARRAIL_PLAYER_ID= +# REGION= # STOKEN= # LOGIN_TICKET= # TEST_BUILD= \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 86fffb5..ba07001 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ from dotenv import load_dotenv from simnet.client.cookies import Cookies from simnet.utils.cookies import parse_cookie +from simnet.utils.enum_ import Region env_path = Path(".env") if env_path.exists(): @@ -61,6 +62,14 @@ def account_id() -> int: # skipcq: PY-D0003 return int(_account_id) +@pytest.fixture(scope="session") +def region() -> Region: # skipcq: PY-D0003 + _region = os.environ.get("REGION") + if not _region: + return Region.CHINESE + return Region(_region) + + @pytest.fixture(scope="session") def stoken() -> Optional[str]: # skipcq: PY-D0003 _stoken = os.environ.get("STOKEN") diff --git a/tests/test_auth_client.py b/tests/test_auth_client.py index c590c11..e0c1ec2 100644 --- a/tests/test_auth_client.py +++ b/tests/test_auth_client.py @@ -12,11 +12,11 @@ if TYPE_CHECKING: @pytest_asyncio.fixture -async def auth_client(account_id: int, cookies: "Cookies"): +async def auth_client(account_id: int, region: "Region", cookies: "Cookies"): async with AuthClient( cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance @@ -33,6 +33,11 @@ class TestAuthClient: @staticmethod async def test_get_stoken_by_login_ticket(auth_client: "AuthClient", login_ticket: str, account_id: int): + if auth_client.region != Region.CHINESE: + pytest.skip( + "Test case test_get_stoken_by_login_ticket skipped:" + "This method is only available for the Chinese region." + ) if login_ticket is None: pytest.skip("Test case test_get_stoken_by_login_ticket skipped: Parameter login_ticket is None") stoken = await auth_client.get_stoken_by_login_ticket(login_ticket, account_id) @@ -40,6 +45,11 @@ class TestAuthClient: @staticmethod async def test_get_cookie_token_by_stoken(auth_client: "AuthClient", stoken: str, account_id: int): + if auth_client.region != Region.CHINESE: + pytest.skip( + "Test case test_get_cookie_token_by_stoken skipped:" + "This method is only available for the Chinese region." + ) if stoken is None: pytest.skip("Test case test_get_cookie_token_by_stoken skipped: Parameter stoken is None") cookie_token = await auth_client.get_cookie_token_by_stoken(stoken, account_id) @@ -47,20 +57,28 @@ class TestAuthClient: @staticmethod async def test_get_ltoken_by_stoken(auth_client: "AuthClient", stoken: str, account_id: int): + if auth_client.region != Region.CHINESE: + pytest.skip( + "Test case test_get_ltoken_by_stoken skipped:This method is only available for the Chinese region." + ) if stoken is None: pytest.skip("Test case test_get_ltoken_by_stoken skipped: Parameter stoken is None") ltoken = await auth_client.get_ltoken_by_stoken(stoken, account_id) assert ltoken is not None @staticmethod - async def test_get_authkey_by_stoken(stoken: str, account_id: int, genshin_player_id: int): + async def test_get_authkey_by_stoken(stoken: str, account_id: int, region: "Region", genshin_player_id: int): + if auth_client.region != Region.CHINESE: + pytest.skip( + "Test case test_get_authkey_by_stoken skipped:This method is only available for the Chinese region." + ) if stoken is None: pytest.skip("Test case test_get_authkey_by_stoken skipped: Parameter stoken is None") async with AuthClient( cookies={"stoken": stoken}, player_id=genshin_player_id, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: authkey = await client_instance.get_authkey_by_stoken( "hk4e_cn", recognize_genshin_server(genshin_player_id), "webview_gacha" diff --git a/tests/test_base_chronicle_client.py b/tests/test_base_chronicle_client.py index ade4bef..2127d70 100644 --- a/tests/test_base_chronicle_client.py +++ b/tests/test_base_chronicle_client.py @@ -4,18 +4,18 @@ 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 + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def base_chronicle_client(account_id: int, cookies: "Cookies"): +async def base_chronicle_client(account_id: int, region: "Region", cookies: "Cookies"): async with BaseChronicleClient( cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance diff --git a/tests/test_genshin.py b/tests/test_genshin.py index 5e9ee48..980dcf9 100644 --- a/tests/test_genshin.py +++ b/tests/test_genshin.py @@ -4,21 +4,20 @@ import pytest import pytest_asyncio from simnet.client.genshin import GenshinClient -from simnet.utils.enum_ import Region, Game +from simnet.utils.enum_ import Game if TYPE_CHECKING: from simnet.client.cookies import Cookies + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def genshin_client( - genshin_player_id: int, account_id: int, cookies: "Cookies" -): # skipcq: PY-D0003 # skipcq: PYL-W0621 +async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"): async with GenshinClient( player_id=genshin_player_id, cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance diff --git a/tests/test_genshin_battle_chronicle_client.py b/tests/test_genshin_battle_chronicle_client.py index e74af03..9172e91 100644 --- a/tests/test_genshin_battle_chronicle_client.py +++ b/tests/test_genshin_battle_chronicle_client.py @@ -5,19 +5,19 @@ 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 + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def genshin_client(genshin_player_id: int, account_id: int, cookies: "Cookies"): +async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"): async with GenshinBattleChronicleClient( player_id=genshin_player_id, cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance @@ -36,16 +36,12 @@ class TestGenshinBattleChronicleClient: assert isinstance(user.stats, Stats) @staticmethod - async def test_get_partial_genshin_user( - genshin_client: GenshinBattleChronicleClient, - ): + async def test_get_partial_genshin_user(genshin_client: GenshinBattleChronicleClient): user = await genshin_client.get_partial_genshin_user() assert user.stats.days_active >= 0 @staticmethod - async def test_get_genshin_characters( - genshin_client: GenshinBattleChronicleClient, - ): + async def test_get_genshin_characters(genshin_client: GenshinBattleChronicleClient): characters = await genshin_client.get_genshin_characters() assert len(characters) > 0 for character in characters: diff --git a/tests/test_genshin_calculator_client.py b/tests/test_genshin_calculator_client.py index 57a1b5a..31d3f9a 100644 --- a/tests/test_genshin_calculator_client.py +++ b/tests/test_genshin_calculator_client.py @@ -5,30 +5,32 @@ import pytest_asyncio from simnet.client.components.calculator.genshin import CalculatorClient from simnet.client.components.chronicle.genshin import GenshinBattleChronicleClient -from simnet.utils.enum_ import Region if TYPE_CHECKING: from simnet.client.cookies import Cookies + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def calculator_client(genshin_player_id: int, account_id: int, cookies: "Cookies"): +async def calculator_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"): async with CalculatorClient( player_id=genshin_player_id, cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance @pytest_asyncio.fixture -async def genshin_battle_chronicle_client(genshin_player_id: int, account_id: int, cookies: "Cookies"): +async def genshin_battle_chronicle_client( + genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies" +): async with GenshinBattleChronicleClient( player_id=genshin_player_id, cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance diff --git a/tests/test_lab_client.py b/tests/test_lab_client.py index afdedf5..e20373a 100644 --- a/tests/test_lab_client.py +++ b/tests/test_lab_client.py @@ -4,18 +4,19 @@ import pytest import pytest_asyncio from simnet.client.components.lab import LabClient -from simnet.utils.enum_ import Region, Game +from simnet.utils.enum_ import Game if TYPE_CHECKING: from simnet.client.cookies import Cookies + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def client_instance(account_id: int, cookies: "Cookies"): +async def client_instance(account_id: int, region: "Region", cookies: "Cookies"): async with LabClient( cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance diff --git a/tests/test_starrail.py b/tests/test_starrail.py index 08c463e..34109d4 100644 --- a/tests/test_starrail.py +++ b/tests/test_starrail.py @@ -4,21 +4,20 @@ import pytest import pytest_asyncio from simnet.client.starrail import StarRailClient -from simnet.utils.enum_ import Region, Game +from simnet.utils.enum_ import Game if TYPE_CHECKING: from simnet.client.cookies import Cookies + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def starrail_client( - starrail_player_id: int, account_id: int, cookies: "Cookies" -): # skipcq: PY-D0003 # skipcq: PYL-W0621 +async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"): async with StarRailClient( player_id=starrail_player_id, cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance diff --git a/tests/test_starrail_battle_chronicle_client.py b/tests/test_starrail_battle_chronicle_client.py index ebae61a..2464203 100644 --- a/tests/test_starrail_battle_chronicle_client.py +++ b/tests/test_starrail_battle_chronicle_client.py @@ -4,19 +4,19 @@ 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 + from simnet.utils.enum_ import Region @pytest_asyncio.fixture -async def starrail_client(starrail_player_id: int, account_id: int, cookies: "Cookies"): +async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"): async with StarRailBattleChronicleClient( player_id=starrail_player_id, cookies=cookies, account_id=account_id, - region=Region.CHINESE, + region=region, ) as client_instance: yield client_instance @@ -38,9 +38,7 @@ class TestStarrailBattleChronicleClient: assert notes is not None @staticmethod - async def test_get_starrail_characters( - starrail_client: "StarRailBattleChronicleClient", - ): + 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]