Spaces:
Sleeping
Sleeping
Download bot/tests/test_bootstrap_runtime_v3.py from JuanCS-Dev/twitch-byte-bot: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/spaces/JuanCS-Dev/twitch-byte-bot/resolve/main/bot/tests/test_bootstrap_runtime_v3.py
- Command line
-
hf download hf://spaces/JuanCS-Dev/twitch-byte-bot/bot/tests/test_bootstrap_runtime_v3.py
-
curl -L -o test_bootstrap_runtime_v3.py https://huggingface.co/spaces/JuanCS-Dev/twitch-byte-bot/resolve/main/bot/tests/test_bootstrap_runtime_v3.py
2.68 kB
| 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)) | |
| 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() | |
| 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, "") | |
| 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) | |
| 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, "") | |