From 5a6629980de936668fed6fc8d908a958592a55e3 Mon Sep 17 00:00:00 2001 From: voluntas Date: Wed, 6 Nov 2024 23:41:26 +0900 Subject: [PATCH] =?UTF-8?q?=E8=89=B2=E3=80=85=E5=A4=89=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ test/.env.template | 4 ++++ test/conftest.py | 36 ++++++++++++++++++++++++++++++++++ test/{momo.py => momo_sora.py} | 33 +++++++++++++++++++++++++------ test/pyproject.toml | 8 ++++++-- test/test_momo.py | 6 +++--- test/uv.lock | 13 +++++++++++- 7 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 test/.env.template create mode 100644 test/conftest.py rename test/{momo.py => momo_sora.py} (80%) diff --git a/.gitignore b/.gitignore index 6bf4759f..d9ea684a 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,7 @@ __pycache__ # vscode build + +# .env +.env +!.env.template diff --git a/test/.env.template b/test/.env.template new file mode 100644 index 00000000..8a764035 --- /dev/null +++ b/test/.env.template @@ -0,0 +1,4 @@ +TEST_SIGNALING_URLS=wss://sora.example.com/signaling +TEST_CHANNEL_ID_PREFIX=momo_ +TEST_SECRET_KEY=secret +TEST_API_URL=https://sora.example.com/api diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 00000000..914df6d9 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,36 @@ +import os + +import pytest +from dotenv import load_dotenv + + +@pytest.fixture +def setup(): + # 環境変数読み込み + load_dotenv() + + # signaling_url 単体か複数かをランダムで決めてテストする + if (test_signaling_urls := os.environ.get("TEST_SIGNALING_URLS")) is None: + raise ValueError("TEST_SIGNALING_URLS is required.") + + # , で区切って ['wss://...', ...] に変換 + test_signaling_urls = test_signaling_urls.split(",") + + if (test_channel_id_prefix := os.environ.get("TEST_CHANNEL_ID_PREFIX")) is None: + raise ValueError("TEST_CHANNEL_ID_PREFIX is required.") + + if (test_secret_key := os.environ.get("TEST_SECRET_KEY")) is None: + raise ValueError("TEST_SECRET_KEY is required.") + + # if (test_api_url := os.environ.get("TEST_API_URL")) is None: + # raise ValueError("TEST_API_URL is required.") + + return { + "signaling_urls": test_signaling_urls, + "channel_id_prefix": test_channel_id_prefix, + # "secret": test_secret_key, + # "api_url": test_api_url, + "metadata": {"access_token": test_secret_key}, + # openh264_path は str | None でよい + # "openh264_path": os.environ.get("OPENH264_PATH"), + } diff --git a/test/momo.py b/test/momo_sora.py similarity index 80% rename from test/momo.py rename to test/momo_sora.py index 1418a888..9ba8d0e4 100644 --- a/test/momo.py +++ b/test/momo_sora.py @@ -4,6 +4,7 @@ import sys import threading import time +import uuid from pathlib import Path # プラットフォームに応じたリリースディレクトリの設定 @@ -22,11 +23,27 @@ class Momo: - def __init__(self, mode="test", port=5000): + signaling_urls: list[str] + channel_id_prefix: str + secret_key: str + port: int + + def __init__( + self, + signaling_urls: list[str], + channel_id_prefix: str, + metadata: dict[str, str], + ): + self.signaling_urls = signaling_urls + self.channel_id_prefix = channel_id_prefix + self.metadata = metadata + + self.channel_id = f"{self.channel_id_prefix}_{uuid.uuid4()}" + + self.port = 5000 + self.executable = RELEASE_DIR / "momo" assert self.executable.exists() - self.mode = mode - self.port = port self.process = None self.thread = None self.is_running = False @@ -38,14 +55,18 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.stop() def run_app(self): - print(self.executable) - args = [ "sudo", str(self.executable), - self.mode, + "sora", "--port", str(self.port), + "--signaling-urls", + ",".join(self.signaling_urls), + "--channel-id", + self.channel_id_prefix, + "--secret-key", + self.secret_key, "--video-device", # これは GitHub Actions 用 "VCamera", diff --git a/test/pyproject.toml b/test/pyproject.toml index 49344935..3a615da8 100644 --- a/test/pyproject.toml +++ b/test/pyproject.toml @@ -2,12 +2,16 @@ name = "momo-e2e-test" version = "2013.3.8" requires-python = ">= 3.12" -dependencies = ["pytest>=8.3", "pytest-timeout>=2.3"] +dependencies = [ + "pytest>=8.3", + "pytest-timeout>=2.3", + "python-dotenv>=1.0", +] [tool.uv] package = false managed = true -dev-dependencies = ["ruff>=0.6"] +dev-dependencies = ["ruff"] [tool.pytest.ini_options] timeout = 45 diff --git a/test/test_momo.py b/test/test_momo.py index 5b7d6ac5..2fc442e7 100644 --- a/test/test_momo.py +++ b/test/test_momo.py @@ -1,10 +1,10 @@ import time -from momo import Momo +from momo_sora import Momo -def test_start_and_stop(): - with Momo() as momo: +def test_start_and_stop(setup): + with Momo(**setup) as momo: momo.start() time.sleep(3) diff --git a/test/uv.lock b/test/uv.lock index 3319dd38..0ad4f555 100644 --- a/test/uv.lock +++ b/test/uv.lock @@ -26,6 +26,7 @@ source = { virtual = "." } dependencies = [ { name = "pytest" }, { name = "pytest-timeout" }, + { name = "python-dotenv" }, ] [package.dev-dependencies] @@ -37,10 +38,11 @@ dev = [ requires-dist = [ { name = "pytest", specifier = ">=8.3" }, { name = "pytest-timeout", specifier = ">=2.3" }, + { name = "python-dotenv", specifier = ">=1.0" }, ] [package.metadata.requires-dev] -dev = [{ name = "ruff", specifier = ">=0.6" }] +dev = [{ name = "ruff" }] [[package]] name = "packaging" @@ -87,6 +89,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/03/27/14af9ef8321f5edc7527e47def2a21d8118c6f329a9342cc61387a0c0599/pytest_timeout-2.3.1-py3-none-any.whl", hash = "sha256:68188cb703edfc6a18fad98dc25a3c61e9f24d644b0b70f33af545219fc7813e", size = 14148 }, ] +[[package]] +name = "python-dotenv" +version = "1.0.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bc/57/e84d88dfe0aec03b7a2d4327012c1627ab5f03652216c63d49846d7a6c58/python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca", size = 39115 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6a/3e/b68c118422ec867fa7ab88444e1274aa40681c606d59ac27de5a5588f082/python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a", size = 19863 }, +] + [[package]] name = "ruff" version = "0.7.2"