test_configuration.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from pathlib import Path
  2. import pytest
  3. from pydantic import ValidationError
  4. from zbt.core.config import BACKEND_ROOT, Settings, resolve_env_file
  5. def test_settings_load_environment_from_backend_directory() -> None:
  6. assert Settings.model_config["env_file"] == BACKEND_ROOT / ".env"
  7. def test_resolve_env_file_from_project_root(tmp_path: Path) -> None:
  8. backend = tmp_path / "backend"
  9. backend.mkdir()
  10. env_file = backend / ".env"
  11. env_file.write_text("MYSQL_USER=root\n", encoding="utf-8")
  12. assert resolve_env_file(tmp_path) == env_file
  13. assert resolve_env_file(backend) == env_file
  14. @pytest.mark.parametrize(
  15. ("field", "value"),
  16. [
  17. ("mysql_core_database", "insurance_core"),
  18. ("mysql_agent_database", "insurance_agent"),
  19. ("mysql_analytics_database", "insurance_analytics"),
  20. ("redis_prefix", "ins:"),
  21. ],
  22. )
  23. def test_stage_one_configuration_rejects_unsafe_data_targets(
  24. field: str,
  25. value: str,
  26. ) -> None:
  27. with pytest.raises(ValidationError):
  28. Settings(
  29. app_env="test",
  30. jwt_access_secret="a" * 32,
  31. jwt_refresh_secret="b" * 32,
  32. field_encryption_key="c" * 32,
  33. **{field: value},
  34. )