Add migration to version 2 and update tests

This commit is contained in:
thePR0M3TH3AN
2025-07-02 22:16:18 -04:00
parent 0bae741f36
commit 47d9e9d8e4
10 changed files with 70 additions and 37 deletions

View File

@@ -13,18 +13,19 @@ def setup(tmp_path: Path):
return enc_mgr, vault
def test_migrate_v0_to_v1(tmp_path: Path):
def test_migrate_v0_to_v2(tmp_path: Path):
enc_mgr, vault = setup(tmp_path)
legacy = {"passwords": {"0": {"website": "a", "length": 8}}}
enc_mgr.save_json_data(legacy)
data = vault.load_index()
assert data["schema_version"] == LATEST_VERSION
assert data["passwords"] == legacy["passwords"]
expected_entry = {"website": "a", "length": 8, "type": "password", "notes": ""}
assert data["entries"]["0"] == expected_entry
def test_error_on_future_version(tmp_path: Path):
enc_mgr, vault = setup(tmp_path)
future = {"schema_version": LATEST_VERSION + 1, "passwords": {}}
future = {"schema_version": LATEST_VERSION + 1, "entries": {}}
enc_mgr.save_json_data(future)
with pytest.raises(ValueError):
vault.load_index()