Skip to content

Commit

Permalink
Simplify cookies in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thesadru committed May 16, 2022
1 parent d53dfd6 commit e0b5a2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
LTOKEN: ${{ secrets.LTOKEN }}
CN_LTUID: ${{ secrets.CN_LTUID }}
CN_LTOKEN: ${{ secrets.CN_LTOKEN }}
LOCAL_ACCOUNT_ID: ${{ secrets.LOCAL_ACCOUNT_ID }}
LOCAL_COOKIE_TOKEN: ${{ secrets.LOCAL_COOKIE_TOKEN }}
LOCAL_ACCOUNT_ID: ${{ matrix.python-version == '3.10' && secrets.LOCAL_ACCOUNT_ID || '' }}
LOCAL_COOKIE_TOKEN: ${{ matrix.python-version == '3.10' && secrets.LOCAL_COOKIE_TOKEN || '' }}
run: |
python -m nox -s test --verbose -- --cov-append
mv .coverage .coverage.${{ matrix.python-version }}
Expand Down
42 changes: 26 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,52 @@ def event_loop():

@pytest.fixture(scope="session")
def cookies() -> typing.Mapping[str, str]:
try:
return {"ltuid": os.environ["LTUID"], "ltoken": os.environ["LTOKEN"]}
except KeyError:
cookies = {"ltuid": os.environ.get("LTUID", ""), "ltoken": os.environ.get("LTOKEN", "")}

if not all(cookies.values()):
pytest.exit("No cookies set", 1)
return {}

return cookies


@pytest.fixture(scope="session")
def local_cookies() -> typing.Mapping[str, str]:
try:
return genshin.utility.get_browser_cookies()
cookies = genshin.utility.get_browser_cookies()
except Exception:
pass
cookies = {
"account_id": os.environ.get("LOCAL_ACCOUNT_ID", ""),
"cookie_token": os.environ.get("LOCAL_COOKIE_TOKEN", ""),
}

try:
return {"account_id": os.environ["LOCAL_ACCOUNT_ID"], "cookie_token": os.environ["LOCAL_COOKIE_TOKEN"]}
except KeyError:
if not all(cookies.values()):
return {}

return cookies


@pytest.fixture(scope="session")
def chinese_cookies() -> typing.Mapping[str, str]:
try:
return {"ltuid": os.environ["CN_LTUID"], "ltoken": os.environ["CN_LTOKEN"]}
except KeyError:
warnings.warn("No chinese cookies were set for tests")
cookies = {"ltuid": os.environ.get("CN_LTUID", ""), "ltoken": os.environ.get("CN_LTOKEN", "")}

if not all(cookies.values()):
return {}

return cookies


@pytest.fixture(scope="session")
def local_chinese_cookies() -> typing.Mapping[str, str]:
try:
return {"account_id": os.environ["LOCAL_CN_ACCOUNT_ID"], "cookie_token": os.environ["LOCAL_CN_COOKIE_TOKEN"]}
except KeyError:
cookies = {
"account_id": os.environ.get("LOCAL_CN_ACCOUNT_ID", ""),
"cookie_token": os.environ.get("LOCAL_CN_COOKIE_TOKEN", ""),
}

if not all(cookies.values()):
return {}

return cookies


@pytest.fixture(scope="session")
async def cache():
Expand Down

0 comments on commit e0b5a2c

Please sign in to comment.