Add config unittest
This commit is contained in:
parent
70e980c5c0
commit
a8d04afb01
2 changed files with 37 additions and 0 deletions
0
spaceapi_server/config/test/__init__.py
Normal file
0
spaceapi_server/config/test/__init__.py
Normal file
37
spaceapi_server/config/test/test_config.py
Normal file
37
spaceapi_server/config/test/test_config.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from spaceapi_server.config import load, get, get_plugin_config
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigTest(unittest.TestCase):
|
||||||
|
|
||||||
|
CONFIG = '''
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"baz": 42,
|
||||||
|
"plugins": {
|
||||||
|
"myplugin": {
|
||||||
|
"foo": "baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
_, self.temp = tempfile.mkstemp('.json', 'spaceapi_server_config_', text=True)
|
||||||
|
with open(self.temp, 'w') as f:
|
||||||
|
f.write(self.CONFIG)
|
||||||
|
|
||||||
|
def test_load(self):
|
||||||
|
pre = get()
|
||||||
|
pre_plugin = get_plugin_config('myplugin')
|
||||||
|
self.assertEqual({}, pre)
|
||||||
|
self.assertEqual({}, pre_plugin)
|
||||||
|
load(self.temp)
|
||||||
|
post = get()
|
||||||
|
post_plugin = get_plugin_config('myplugin')
|
||||||
|
self.assertEqual('bar', post['foo'])
|
||||||
|
self.assertEqual(42, post['baz'])
|
||||||
|
self.assertEqual('baz', post_plugin['foo'])
|
Loading…
Reference in a new issue