Skip to content

Commit

Permalink
Add configuration tests.
Browse files Browse the repository at this point in the history
* tests/test_config.py: New file.
  • Loading branch information
mbakke committed Feb 9, 2022
1 parent 733f949 commit 13d42cf
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_config.py
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()

0 comments on commit 13d42cf

Please sign in to comment.