cteward-ng/cteward-ng/tests/test_config.py
2026-06-06 10:18:15 +02:00

55 lines
1.5 KiB
Python

"""Test configuration loading.
Verifies that config.py loads the JSON config and applies defaults
the same way startup.js does.
"""
import json
import os
import tempfile
import pytest
from cteward_ng.config import load_config
class TestLoadConfig:
def test_loads_json_file(self):
with tempfile.NamedTemporaryFile(
mode='w', suffix='.json', delete=False
) as fh:
json.dump({'mssql': {'password': 'test'}}, fh)
fh.flush()
config = load_config(fh.name)
os.unlink(fh.name)
assert config['mssql']['password'] == 'test'
def test_applies_defaults(self):
with tempfile.NamedTemporaryFile(
mode='w', suffix='.json', delete=False
) as fh:
json.dump({}, fh)
fh.flush()
config = load_config(fh.name)
os.unlink(fh.name)
assert 'mssql' in config
assert 'server' in config
assert 'auth' in config
assert 'bots' in config['auth']
assert 'flags' in config['auth']
def test_missing_file_returns_empty(self):
config = load_config('/nonexistent/path.json')
assert config == {}
def test_invalid_json_returns_empty(self):
with tempfile.NamedTemporaryFile(
mode='w', suffix='.json', delete=False
) as fh:
fh.write('{invalid json}')
fh.flush()
config = load_config(fh.name)
os.unlink(fh.name)
assert config == {}