Completed
Branch development (19ca9f)
by Jochen
02:17
created

tests.test_load_config.test_load_config()   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nop 0
dl 0
loc 17
rs 9.75
c 0
b 0
f 0
1
"""
2
:Copyright: 2007-2020 Jochen Kupperschmidt
3
:License: MIT, see LICENSE for details.
4
"""
5
6
from io import StringIO
7
8
from weitersager.config import load_config
9
from weitersager.irc import Channel, Config as IrcConfig, Server as IrcServer
10
11
12
TOML_CONFIG = '''\
13
[http]
14
host = "127.0.0.1"
15
port = 55555
16
17
[irc.server]
18
host = "orion.astrochat.test"
19
port = 6669
20
password = "ToTheStars!"
21
22
[irc.bot]
23
nickname = "SpaceCowboy"
24
realname = "Monsieur Weitersager"
25
26
[[irc.channels]]
27
name = "#skyscreeners"
28
29
[[irc.channels]]
30
name = "#elite-astrology"
31
password = "twinkle-twinkle"
32
33
[[irc.channels]]
34
name = "#hubblebubble"
35
'''
36
37
38
def test_load_config():
39
    toml = StringIO(TOML_CONFIG)
40
41
    irc_config, http_host, http_port = load_config(toml)
42
43
    assert irc_config == IrcConfig(
44
        server=IrcServer('orion.astrochat.test', 6669, 'ToTheStars!'),
45
        nickname='SpaceCowboy',
46
        realname='Monsieur Weitersager',
47
        channels=[
48
            Channel('#skyscreeners'),
49
            Channel('#elite-astrology', password='twinkle-twinkle'),
50
            Channel('#hubblebubble'),
51
        ],
52
    )
53
    assert http_host == '127.0.0.1'
54
    assert http_port == 55555
55
56
57
TOML_CONFIG_WITH_DEFAULTS = '''\
58
[irc.server]
59
host = "irc.onlinetalk.test"
60
61
[irc.bot]
62
nickname = "TownCrier"
63
'''
64
65
66
def test_load_config_with_defaults():
67
    toml = StringIO(TOML_CONFIG_WITH_DEFAULTS)
68
69
    irc_config, http_host, http_port = load_config(toml)
70
71
    assert irc_config == IrcConfig(
72
        server=IrcServer('irc.onlinetalk.test', 6667),
73
        nickname='TownCrier',
74
        realname='Weitersager',
75
        channels=[],
76
    )
77
    assert http_host == '127.0.0.1'
78
    assert http_port == 8080
79