Archived
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
from app.core import audit, preferences
|
|
|
|
|
|
def test_settings_are_loaded_in_batches(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(preferences, 'DATABASE_PATH', str(tmp_path / 'settings.db'))
|
|
original = preferences._connect
|
|
connections = []
|
|
def connect():
|
|
connections.append(1)
|
|
return original()
|
|
monkeypatch.setattr(preferences, '_connect', connect)
|
|
assert preferences.get_preferences()['refresh_seconds'] == max(2, min(preferences.REFRESH_SECONDS, 60))
|
|
assert len(connections) == 2
|
|
connections.clear()
|
|
assert preferences.get_branding()['name'] == 'WGTools-Extended'
|
|
assert len(connections) == 2
|
|
|
|
|
|
def test_historical_connection_lookup_uses_index(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(audit, 'DATABASE_PATH', str(tmp_path / 'audit.db'))
|
|
audit.init_audit_database()
|
|
with audit._connection() as conn:
|
|
plan = conn.execute(
|
|
"EXPLAIN QUERY PLAN SELECT created_at,details FROM audit_log "
|
|
"WHERE action='wireguard.client_connected' AND object=? "
|
|
"ORDER BY created_at DESC,id DESC LIMIT 1", ('wg0 · klient',)
|
|
).fetchall()
|
|
assert any('idx_audit_connection_lookup' in str(row[3]) for row in plan)
|