Skip to content

Commit

Permalink
Allow importing creds from json during test
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Feb 4, 2024
1 parent deaec7c commit 4d30b6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
20 changes: 20 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import subprocess
from pathlib import Path
Expand All @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4d30b6e

Please sign in to comment.