2023-05-01 12:50:48 +00:00
|
|
|
import asyncio
|
|
|
|
import os
|
|
|
|
import warnings
|
2023-05-08 01:21:32 +00:00
|
|
|
from pathlib import Path
|
2023-05-09 08:06:32 +00:00
|
|
|
from typing import Optional
|
2023-05-01 12:50:48 +00:00
|
|
|
|
|
|
|
import pytest
|
2023-05-08 01:21:32 +00:00
|
|
|
from dotenv import load_dotenv
|
2023-05-01 12:50:48 +00:00
|
|
|
|
|
|
|
from simnet.client.cookies import Cookies
|
|
|
|
from simnet.utils.cookies import parse_cookie
|
2023-12-27 07:09:24 +00:00
|
|
|
from simnet.utils.enums import Region
|
2023-05-08 01:21:32 +00:00
|
|
|
|
|
|
|
env_path = Path(".env")
|
|
|
|
if env_path.exists():
|
|
|
|
load_dotenv()
|
2023-05-01 12:50:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def event_loop(): # skipcq: PY-D0003
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.simplefilter("ignore")
|
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
|
|
|
|
yield loop
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def cookies() -> "Cookies": # skipcq: PY-D0003
|
|
|
|
cookies_str = os.environ.get("COOKIES")
|
|
|
|
if not cookies_str:
|
|
|
|
pytest.exit("No cookies set", 1)
|
|
|
|
|
|
|
|
_cookies = Cookies(parse_cookie(cookies_str))
|
2023-05-12 03:36:03 +00:00
|
|
|
if _cookies.account_id is None:
|
|
|
|
warnings.warn("can not found account id in cookies")
|
2023-05-01 12:50:48 +00:00
|
|
|
|
|
|
|
return _cookies
|
|
|
|
|
|
|
|
|
2024-11-08 05:22:13 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def starrail_cookies() -> Optional["Cookies"]: # skipcq: PY-D0003
|
|
|
|
cookies_str = os.environ.get("STARRAIL_COOKIES")
|
|
|
|
if not cookies_str:
|
|
|
|
return None
|
|
|
|
_cookies = Cookies(parse_cookie(cookies_str))
|
|
|
|
if _cookies.account_id is None:
|
|
|
|
warnings.warn("can not found account id in starrail cookies")
|
|
|
|
|
|
|
|
return _cookies
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def zzz_cookies() -> Optional["Cookies"]:
|
|
|
|
cookies_str = os.environ.get("ZZZ_COOKIES")
|
|
|
|
if not cookies_str:
|
|
|
|
return None
|
|
|
|
_cookies = Cookies(parse_cookie(cookies_str))
|
|
|
|
if _cookies.account_id is None:
|
|
|
|
warnings.warn("can not found account id in zzz cookies")
|
|
|
|
|
|
|
|
return _cookies
|
|
|
|
|
|
|
|
|
2023-05-01 12:50:48 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2023-05-12 03:36:03 +00:00
|
|
|
def genshin_player_id() -> Optional[int]: # skipcq: PY-D0003
|
2023-05-08 01:21:32 +00:00
|
|
|
_player_id = os.environ.get("GENSHIN_PLAYER_ID")
|
|
|
|
if not _player_id:
|
2023-05-12 03:36:03 +00:00
|
|
|
warnings.warn("No genshin player id set")
|
|
|
|
return None
|
2023-05-08 01:21:32 +00:00
|
|
|
return int(_player_id)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2023-05-12 03:36:03 +00:00
|
|
|
def starrail_player_id() -> Optional[int]: # skipcq: PY-D0003
|
2023-05-08 01:21:32 +00:00
|
|
|
_player_id = os.environ.get("STARRAIL_PLAYER_ID")
|
2023-05-01 12:50:48 +00:00
|
|
|
if not _player_id:
|
2023-05-12 03:36:03 +00:00
|
|
|
warnings.warn("No starrail player id set")
|
|
|
|
return None
|
2023-05-01 12:50:48 +00:00
|
|
|
return int(_player_id)
|
|
|
|
|
|
|
|
|
2024-11-08 05:22:13 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def zzz_player_id() -> Optional[int]:
|
|
|
|
_player_id = os.environ.get("ZZZ_PLAYER_ID")
|
|
|
|
if not _player_id:
|
|
|
|
warnings.warn("No zzz player id set")
|
|
|
|
return None
|
|
|
|
return int(_player_id)
|
|
|
|
|
|
|
|
|
2023-05-01 12:50:48 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2023-05-12 03:36:03 +00:00
|
|
|
def account_id() -> Optional[int]: # skipcq: PY-D0003
|
2023-05-01 12:50:48 +00:00
|
|
|
_account_id = os.environ.get("ACCOUNT_ID")
|
|
|
|
if not _account_id:
|
2023-05-12 03:36:03 +00:00
|
|
|
return None
|
2023-05-01 12:50:48 +00:00
|
|
|
return int(_account_id)
|
2023-05-09 08:06:32 +00:00
|
|
|
|
|
|
|
|
2023-05-12 03:01:53 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def region() -> Region: # skipcq: PY-D0003
|
|
|
|
_region = os.environ.get("REGION")
|
|
|
|
if not _region:
|
|
|
|
return Region.CHINESE
|
|
|
|
return Region(_region)
|
|
|
|
|
|
|
|
|
2023-05-09 08:06:32 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def stoken() -> Optional[str]: # skipcq: PY-D0003
|
|
|
|
_stoken = os.environ.get("STOKEN")
|
|
|
|
return _stoken
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def login_ticket() -> Optional[str]: # skipcq: PY-D0003
|
|
|
|
_login_ticket = os.environ.get("LOGIN_TICKET")
|
|
|
|
return _login_ticket
|
2023-05-09 08:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def if_test_build() -> bool: # skipcq: PY-D0003
|
|
|
|
_test_build = bool(os.environ.get("TEST_BUILD", False))
|
|
|
|
return _test_build
|