mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-22 06:17:57 +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=
|
ACCOUNT_ID=
|
||||||
GENSHIN_PLAYER_ID=
|
GENSHIN_PLAYER_ID=
|
||||||
STARRAIL_PLAYER_ID=
|
STARRAIL_PLAYER_ID=
|
||||||
|
# REGION=
|
||||||
# STOKEN=
|
# STOKEN=
|
||||||
# LOGIN_TICKET=
|
# LOGIN_TICKET=
|
||||||
# TEST_BUILD=
|
# TEST_BUILD=
|
@ -9,6 +9,7 @@ from dotenv import load_dotenv
|
|||||||
|
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
from simnet.utils.cookies import parse_cookie
|
from simnet.utils.cookies import parse_cookie
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
env_path = Path(".env")
|
env_path = Path(".env")
|
||||||
if env_path.exists():
|
if env_path.exists():
|
||||||
@ -61,6 +62,14 @@ def account_id() -> int: # skipcq: PY-D0003
|
|||||||
return int(_account_id)
|
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")
|
@pytest.fixture(scope="session")
|
||||||
def stoken() -> Optional[str]: # skipcq: PY-D0003
|
def stoken() -> Optional[str]: # skipcq: PY-D0003
|
||||||
_stoken = os.environ.get("STOKEN")
|
_stoken = os.environ.get("STOKEN")
|
||||||
|
@ -12,11 +12,11 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with AuthClient(
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
@ -33,6 +33,11 @@ class TestAuthClient:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_stoken_by_login_ticket(auth_client: "AuthClient", login_ticket: str, account_id: int):
|
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:
|
if login_ticket is None:
|
||||||
pytest.skip("Test case test_get_stoken_by_login_ticket skipped: Parameter 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)
|
stoken = await auth_client.get_stoken_by_login_ticket(login_ticket, account_id)
|
||||||
@ -40,6 +45,11 @@ class TestAuthClient:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_cookie_token_by_stoken(auth_client: "AuthClient", stoken: str, account_id: int):
|
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:
|
if stoken is None:
|
||||||
pytest.skip("Test case test_get_cookie_token_by_stoken skipped: Parameter 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)
|
cookie_token = await auth_client.get_cookie_token_by_stoken(stoken, account_id)
|
||||||
@ -47,20 +57,28 @@ class TestAuthClient:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_ltoken_by_stoken(auth_client: "AuthClient", stoken: str, account_id: int):
|
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:
|
if stoken is None:
|
||||||
pytest.skip("Test case test_get_ltoken_by_stoken skipped: Parameter 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)
|
ltoken = await auth_client.get_ltoken_by_stoken(stoken, account_id)
|
||||||
assert ltoken is not None
|
assert ltoken is not None
|
||||||
|
|
||||||
@staticmethod
|
@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:
|
if stoken is None:
|
||||||
pytest.skip("Test case test_get_authkey_by_stoken skipped: Parameter stoken is None")
|
pytest.skip("Test case test_get_authkey_by_stoken skipped: Parameter stoken is None")
|
||||||
async with AuthClient(
|
async with AuthClient(
|
||||||
cookies={"stoken": stoken},
|
cookies={"stoken": stoken},
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
authkey = await client_instance.get_authkey_by_stoken(
|
authkey = await client_instance.get_authkey_by_stoken(
|
||||||
"hk4e_cn", recognize_genshin_server(genshin_player_id), "webview_gacha"
|
"hk4e_cn", recognize_genshin_server(genshin_player_id), "webview_gacha"
|
||||||
|
@ -4,18 +4,18 @@ import pytest
|
|||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
from simnet.client.components.chronicle.base import BaseChronicleClient
|
from simnet.client.components.chronicle.base import BaseChronicleClient
|
||||||
from simnet.utils.enum_ import Region
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with BaseChronicleClient(
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
|
@ -4,21 +4,20 @@ import pytest
|
|||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
from simnet.client.genshin import GenshinClient
|
from simnet.client.genshin import GenshinClient
|
||||||
from simnet.utils.enum_ import Region, Game
|
from simnet.utils.enum_ import Game
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def genshin_client(
|
async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
genshin_player_id: int, account_id: int, cookies: "Cookies"
|
|
||||||
): # skipcq: PY-D0003 # skipcq: PYL-W0621
|
|
||||||
async with GenshinClient(
|
async with GenshinClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
|
@ -5,19 +5,19 @@ import pytest_asyncio
|
|||||||
|
|
||||||
from simnet.client.components.chronicle.genshin import GenshinBattleChronicleClient
|
from simnet.client.components.chronicle.genshin import GenshinBattleChronicleClient
|
||||||
from simnet.models.genshin.chronicle.stats import FullGenshinUserStats, Stats
|
from simnet.models.genshin.chronicle.stats import FullGenshinUserStats, Stats
|
||||||
from simnet.utils.enum_ import Region
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with GenshinBattleChronicleClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
@ -36,16 +36,12 @@ class TestGenshinBattleChronicleClient:
|
|||||||
assert isinstance(user.stats, Stats)
|
assert isinstance(user.stats, Stats)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_partial_genshin_user(
|
async def test_get_partial_genshin_user(genshin_client: GenshinBattleChronicleClient):
|
||||||
genshin_client: GenshinBattleChronicleClient,
|
|
||||||
):
|
|
||||||
user = await genshin_client.get_partial_genshin_user()
|
user = await genshin_client.get_partial_genshin_user()
|
||||||
assert user.stats.days_active >= 0
|
assert user.stats.days_active >= 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_genshin_characters(
|
async def test_get_genshin_characters(genshin_client: GenshinBattleChronicleClient):
|
||||||
genshin_client: GenshinBattleChronicleClient,
|
|
||||||
):
|
|
||||||
characters = await genshin_client.get_genshin_characters()
|
characters = await genshin_client.get_genshin_characters()
|
||||||
assert len(characters) > 0
|
assert len(characters) > 0
|
||||||
for character in characters:
|
for character in characters:
|
||||||
|
@ -5,30 +5,32 @@ import pytest_asyncio
|
|||||||
|
|
||||||
from simnet.client.components.calculator.genshin import CalculatorClient
|
from simnet.client.components.calculator.genshin import CalculatorClient
|
||||||
from simnet.client.components.chronicle.genshin import GenshinBattleChronicleClient
|
from simnet.client.components.chronicle.genshin import GenshinBattleChronicleClient
|
||||||
from simnet.utils.enum_ import Region
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with CalculatorClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with GenshinBattleChronicleClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
|
@ -4,18 +4,19 @@ import pytest
|
|||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
from simnet.client.components.lab import LabClient
|
from simnet.client.components.lab import LabClient
|
||||||
from simnet.utils.enum_ import Region, Game
|
from simnet.utils.enum_ import Game
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with LabClient(
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
|
@ -4,21 +4,20 @@ import pytest
|
|||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
from simnet.client.starrail import StarRailClient
|
from simnet.client.starrail import StarRailClient
|
||||||
from simnet.utils.enum_ import Region, Game
|
from simnet.utils.enum_ import Game
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def starrail_client(
|
async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
starrail_player_id: int, account_id: int, cookies: "Cookies"
|
|
||||||
): # skipcq: PY-D0003 # skipcq: PYL-W0621
|
|
||||||
async with StarRailClient(
|
async with StarRailClient(
|
||||||
player_id=starrail_player_id,
|
player_id=starrail_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
|
@ -4,19 +4,19 @@ import pytest
|
|||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
from simnet.client.components.chronicle.starrail import StarRailBattleChronicleClient
|
from simnet.client.components.chronicle.starrail import StarRailBattleChronicleClient
|
||||||
from simnet.utils.enum_ import Region
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
|
from simnet.utils.enum_ import Region
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@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(
|
async with StarRailBattleChronicleClient(
|
||||||
player_id=starrail_player_id,
|
player_id=starrail_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
region=Region.CHINESE,
|
region=region,
|
||||||
) as client_instance:
|
) as client_instance:
|
||||||
yield client_instance
|
yield client_instance
|
||||||
|
|
||||||
@ -38,9 +38,7 @@ class TestStarrailBattleChronicleClient:
|
|||||||
assert notes is not None
|
assert notes is not None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_starrail_characters(
|
async def test_get_starrail_characters(starrail_client: "StarRailBattleChronicleClient"):
|
||||||
starrail_client: "StarRailBattleChronicleClient",
|
|
||||||
):
|
|
||||||
characters = await starrail_client.get_starrail_characters()
|
characters = await starrail_client.get_starrail_characters()
|
||||||
assert len(characters.avatar_list) > 0
|
assert len(characters.avatar_list) > 0
|
||||||
character = characters.avatar_list[-1]
|
character = characters.avatar_list[-1]
|
||||||
|
Loading…
Reference in New Issue
Block a user