feat: bot reads JIGAIDO_BOT_TOKEN from config file

- config.py: Added _resolve_bot_token() to read from config file
- bot.py: Uses config.config.bot_token instead of env var directly
- test_config.py: Added test for config file token reading
This commit is contained in:
shokollm
2026-04-04 15:16:55 +00:00
parent 5502de96ad
commit 408318d323
3 changed files with 50 additions and 5 deletions

View File

@@ -47,10 +47,27 @@ class TestConfigDataDir:
assert cfg.bot_token == "test_token_123"
def test_bot_token_none_when_not_set(self):
"""Test that bot_token is None when JIGAIDO_BOT_TOKEN not set."""
"""Test that bot_token is None when JIGAIDO_BOT_TOKEN not set and no config file."""
with patch.dict(os.environ, {}, clear=True):
cfg = Config()
assert cfg.bot_token is None
with patch("pathlib.Path.exists", return_value=False):
cfg = Config()
assert cfg.bot_token is None
def test_bot_token_from_config_file(self):
"""Test that bot_token is read from config file when env var not set."""
config_dir = Path.home() / ".jigaido"
config_file = config_dir / "config.json"
with patch.dict(os.environ, {}, clear=True):
with patch("pathlib.Path.expanduser", return_value=config_file):
with patch("pathlib.Path.exists", return_value=True):
with patch("builtins.open", create=True) as mock_open:
mock_open.return_value.__enter__ = lambda s: s
mock_open.return_value.__exit__ = lambda *a: None
mock_open.return_value.read = lambda: (
'{"JIGAIDO_BOT_TOKEN": "config_token"}'
)
cfg = Config()
assert cfg.bot_token == "config_token"
class TestConfigEnsureDataDir: