-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtest_general.py
More file actions
79 lines (59 loc) · 2.57 KB
/
test_general.py
File metadata and controls
79 lines (59 loc) · 2.57 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pytest
from nmcli._const import NetworkConnectivity, NetworkManagerState
from nmcli._general import GeneralControl
from nmcli.data import General
from .helper import DummySystemCommand
def test_general():
s = DummySystemCommand('''STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled''')
general = GeneralControl(s)
r = general()
assert r == General(NetworkManagerState.CONNECTED_GLOBAL,
NetworkConnectivity.FULL, True, True, True, True)
assert s.passed_parameters == ['general', 'status']
def test_status():
s = DummySystemCommand('''STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled''')
general = GeneralControl(s)
r = general.status()
assert r == General(NetworkManagerState.CONNECTED_GLOBAL,
NetworkConnectivity.FULL, True, True, True, True)
assert s.passed_parameters == ['general', 'status']
def test_get_hostname():
s = DummySystemCommand('test\n')
general = GeneralControl(s)
assert general.get_hostname() == 'test'
assert s.passed_parameters == ['general', 'hostname']
def test_set_hostname():
s = DummySystemCommand()
general = GeneralControl(s)
general.set_hostname('test')
assert s.passed_parameters == ['general', 'hostname', 'test']
def test_reload_without_flags():
s = DummySystemCommand()
general = GeneralControl(s)
general.reload()
assert s.passed_parameters == ['general', 'reload']
def test_reload_with_single_flag():
s = DummySystemCommand()
general = GeneralControl(s)
general.reload(['conf'])
assert s.passed_parameters == ['general', 'reload', 'conf']
def test_reload_with_all_valid_flags():
s = DummySystemCommand()
general = GeneralControl(s)
general.reload(['conf', 'dns-rc', 'dns-full'])
assert s.passed_parameters == ['general', 'reload', 'conf', 'dns-rc', 'dns-full']
def test_reload_with_invalid_flag():
s = DummySystemCommand()
general = GeneralControl(s)
with pytest.raises(ValueError) as exc_info:
general.reload(['invalid-flag'])
assert "Invalid reload flag 'invalid-flag'" in str(exc_info.value)
assert "Valid flags are: conf, dns-rc, dns-full" in str(exc_info.value)
def test_reload_with_mixed_valid_and_invalid_flags():
s = DummySystemCommand()
general = GeneralControl(s)
with pytest.raises(ValueError) as exc_info:
general.reload(['conf', 'invalid'])
assert "Invalid reload flag 'invalid'" in str(exc_info.value)