diff options
| author | Fuwn <[email protected]> | 2025-08-27 17:49:43 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-08-27 17:49:43 -0700 |
| commit | 6650dcfee1c8aefedf7c9330566c0bb7ecb1a1d3 (patch) | |
| tree | 0fa54793cc077dc75b5086a2badf00457c6c8b25 /tests | |
| download | umabot-6650dcfee1c8aefedf7c9330566c0bb7ecb1a1d3.tar.xz umabot-6650dcfee1c8aefedf7c9330566c0bb7ecb1a1d3.zip | |
feat: Initial commit
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/__init__.py | 1 | ||||
| -rw-r--r-- | tests/test_config.py | 68 |
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..470a85f --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Tests for UmaBot.""" diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..30ccda7 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,68 @@ +"""Tests for the configuration module.""" + +import os +import pytest +from unittest.mock import patch + +from umabot.config import Config + + +def test_config_from_env(): + """Test configuration loading from environment variables.""" + test_env = { + "REDDIT_CLIENT_ID": "test_client_id", + "REDDIT_CLIENT_SECRET": "test_client_secret", + "REDDIT_USERNAME": "test_username", + "REDDIT_PASSWORD": "test_password", + "SUBREDDIT_NAME": "test_subreddit", + "SPAM_MESSAGE": "Test spam message", + "ROLEPLAY_MESSAGE": "Test roleplay message", + } + + with patch.dict(os.environ, test_env): + config = Config.from_env() + + assert config.client_id == "test_client_id" + assert config.client_secret == "test_client_secret" + assert config.username == "test_username" + assert config.password == "test_password" + assert config.subreddit_name == "test_subreddit" + assert config.spam_message == "Test spam message" + assert config.roleplay_message == "Test roleplay message" + assert config.check_interval == 60 + assert config.max_posts_per_day == 3 + assert config.dry_run is False + + +def test_config_validation(): + """Test configuration validation.""" + config = Config( + client_id="", + client_secret="", + username="", + password="", + user_agent="test", + subreddit_name="", + spam_message="", + roleplay_message="" + ) + + with pytest.raises(ValueError, match="Missing required configuration"): + config.validate() + + +def test_config_validation_success(): + """Test successful configuration validation.""" + config = Config( + client_id="test", + client_secret="test", + username="test", + password="test", + user_agent="test", + subreddit_name="test", + spam_message="test", + roleplay_message="test" + ) + + # Should not raise an exception + config.validate() |