mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 08:19:23 +00:00
Add backup interval setting and throttled backups
This commit is contained in:
34
src/tests/test_backup_interval.py
Normal file
34
src/tests/test_backup_interval.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import time
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from helpers import create_vault, TEST_SEED, TEST_PASSWORD
|
||||
|
||||
from password_manager.backup import BackupManager
|
||||
from password_manager.config_manager import ConfigManager
|
||||
|
||||
|
||||
def test_backup_interval(monkeypatch):
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
fp_dir = Path(tmpdir)
|
||||
vault, _ = create_vault(fp_dir, TEST_SEED, TEST_PASSWORD)
|
||||
cfg_mgr = ConfigManager(vault, fp_dir)
|
||||
cfg_mgr.set_backup_interval(10)
|
||||
backup_mgr = BackupManager(fp_dir, cfg_mgr)
|
||||
|
||||
vault.save_index({"entries": {}})
|
||||
|
||||
monkeypatch.setattr(time, "time", lambda: 1000)
|
||||
backup_mgr.create_backup()
|
||||
first = fp_dir / "backups" / "entries_db_backup_1000.json.enc"
|
||||
assert first.exists()
|
||||
|
||||
monkeypatch.setattr(time, "time", lambda: 1005)
|
||||
backup_mgr.create_backup()
|
||||
second = fp_dir / "backups" / "entries_db_backup_1005.json.enc"
|
||||
assert not second.exists()
|
||||
|
||||
monkeypatch.setattr(time, "time", lambda: 1012)
|
||||
backup_mgr.create_backup()
|
||||
third = fp_dir / "backups" / "entries_db_backup_1012.json.enc"
|
||||
assert third.exists()
|
Reference in New Issue
Block a user