Skip to content

Commit 13d42cf

Browse files
committed
Add configuration tests.
* tests/test_config.py: New file.
1 parent 733f949 commit 13d42cf

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_config.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import unittest
3+
import tomli
4+
5+
import pytest
6+
from pydantic.error_wrappers import ValidationError
7+
8+
import zabbix_auto_config.models as models
9+
10+
class TestConfig(unittest.TestCase):
11+
@staticmethod
12+
def get_sample_config():
13+
with open(os.path.dirname(os.path.dirname(__file__)) +
14+
"/config.sample.toml") as config:
15+
return config.read()
16+
17+
def setUp(self):
18+
self.sample_config = self.get_sample_config()
19+
20+
def test_sample_config(self):
21+
models.Settings(**tomli.loads(self.sample_config))
22+
23+
def test_invalid_config(self):
24+
config = tomli.loads(self.sample_config)
25+
config["foo"] = "bar"
26+
with pytest.raises(ValidationError) as exc_info:
27+
models.Settings(**config)
28+
assert exc_info.value.errors() == [{'loc': ('foo',),
29+
'msg': 'extra fields not permitted',
30+
'type': 'value_error.extra'}]
31+
32+
33+
if __name__ == "__main__":
34+
unittest.main()

0 commit comments

Comments
 (0)