mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-22 06:17:57 +00:00
✅ Add player ID check to client fixtures
In various client fixtures, a player ID check has been added to ensure that the player ID parameter is not None before creating the client object. This check helps to handle scenarios where the player ID is not provided, preventing potential errors or undesired behavior.
This commit is contained in:
parent
d161c62e13
commit
f61f2951a5
@ -34,31 +34,36 @@ def cookies() -> "Cookies": # skipcq: PY-D0003
|
|||||||
pytest.exit("No cookies set", 1)
|
pytest.exit("No cookies set", 1)
|
||||||
|
|
||||||
_cookies = Cookies(parse_cookie(cookies_str))
|
_cookies = Cookies(parse_cookie(cookies_str))
|
||||||
|
if _cookies.account_id is None:
|
||||||
|
warnings.warn("can not found account id in cookies")
|
||||||
|
|
||||||
return _cookies
|
return _cookies
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def genshin_player_id() -> int: # skipcq: PY-D0003
|
def genshin_player_id() -> Optional[int]: # skipcq: PY-D0003
|
||||||
_player_id = os.environ.get("GENSHIN_PLAYER_ID")
|
_player_id = os.environ.get("GENSHIN_PLAYER_ID")
|
||||||
if not _player_id:
|
if not _player_id:
|
||||||
pytest.exit("No genshin player id set", 1)
|
warnings.warn("No genshin player id set")
|
||||||
|
return None
|
||||||
return int(_player_id)
|
return int(_player_id)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def starrail_player_id() -> int: # skipcq: PY-D0003
|
def starrail_player_id() -> Optional[int]: # skipcq: PY-D0003
|
||||||
_player_id = os.environ.get("STARRAIL_PLAYER_ID")
|
_player_id = os.environ.get("STARRAIL_PLAYER_ID")
|
||||||
if not _player_id:
|
if not _player_id:
|
||||||
pytest.exit("No genshin player id set", 1)
|
warnings.warn("No starrail player id set")
|
||||||
|
return None
|
||||||
return int(_player_id)
|
return int(_player_id)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def account_id() -> int: # skipcq: PY-D0003
|
def account_id() -> Optional[int]: # skipcq: PY-D0003
|
||||||
_account_id = os.environ.get("ACCOUNT_ID")
|
_account_id = os.environ.get("ACCOUNT_ID")
|
||||||
if not _account_id:
|
if not _account_id:
|
||||||
pytest.exit("No account id set", 1)
|
warnings.warn("No account id id set")
|
||||||
|
return None
|
||||||
return int(_account_id)
|
return int(_account_id)
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class TestAuthClient:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def test_get_authkey_by_stoken(stoken: str, account_id: int, region: "Region", 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:
|
if region != Region.CHINESE:
|
||||||
pytest.skip(
|
pytest.skip(
|
||||||
"Test case test_get_authkey_by_stoken skipped:This method is only available for the Chinese region."
|
"Test case test_get_authkey_by_stoken skipped:This method is only available for the Chinese region."
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
|
if genshin_player_id is None:
|
||||||
|
pytest.skip("Test case test_genshin skipped: No starrail player id set.")
|
||||||
async with GenshinClient(
|
async with GenshinClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
|
@ -13,6 +13,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
async def genshin_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
|
if genshin_player_id is None:
|
||||||
|
pytest.skip("Test case test_genshin_battle_chronicle_client skipped: No starrail player id set.")
|
||||||
async with GenshinBattleChronicleClient(
|
async with GenshinBattleChronicleClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
|
@ -13,6 +13,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def calculator_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
async def calculator_client(genshin_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
|
if genshin_player_id is None:
|
||||||
|
pytest.skip("Test case test_starrail_battle_chronicle_client skipped: No starrail player id set.")
|
||||||
async with CalculatorClient(
|
async with CalculatorClient(
|
||||||
player_id=genshin_player_id,
|
player_id=genshin_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
|
@ -13,6 +13,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
|
if starrail_player_id is None:
|
||||||
|
pytest.skip("Test case test_starrail skipped: No starrail player id set.")
|
||||||
async with StarRailClient(
|
async with StarRailClient(
|
||||||
player_id=starrail_player_id,
|
player_id=starrail_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
|
@ -12,6 +12,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
async def starrail_client(starrail_player_id: int, account_id: int, region: "Region", cookies: "Cookies"):
|
||||||
|
if starrail_player_id is None:
|
||||||
|
pytest.skip("Test case test_genshin_calculator_client skipped: No starrail player id set.")
|
||||||
async with StarRailBattleChronicleClient(
|
async with StarRailBattleChronicleClient(
|
||||||
player_id=starrail_player_id,
|
player_id=starrail_player_id,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
|
Loading…
Reference in New Issue
Block a user