M1-T05: drop location/poo database config from Settings and tests
Remove the dead location_database_url / poo_database_url fields and the location_sqlite_path / poo_sqlite_path computed properties from Settings; drop them from the config-page payload and from .env.example. Update the test hardcodes (test_config, test_public_ip, test_smtp) and reduce the conftest test_database_urls fixture to the single app DB. The one-time migration script keeps reading legacy URLs from env/CLI, independent of Settings. pytest 95 passed; ruff clean (pre-existing only).
This commit is contained in:
@@ -4,8 +4,6 @@ APP_NAME=Home Automation Backend (Python)
|
|||||||
APP_ENV=production
|
APP_ENV=production
|
||||||
APP_HOSTNAME=home-automation.example.com
|
APP_HOSTNAME=home-automation.example.com
|
||||||
APP_DATABASE_URL=sqlite:////app/data/app.db
|
APP_DATABASE_URL=sqlite:////app/data/app.db
|
||||||
LOCATION_DATABASE_URL=sqlite:////app/data/locationRecorder.db
|
|
||||||
POO_DATABASE_URL=sqlite:////app/data/pooRecorder.db
|
|
||||||
AUTH_BOOTSTRAP_USERNAME=admin
|
AUTH_BOOTSTRAP_USERNAME=admin
|
||||||
AUTH_BOOTSTRAP_PASSWORD=change-me
|
AUTH_BOOTSTRAP_PASSWORD=change-me
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ class Settings(BaseSettings):
|
|||||||
app_hostname: str = "localhost:8000"
|
app_hostname: str = "localhost:8000"
|
||||||
app_database_url: str = "sqlite:///./data/app.db"
|
app_database_url: str = "sqlite:///./data/app.db"
|
||||||
|
|
||||||
location_database_url: str = "sqlite:///./data/locationRecorder.db"
|
|
||||||
poo_database_url: str = "sqlite:///./data/pooRecorder.db"
|
|
||||||
|
|
||||||
ticktick_client_id: str = ""
|
ticktick_client_id: str = ""
|
||||||
ticktick_client_secret: str = ""
|
ticktick_client_secret: str = ""
|
||||||
ticktick_token: str = ""
|
ticktick_token: str = ""
|
||||||
@@ -77,21 +74,11 @@ class Settings(BaseSettings):
|
|||||||
raw_path = database_url[len(prefix) :]
|
raw_path = database_url[len(prefix) :]
|
||||||
return Path(raw_path)
|
return Path(raw_path)
|
||||||
|
|
||||||
@computed_field
|
|
||||||
@property
|
|
||||||
def location_sqlite_path(self) -> Path | None:
|
|
||||||
return self._sqlite_path_from_url(self.location_database_url)
|
|
||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
@property
|
@property
|
||||||
def app_sqlite_path(self) -> Path | None:
|
def app_sqlite_path(self) -> Path | None:
|
||||||
return self._sqlite_path_from_url(self.app_database_url)
|
return self._sqlite_path_from_url(self.app_database_url)
|
||||||
|
|
||||||
@computed_field
|
|
||||||
@property
|
|
||||||
def poo_sqlite_path(self) -> Path | None:
|
|
||||||
return self._sqlite_path_from_url(self.poo_database_url)
|
|
||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
@property
|
@property
|
||||||
def auth_cookie_secure(self) -> bool:
|
def auth_cookie_secure(self) -> bool:
|
||||||
|
|||||||
@@ -260,8 +260,6 @@ def _settings_payload(settings: Settings) -> dict[str, Any]:
|
|||||||
"app_debug": settings.app_debug,
|
"app_debug": settings.app_debug,
|
||||||
"app_hostname": settings.app_hostname,
|
"app_hostname": settings.app_hostname,
|
||||||
"app_database_url": settings.app_database_url,
|
"app_database_url": settings.app_database_url,
|
||||||
"location_database_url": settings.location_database_url,
|
|
||||||
"poo_database_url": settings.poo_database_url,
|
|
||||||
"ticktick_client_id": settings.ticktick_client_id,
|
"ticktick_client_id": settings.ticktick_client_id,
|
||||||
"ticktick_client_secret": settings.ticktick_client_secret,
|
"ticktick_client_secret": settings.ticktick_client_secret,
|
||||||
"ticktick_token": settings.ticktick_token,
|
"ticktick_token": settings.ticktick_token,
|
||||||
|
|||||||
@@ -20,15 +20,9 @@ def _make_app_alembic_config(database_url: str) -> Config:
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_database_urls(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
def test_database_urls(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||||
app_database_path = tmp_path / "app_test.db"
|
app_database_path = tmp_path / "app_test.db"
|
||||||
location_database_path = tmp_path / "location_test.db"
|
|
||||||
poo_database_path = tmp_path / "poo_placeholder.db"
|
|
||||||
app_database_url = f"sqlite:///{app_database_path}"
|
app_database_url = f"sqlite:///{app_database_path}"
|
||||||
location_database_url = f"sqlite:///{location_database_path}"
|
|
||||||
poo_database_url = f"sqlite:///{poo_database_path}"
|
|
||||||
|
|
||||||
monkeypatch.setenv("APP_DATABASE_URL", app_database_url)
|
monkeypatch.setenv("APP_DATABASE_URL", app_database_url)
|
||||||
monkeypatch.setenv("LOCATION_DATABASE_URL", location_database_url)
|
|
||||||
monkeypatch.setenv("POO_DATABASE_URL", poo_database_url)
|
|
||||||
monkeypatch.setenv("AUTH_BOOTSTRAP_USERNAME", "admin")
|
monkeypatch.setenv("AUTH_BOOTSTRAP_USERNAME", "admin")
|
||||||
monkeypatch.setenv("AUTH_BOOTSTRAP_PASSWORD", "test-password")
|
monkeypatch.setenv("AUTH_BOOTSTRAP_PASSWORD", "test-password")
|
||||||
monkeypatch.setenv("AUTH_COOKIE_SECURE_OVERRIDE", "false")
|
monkeypatch.setenv("AUTH_COOKIE_SECURE_OVERRIDE", "false")
|
||||||
@@ -39,10 +33,6 @@ def test_database_urls(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
|||||||
yield {
|
yield {
|
||||||
"app_path": app_database_path,
|
"app_path": app_database_path,
|
||||||
"app_url": app_database_url,
|
"app_url": app_database_url,
|
||||||
"location_path": location_database_path,
|
|
||||||
"location_url": location_database_url,
|
|
||||||
"poo_path": poo_database_path,
|
|
||||||
"poo_url": poo_database_url,
|
|
||||||
}
|
}
|
||||||
finally:
|
finally:
|
||||||
get_settings.cache_clear()
|
get_settings.cache_clear()
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
from app.config import Settings
|
from app.config import Settings
|
||||||
|
|
||||||
|
|
||||||
def test_settings_support_two_independent_database_urls(monkeypatch) -> None:
|
def test_settings_load_core_fields_from_env(monkeypatch) -> None:
|
||||||
monkeypatch.setenv("APP_DATABASE_URL", "sqlite:///./data/app.db")
|
monkeypatch.setenv("APP_DATABASE_URL", "sqlite:///./data/app.db")
|
||||||
monkeypatch.setenv("LOCATION_DATABASE_URL", "sqlite:///./data/locationRecorder.db")
|
|
||||||
monkeypatch.setenv("POO_DATABASE_URL", "sqlite:///./data/pooRecorder.db")
|
|
||||||
monkeypatch.setenv("APP_HOSTNAME", "home.example.com")
|
monkeypatch.setenv("APP_HOSTNAME", "home.example.com")
|
||||||
monkeypatch.setenv("POO_WEBHOOK_ID", "poo-hook")
|
monkeypatch.setenv("POO_WEBHOOK_ID", "poo-hook")
|
||||||
monkeypatch.setenv("POO_SENSOR_ENTITY_NAME", "sensor.test_poo_status")
|
monkeypatch.setenv("POO_SENSOR_ENTITY_NAME", "sensor.test_poo_status")
|
||||||
@@ -21,8 +19,6 @@ def test_settings_support_two_independent_database_urls(monkeypatch) -> None:
|
|||||||
settings = Settings(_env_file=None)
|
settings = Settings(_env_file=None)
|
||||||
|
|
||||||
assert settings.app_database_url == "sqlite:///./data/app.db"
|
assert settings.app_database_url == "sqlite:///./data/app.db"
|
||||||
assert settings.location_database_url == "sqlite:///./data/locationRecorder.db"
|
|
||||||
assert settings.poo_database_url == "sqlite:///./data/pooRecorder.db"
|
|
||||||
assert settings.poo_webhook_id == "poo-hook"
|
assert settings.poo_webhook_id == "poo-hook"
|
||||||
assert settings.poo_sensor_entity_name == "sensor.test_poo_status"
|
assert settings.poo_sensor_entity_name == "sensor.test_poo_status"
|
||||||
assert settings.poo_sensor_friendly_name == "Poo Status"
|
assert settings.poo_sensor_friendly_name == "Poo Status"
|
||||||
@@ -36,12 +32,8 @@ def test_settings_support_two_independent_database_urls(monkeypatch) -> None:
|
|||||||
assert settings.auth_bootstrap_password == "secret"
|
assert settings.auth_bootstrap_password == "secret"
|
||||||
assert settings.auth_session_cookie_name == "auth_cookie"
|
assert settings.auth_session_cookie_name == "auth_cookie"
|
||||||
assert settings.auth_session_ttl_hours == 8
|
assert settings.auth_session_ttl_hours == 8
|
||||||
assert settings.location_sqlite_path is not None
|
|
||||||
assert settings.location_sqlite_path.name == "locationRecorder.db"
|
|
||||||
assert settings.app_sqlite_path is not None
|
assert settings.app_sqlite_path is not None
|
||||||
assert settings.app_sqlite_path.name == "app.db"
|
assert settings.app_sqlite_path.name == "app.db"
|
||||||
assert settings.poo_sqlite_path is not None
|
|
||||||
assert settings.poo_sqlite_path.name == "pooRecorder.db"
|
|
||||||
assert settings.auth_cookie_secure is True
|
assert settings.auth_cookie_secure is True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -182,8 +182,6 @@ def _notification_settings() -> Settings:
|
|||||||
app_env="development",
|
app_env="development",
|
||||||
app_hostname="localhost:8000",
|
app_hostname="localhost:8000",
|
||||||
app_database_url="sqlite:///./data/app.db",
|
app_database_url="sqlite:///./data/app.db",
|
||||||
location_database_url="sqlite:///./data/locationRecorder.db",
|
|
||||||
poo_database_url="sqlite:///./data/pooRecorder.db",
|
|
||||||
auth_bootstrap_username="admin",
|
auth_bootstrap_username="admin",
|
||||||
auth_bootstrap_password="secret-password",
|
auth_bootstrap_password="secret-password",
|
||||||
smtp_enabled=True,
|
smtp_enabled=True,
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ def _smtp_settings(**overrides) -> Settings:
|
|||||||
"app_env": "development",
|
"app_env": "development",
|
||||||
"app_hostname": "localhost:8000",
|
"app_hostname": "localhost:8000",
|
||||||
"app_database_url": "sqlite:///./data/app.db",
|
"app_database_url": "sqlite:///./data/app.db",
|
||||||
"location_database_url": "sqlite:///./data/locationRecorder.db",
|
|
||||||
"poo_database_url": "sqlite:///./data/pooRecorder.db",
|
|
||||||
"auth_bootstrap_username": "admin",
|
"auth_bootstrap_username": "admin",
|
||||||
"auth_bootstrap_password": "secret-password",
|
"auth_bootstrap_password": "secret-password",
|
||||||
"smtp_enabled": True,
|
"smtp_enabled": True,
|
||||||
|
|||||||
Reference in New Issue
Block a user