Files
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

129 lines
5.2 KiB
Python

"""Tests for credential resolution."""
from __future__ import annotations
import pytest
from platform.scheduler.credentials import (
resolve_discord_credentials,
resolve_slack_credentials,
resolve_telegram_credentials,
)
class TestTelegramCredentials:
def test_from_params(self) -> None:
creds = resolve_telegram_credentials({"bot_token": "from_params"})
assert creds == {"bot_token": "from_params"}
def test_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "from_env")
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_telegram_credentials({})
assert creds == {"bot_token": "from_env"}
def test_empty_when_nothing_configured(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("TELEGRAM_BOT_TOKEN", raising=False)
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
monkeypatch.setattr(
"config.llm_credentials.resolve_env_credential",
lambda *_args, **_kwargs: "",
)
creds = resolve_telegram_credentials({})
assert creds == {}
def test_from_keyring(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("OPENSRE_DISABLE_KEYRING", raising=False)
monkeypatch.delenv("TELEGRAM_BOT_TOKEN", raising=False)
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
monkeypatch.setattr(
"config.llm_credentials.resolve_env_credential",
lambda *_args, **_kwargs: "from_keyring",
)
creds = resolve_telegram_credentials({})
assert creds == {"bot_token": "from_keyring"}
class TestSlackCredentials:
def test_from_params(self) -> None:
creds = resolve_slack_credentials({"webhook_url": "https://hooks.slack.com/from-params"})
assert creds == {"webhook_url": "https://hooks.slack.com/from-params"}
def test_from_params_access_token_fallback(self) -> None:
creds = resolve_slack_credentials({"access_token": "xoxb-from-params"})
assert creds == {"access_token": "xoxb-from-params"}
def test_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("SLACK_WEBHOOK_URL", "https://hooks.slack.com/from-env")
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_slack_credentials({})
assert creds == {"webhook_url": "https://hooks.slack.com/from-env"}
def test_from_env_access_token_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("SLACK_WEBHOOK_URL", raising=False)
monkeypatch.delenv("SLACK_BOT_TOKEN", raising=False)
monkeypatch.setenv("SLACK_ACCESS_TOKEN", "xoxp-from-access-env")
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_slack_credentials({})
assert creds == {"access_token": "xoxp-from-access-env"}
def test_from_env_webhook_takes_priority(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("SLACK_WEBHOOK_URL", "https://hooks.slack.com/primary")
monkeypatch.setenv("SLACK_BOT_TOKEN", "xoxb-secondary")
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_slack_credentials({})
assert creds == {"webhook_url": "https://hooks.slack.com/primary"}
def test_empty_when_nothing_configured(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("SLACK_WEBHOOK_URL", raising=False)
monkeypatch.delenv("SLACK_BOT_TOKEN", raising=False)
monkeypatch.delenv("SLACK_ACCESS_TOKEN", raising=False)
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_slack_credentials({})
assert creds == {}
class TestDiscordCredentials:
def test_from_params(self) -> None:
creds = resolve_discord_credentials({"bot_token": "discord_from_params"})
assert creds == {"bot_token": "discord_from_params"}
def test_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("DISCORD_BOT_TOKEN", "discord_from_env")
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_discord_credentials({})
assert creds == {"bot_token": "discord_from_env"}
def test_empty_when_nothing_configured(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("DISCORD_BOT_TOKEN", raising=False)
monkeypatch.setattr(
"platform.scheduler.credentials._get_integration_credential",
lambda *_: "",
)
creds = resolve_discord_credentials({})
assert creds == {}