Debian Codegraph @

tests/plugin_config_test.py

raw
1 from os import path
2
3 import pytest
4
5 from errbot.botplugin import ValidationException, recurse_check_structure
6
7 extra_plugin_dir = path.join(path.dirname(path.realpath(__file__)), "config_plugin")
8
9
10 def test_recurse_check_structure_valid():
11 sample = dict(
12 string="Foobar",
13 list=["Foo", "Bar"],
14 dict={"foo": "Bar"},
15 none=None,
16 true=True,
17 false=False,
18 )
19 to_check = dict(
20 string="Foobar",
21 list=["Foo", "Bar", "Bas"],
22 dict={"foo": "Bar"},
23 none=None,
24 true=True,
25 false=False,
26 )
27 recurse_check_structure(sample, to_check)
28
29
30 def test_recurse_check_structure_missingitem():
31 sample = dict(
32 string="Foobar",
33 list=["Foo", "Bar"],
34 dict={"foo": "Bar"},
35 none=None,
36 true=True,
37 false=False,
38 )
39 to_check = dict(
40 string="Foobar", list=["Foo", "Bar"], dict={"foo": "Bar"}, none=None, true=True
41 )
42 with pytest.raises(ValidationException):
43 recurse_check_structure(sample, to_check)
44
45
46 def test_recurse_check_structure_extrasubitem():
47 sample = dict(
48 string="Foobar",
49 list=["Foo", "Bar"],
50 dict={"foo": "Bar"},
51 none=None,
52 true=True,
53 false=False,
54 )
55 to_check = dict(
56 string="Foobar",
57 list=["Foo", "Bar", "Bas"],
58 dict={"foo": "Bar", "Bar": "Foo"},
59 none=None,
60 true=True,
61 false=False,
62 )
63 with pytest.raises(ValidationException):
64 recurse_check_structure(sample, to_check)
65
66
67 def test_recurse_check_structure_missingsubitem():
68 sample = dict(
69 string="Foobar",
70 list=["Foo", "Bar"],
71 dict={"foo": "Bar"},
72 none=None,
73 true=True,
74 false=False,
75 )
76 to_check = dict(
77 string="Foobar",
78 list=["Foo", "Bar", "Bas"],
79 dict={},
80 none=None,
81 true=True,
82 false=False,
83 )
84 with pytest.raises(ValidationException):
85 recurse_check_structure(sample, to_check)
86
87
88 def test_recurse_check_structure_wrongtype_1():
89 sample = dict(
90 string="Foobar",
91 list=["Foo", "Bar"],
92 dict={"foo": "Bar"},
93 none=None,
94 true=True,
95 false=False,
96 )
97 to_check = dict(
98 string=None,
99 list=["Foo", "Bar"],
100 dict={"foo": "Bar"},
101 none=None,
102 true=True,
103 false=False,
104 )
105 with pytest.raises(ValidationException):
106 recurse_check_structure(sample, to_check)
107
108
109 def test_recurse_check_structure_wrongtype_2():
110 sample = dict(
111 string="Foobar",
112 list=["Foo", "Bar"],
113 dict={"foo": "Bar"},
114 none=None,
115 true=True,
116 false=False,
117 )
118 to_check = dict(
119 string="Foobar",
120 list={"foo": "Bar"},
121 dict={"foo": "Bar"},
122 none=None,
123 true=True,
124 false=False,
125 )
126 with pytest.raises(ValidationException):
127 recurse_check_structure(sample, to_check)
128
129
130 def test_recurse_check_structure_wrongtype_3():
131 sample = dict(
132 string="Foobar",
133 list=["Foo", "Bar"],
134 dict={"foo": "Bar"},
135 none=None,
136 true=True,
137 false=False,
138 )
139 to_check = dict(
140 string="Foobar",
141 list=["Foo", "Bar"],
142 dict=["Foo", "Bar"],
143 none=None,
144 true=True,
145 false=False,
146 )
147 with pytest.raises(ValidationException):
148 recurse_check_structure(sample, to_check)
149
150
151 def test_failed_config(testbot):
152 assert "Plugin configuration done." in testbot.exec_command(
153 '!plugin config Config {"One": "two"}'
154 )