This repository has been archived on 2026-11-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
WGTools-Extended/tests/test_performance_changes.py
T
asminme 3841e93e32
Wydanie WGTools-Extended / release (push) Successful in 12s
1.0.3 - poprawa wydajności panelu
2026-10-30 03:20:21 +01:00

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)