From 4d30b6ea58ce04c10a5408ceac34814945781a62 Mon Sep 17 00:00:00 2001 From: laggykiller Date: Sun, 4 Feb 2024 21:54:19 +0800 Subject: [PATCH] Allow importing creds from json during test --- tests/common.py | 20 ++++++++++++++++++++ tests/test_download.py | 5 +---- tests/test_export.py | 13 ++++++++----- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/common.py b/tests/common.py index 5031a87..8daf734 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,3 +1,4 @@ +import os import shutil import subprocess from pathlib import Path @@ -9,10 +10,29 @@ SRC_DIR = Path(__file__).resolve().parent / '../src' SAMPLE_DIR = Path(__file__).resolve().parent / 'samples' COMPRESSION_JSON_PATH = SRC_DIR / 'sticker_convert/resources/compression.json' +CREDS_JSON_PATH = SRC_DIR / 'sticker_convert/creds.json' with open(COMPRESSION_JSON_PATH) as f: COMPRESSION_DICT = json.load(f) +if CREDS_JSON_PATH.is_file(): + with open(CREDS_JSON_PATH) as f: + CREDS_JSON_DICT = json.load(f) + + SIGNAL_UUID = CREDS_JSON_DICT.get("signal", {}).get("uuid") + SIGNAL_PASSWORD = CREDS_JSON_DICT.get("signal", {}).get("password") + TELEGRAM_TOKEN = CREDS_JSON_DICT.get("telegram", {}).get("token") + TELEGRAM_USERID = CREDS_JSON_DICT.get("telegram", {}).get("userid") + KAKAO_TOKEN = CREDS_JSON_DICT.get("kakao", {}).get("auth_token") + LINE_COOKIES = CREDS_JSON_DICT.get("line", {}).get("cookies") +else: + SIGNAL_UUID = os.environ.get("SIGNAL_UUID") + SIGNAL_PASSWORD = os.environ.get("SIGNAL_PASSWORD") + TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN") + TELEGRAM_USERID = os.environ.get("TELEGRAM_USERID") + KAKAO_TOKEN = os.environ.get("KAKAO_TOKEN") + LINE_COOKIES = os.environ.get("LINE_COOKIES") + def run_cmd(cmd, **kwargs): result = subprocess.run(cmd, **kwargs) diff --git a/tests/test_download.py b/tests/test_download.py index 40b52cd..c515664 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -3,12 +3,9 @@ import pytest -from .common import run_cmd, PYTHON_EXE, SRC_DIR +from .common import run_cmd, PYTHON_EXE, SRC_DIR, TELEGRAM_TOKEN, LINE_COOKIES, KAKAO_TOKEN TEST_DOWNLOAD = os.environ.get("TEST_DOWNLOAD") -TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN") -KAKAO_TOKEN = os.environ.get("KAKAO_TOKEN") -LINE_COOKIES = os.environ.get("LINE_COOKIES") def _run_sticker_convert( tmp_path: Path, diff --git a/tests/test_export.py b/tests/test_export.py index bd9d673..70c47a7 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -4,17 +4,17 @@ import pytest -from .common import run_cmd, PYTHON_EXE, SRC_DIR, SAMPLE_DIR, COMPRESSION_DICT +from .common import ( + run_cmd, PYTHON_EXE, SRC_DIR, SAMPLE_DIR, COMPRESSION_DICT, + SIGNAL_UUID, SIGNAL_PASSWORD, TELEGRAM_TOKEN, TELEGRAM_USERID +) os.chdir(Path(__file__).resolve().parent) sys.path.append('../src') from sticker_convert.utils.media.codec_info import CodecInfo -SIGNAL_UUID = os.environ.get("SIGNAL_UUID") -SIGNAL_PASSWORD = os.environ.get("SIGNAL_UUID") -TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN") -TELEGRAM_USERID = os.environ.get("TELEGRAM_USERID") +TEST_UPLOAD = os.environ.get("TEST_UPLOAD") def _run_sticker_convert(tmp_path: Path, preset: str, export: str): preset_dict = COMPRESSION_DICT.get(preset) @@ -91,14 +91,17 @@ def _xcode_asserts(tmp_path: Path): assert os.path.isfile(imessage_xcode_dir / "sticker-convert-test.xcodeproj/project.pbxproj") +@pytest.mark.skipif(not TEST_UPLOAD, reason="TEST_UPLOAD not set") @pytest.mark.skipif(not (SIGNAL_UUID and SIGNAL_PASSWORD), reason="No credentials") def test_upload_signal_with_upload(tmp_path): _run_sticker_convert(tmp_path, "signal", "signal") +@pytest.mark.skipif(not TEST_UPLOAD, reason="TEST_UPLOAD not set") @pytest.mark.skipif(not (TELEGRAM_TOKEN and TELEGRAM_USERID), reason="No credentials") def test_upload_telegram_with_upload(tmp_path): _run_sticker_convert(tmp_path, "telegram", "telegram") +@pytest.mark.skipif(not TEST_UPLOAD, reason="TEST_UPLOAD not set") @pytest.mark.skipif(not (TELEGRAM_TOKEN and TELEGRAM_USERID), reason="No credentials") def test_upload_telegram_emoji_with_upload(tmp_path): _run_sticker_convert(tmp_path, "telegram_emoji", None)