test_app_config.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import tempfile
  2. import unittest
  3. from pathlib import Path
  4. from app_config import load_config
  5. class AppConfigTest(unittest.TestCase):
  6. def test_load_config_with_defaults(self):
  7. with tempfile.TemporaryDirectory() as tmp_dir:
  8. path = Path(tmp_dir) / "config.yaml"
  9. path.write_text(
  10. """
  11. db:
  12. host: 127.0.0.1
  13. port: 5432
  14. database: test_db
  15. user: postgres
  16. password: secret
  17. """.strip(),
  18. encoding="utf-8",
  19. )
  20. config = load_config(path)
  21. self.assertEqual(config.db.host, "127.0.0.1")
  22. self.assertEqual(config.db.port, 5432)
  23. self.assertEqual(config.modbus.host, "0.0.0.0")
  24. self.assertEqual(config.modbus.port, 502)
  25. self.assertEqual(config.http_provider.interval, 5)
  26. self.assertEqual(config.http_provider.batch_size, 200)
  27. self.assertEqual(config.logging.retention_days, 3)
  28. def test_load_http_provider_refresh_options(self):
  29. with tempfile.TemporaryDirectory() as tmp_dir:
  30. path = Path(tmp_dir) / "config.yaml"
  31. path.write_text(
  32. """
  33. db:
  34. host: 127.0.0.1
  35. port: 5432
  36. database: test_db
  37. user: postgres
  38. password: secret
  39. http_provider:
  40. interval: 10
  41. batch_size: 50
  42. """.strip(),
  43. encoding="utf-8",
  44. )
  45. config = load_config(path)
  46. self.assertEqual(config.http_provider.interval, 10)
  47. self.assertEqual(config.http_provider.batch_size, 50)
  48. if __name__ == "__main__":
  49. unittest.main()