tests/test_vault_lock.py
912 B · 32 lines · python Raw
1 """Tests for Wallet lock/unlock semantics."""
2
3 from __future__ import annotations
4
5 import pytest
6
7 from pqc_agent_wallet import Wallet
8 from pqc_agent_wallet.errors import WalletLockedError
9
10
11 def test_lock_clears_key(open_wallet: Wallet) -> None:
12 assert open_wallet.is_unlocked
13 open_wallet.lock()
14 assert not open_wallet.is_unlocked
15
16
17 def test_operations_fail_after_lock(open_wallet: Wallet) -> None:
18 open_wallet.lock()
19 with pytest.raises(WalletLockedError):
20 open_wallet.get("openai_api_key")
21 with pytest.raises(WalletLockedError):
22 open_wallet.put("foo", "bar")
23 with pytest.raises(WalletLockedError):
24 open_wallet.delete("openai_api_key")
25
26
27 def test_context_manager_locks_on_exit(open_wallet: Wallet) -> None:
28 with open_wallet as w:
29 assert w.is_unlocked
30 assert w.get("openai_api_key") == "sk-test-openai"
31 assert not open_wallet.is_unlocked
32