aboutsummaryrefslogtreecommitdiff
path: root/tests/test_config.py
blob: a160a841f031b6c66893835a82dbde288f5ba72b (plain) (blame)
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
60
61
62
63
64
"""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",
        "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.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="",
        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",
        roleplay_message="test"
    )
    
    # Should not raise an exception
    config.validate()