File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments