diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/test_config.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 81ff498..ca87403 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -497,3 +497,64 @@ def test_proxy_fix_can_be_configured_via_environment( app = create_app(EnvProxyConfig) assert app.config["PROXY_FIX_TRUSTED_HOPS"] == 1 assert app.wsgi_app.__class__.__name__ == "ProxyFix" + + +def test_sqlite_pragma_overrides_keep_default_settings(tmp_path: Path) -> None: + class PartialSQLiteConfig(TestingConfig): + LOG_FILE = str(tmp_path / "partial-sqlite-test.log") + SQLITE_PRAGMAS = {"busy_timeout": 10000, "synchronous": "normal"} + + app = create_app(PartialSQLiteConfig) + assert app.config["SQLITE_PRAGMAS"] == { + "foreign_keys": True, + "journal_mode": "WAL", + "busy_timeout": 10000, + "trusted_schema": False, + "synchronous": "NORMAL", + "cache_size": None, + "wal_autocheckpoint": None, + "journal_size_limit": None, + } + # The default mapping must not be modified by individual app overrides. + assert TestingConfig.SQLITE_PRAGMAS["busy_timeout"] == 5000 + + +@pytest.mark.parametrize( + "invalid", + [ + "PRAGMA foreign_keys=OFF", + None, + {"foreign_keys": "OFF"}, + {"journal_mode": "WAL; DROP TABLE users"}, + {"journal_mode": "MEMORY"}, + {"trusted_schema": 0}, + {"busy_timeout": -1}, + {"busy_timeout": True}, + {"cache_size": 2**32}, + {"wal_autocheckpoint": -1}, + {"journal_size_limit": -2}, + {"synchronous": "INVALID"}, + {"unsupported_pragma": 42}, + ], +) +def test_invalid_sqlite_pragmas_fail_at_startup( + tmp_path: Path, invalid: object +) -> None: + class BadSQLiteConfig(TestingConfig): + LOG_FILE = str(tmp_path / "bad-sqlite-test.log") + SQLITE_PRAGMAS = invalid + + with pytest.raises((TypeError, ValueError), match="SQLITE_PRAGMAS"): + create_app(BadSQLiteConfig) + + +def test_uppercase_sqlite_pragma_keys_support_environment_convention( + tmp_path: Path, +) -> None: + class EnvStyleSQLiteConfig(TestingConfig): + LOG_FILE = str(tmp_path / "env-style-sqlite-test.log") + SQLITE_PRAGMAS = {"CACHE_SIZE": -8192, "SYNCHRONOUS": "normal"} + + app = create_app(EnvStyleSQLiteConfig) + assert app.config["SQLITE_PRAGMAS"]["cache_size"] == -8192 + assert app.config["SQLITE_PRAGMAS"]["synchronous"] == "NORMAL" |
