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:
洛水居室 2023-05-12 11:36:03 +08:00 committed by GitHub
parent d161c62e13
commit f61f2951a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 8 deletions

View File

@ -34,31 +34,36 @@ def cookies() -> "Cookies": # skipcq: PY-D0003
pytest.exit("No cookies set", 1)
_cookies = Cookies(parse_cookie(cookies_str))
if _cookies.account_id is None:
warnings.warn("can not found account id in cookies")
return _cookies
@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")
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)
@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")
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)
@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")
if not _account_id:
pytest.exit("No account id set", 1)
warnings.warn("No account id id set")
return None
return int(_account_id)

View File

@ -68,7 +68,7 @@ class TestAuthClient:
@staticmethod
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(
"Test case test_get_authkey_by_stoken skipped:This method is only available for the Chinese region."
)

View File

@ -13,6 +13,8 @@ if TYPE_CHECKING:
@pytest_asyncio.fixture
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(
player_id=genshin_player_id,
cookies=cookies,

View File

@ -13,6 +13,8 @@ if TYPE_CHECKING:
@pytest_asyncio.fixture
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(
player_id=genshin_player_id,
cookies=cookies,

View File

@ -13,6 +13,8 @@ if TYPE_CHECKING:
@pytest_asyncio.fixture
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(
player_id=genshin_player_id,
cookies=cookies,

View File

@ -13,6 +13,8 @@ if TYPE_CHECKING:
@pytest_asyncio.fixture
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(
player_id=starrail_player_id,
cookies=cookies,

View File

@ -12,6 +12,8 @@ if TYPE_CHECKING:
@pytest_asyncio.fixture
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(
player_id=starrail_player_id,
cookies=cookies,