mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-24 23:33:32 +00:00
✅ Add region-related code to unit tests
This commit is contained in:
parent
a1b78dcb14
commit
834ce9b8ff
@ -2,6 +2,7 @@ COOKIES=
|
||||
ACCOUNT_ID=
|
||||
GENSHIN_PLAYER_ID=
|
||||
STARRAIL_PLAYER_ID=
|
||||
# REGION=
|
||||
# STOKEN=
|
||||
# LOGIN_TICKET=
|
||||
# TEST_BUILD=
|
@ -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")
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user