Spaces:
Sleeping
Sleeping
File size: 2,679 Bytes
127bfda 37ee895 127bfda 37ee895 127bfda 37ee895 127bfda 37ee895 127bfda 37ee895 127bfda 37ee895 127bfda | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import os
import unittest
from unittest.mock import patch
import pytest
import bot.bootstrap_runtime as bootstrap
class TestBootstrapRuntimeV3(unittest.IsolatedAsyncioTestCase):
def test_get_secret_fail(self):
with patch.dict(os.environ, {}, clear=True):
with self.assertRaises(RuntimeError) as cm:
bootstrap.get_secret("missing-secret")
self.assertIn("missing-secret", str(cm.exception))
def test_require_env_fail(self):
with patch.dict(os.environ, {}, clear=True):
with self.assertRaises(RuntimeError) as cm:
bootstrap.require_env("REQUIRED_VAR")
self.assertIn("REQUIRED_VAR", str(cm.exception))
@pytest.mark.asyncio
async def test_resolve_irc_channel_logins_all_missing(self):
with patch("bot.bootstrap_runtime.TWITCH_CHANNEL_LOGINS_RAW", None):
with patch("bot.bootstrap_runtime.TWITCH_CHANNEL_LOGIN", None):
with patch.dict(os.environ, {}, clear=True):
with self.assertRaises(RuntimeError):
await bootstrap.resolve_irc_channel_logins()
@patch("bot.bootstrap_runtime.TWITCH_CLIENT_SECRET_INLINE", None)
@patch("bot.bootstrap_runtime.TWITCH_CLIENT_SECRET_NAME", "my-secret")
def test_resolve_client_secret_for_irc_refresh_exception(self):
with patch("bot.bootstrap_runtime.get_secret", side_effect=Exception("boom")):
res = bootstrap.resolve_client_secret_for_irc_refresh()
self.assertEqual(res, "")
@patch("bot.bootstrap_runtime.require_env")
def test_build_irc_token_manager_no_secret_warning(self, mock_require):
mock_require.side_effect = lambda x: {
"TWITCH_USER_TOKEN": "ut",
"TWITCH_CLIENT_ID": "cid",
}.get(x, "")
with patch("os.environ.get", return_value="rt"):
with patch(
"bot.bootstrap_runtime.resolve_client_secret_for_irc_refresh", return_value=""
) as mock_resolve:
with patch("bot.bootstrap_runtime.logger.warning") as mock_warn:
tm = bootstrap.build_irc_token_manager()
self.assertEqual(tm.client_secret, "")
# When resolve returns empty string, no warning is called (new behavior)
@patch("bot.bootstrap_runtime.require_env")
def test_build_irc_token_manager_no_refresh(self, mock_require):
mock_require.side_effect = lambda x: {"TWITCH_USER_TOKEN": "ut"}.get(x, "")
with patch("os.environ.get", return_value=""):
tm = bootstrap.build_irc_token_manager()
self.assertEqual(tm.refresh_token, "")
|