-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tests/test_config.py: New file.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import unittest | ||
import tomli | ||
|
||
import pytest | ||
from pydantic.error_wrappers import ValidationError | ||
|
||
import zabbix_auto_config.models as models | ||
|
||
class TestConfig(unittest.TestCase): | ||
@staticmethod | ||
def get_sample_config(): | ||
with open(os.path.dirname(os.path.dirname(__file__)) + | ||
"/config.sample.toml") as config: | ||
return config.read() | ||
|
||
def setUp(self): | ||
self.sample_config = self.get_sample_config() | ||
|
||
def test_sample_config(self): | ||
models.Settings(**tomli.loads(self.sample_config)) | ||
|
||
def test_invalid_config(self): | ||
config = tomli.loads(self.sample_config) | ||
config["foo"] = "bar" | ||
with pytest.raises(ValidationError) as exc_info: | ||
models.Settings(**config) | ||
assert exc_info.value.errors() == [{'loc': ('foo',), | ||
'msg': 'extra fields not permitted', | ||
'type': 'value_error.extra'}] | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |