From af8c602988fc12ecaa57a0ae28462c8ab2a0dd5c Mon Sep 17 00:00:00 2001 From: Tianyu Liu Date: Fri, 12 Jun 2026 16:57:54 +0200 Subject: [PATCH] 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). --- .env.example | 2 -- app/config.py | 13 ------------- app/services/config_page.py | 2 -- tests/conftest.py | 10 ---------- tests/test_config.py | 10 +--------- tests/test_public_ip.py | 2 -- tests/test_smtp.py | 2 -- 7 files changed, 1 insertion(+), 40 deletions(-) diff --git a/.env.example b/.env.example index 4156f17..b0297cd 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,6 @@ APP_NAME=Home Automation Backend (Python) APP_ENV=production APP_HOSTNAME=home-automation.example.com 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_PASSWORD=change-me diff --git a/app/config.py b/app/config.py index 29adab5..7140b61 100644 --- a/app/config.py +++ b/app/config.py @@ -12,9 +12,6 @@ class Settings(BaseSettings): app_hostname: str = "localhost:8000" 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_secret: str = "" ticktick_token: str = "" @@ -77,21 +74,11 @@ class Settings(BaseSettings): raw_path = database_url[len(prefix) :] 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 @property def app_sqlite_path(self) -> Path | None: 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 @property def auth_cookie_secure(self) -> bool: diff --git a/app/services/config_page.py b/app/services/config_page.py index 956417f..4deaaf4 100644 --- a/app/services/config_page.py +++ b/app/services/config_page.py @@ -260,8 +260,6 @@ def _settings_payload(settings: Settings) -> dict[str, Any]: "app_debug": settings.app_debug, "app_hostname": settings.app_hostname, "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_secret": settings.ticktick_client_secret, "ticktick_token": settings.ticktick_token, diff --git a/tests/conftest.py b/tests/conftest.py index da18463..55537f8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,15 +20,9 @@ def _make_app_alembic_config(database_url: str) -> Config: @pytest.fixture def test_database_urls(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): 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}" - 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("LOCATION_DATABASE_URL", location_database_url) - monkeypatch.setenv("POO_DATABASE_URL", poo_database_url) monkeypatch.setenv("AUTH_BOOTSTRAP_USERNAME", "admin") monkeypatch.setenv("AUTH_BOOTSTRAP_PASSWORD", "test-password") monkeypatch.setenv("AUTH_COOKIE_SECURE_OVERRIDE", "false") @@ -39,10 +33,6 @@ def test_database_urls(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): yield { "app_path": app_database_path, "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: get_settings.cache_clear() diff --git a/tests/test_config.py b/tests/test_config.py index 6aea8d0..458ebf0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,10 +1,8 @@ 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("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("POO_WEBHOOK_ID", "poo-hook") 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) 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_sensor_entity_name == "sensor.test_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_session_cookie_name == "auth_cookie" 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.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 diff --git a/tests/test_public_ip.py b/tests/test_public_ip.py index a8a9558..6f88fdf 100644 --- a/tests/test_public_ip.py +++ b/tests/test_public_ip.py @@ -182,8 +182,6 @@ def _notification_settings() -> Settings: app_env="development", app_hostname="localhost:8000", 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_password="secret-password", smtp_enabled=True, diff --git a/tests/test_smtp.py b/tests/test_smtp.py index 2881da6..5d06635 100644 --- a/tests/test_smtp.py +++ b/tests/test_smtp.py @@ -40,8 +40,6 @@ def _smtp_settings(**overrides) -> Settings: "app_env": "development", "app_hostname": "localhost:8000", "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_password": "secret-password", "smtp_enabled": True,