mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-06 21:02:04 +00:00
Refactor test fixtures and fix linting issues
- Moved `client` and `dummy_nostr_client` fixtures to `src/tests/conftest.py` to fix F811 redefinition errors and improve test organization. - Introduced `make_dummy_nostr_client` factory fixture to support tests requiring multiple client instances. - Updated all affected tests to use the new fixture pattern. - Removed deprecated `is_flag=True` from Typer boolean options in CLI modules. - Fixed F541 (f-string without placeholders) in `entry_management.py`. - Fixed F841 (unused variable) in `manager.py`. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
8cdf1c523d
commit
1f92fe7901
26 files changed
+131
-120
No files matched your search
+101
-1
@@ -4,14 +4,30 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from types import SimpleNamespace
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
import bcrypt
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from helpers import create_vault, TEST_PASSWORD, TEST_SEED
|
||||
from seedpass import api
|
||||
from seedpass.core.entry_types import EntryType
|
||||
from helpers import (
|
||||
create_vault,
|
||||
TEST_PASSWORD,
|
||||
TEST_SEED,
|
||||
DummyBuilder,
|
||||
DummyFilter,
|
||||
DummyTag,
|
||||
DummyTimestamp,
|
||||
DummyEventId,
|
||||
DummyRelayClient,
|
||||
)
|
||||
from seedpass.core.backup import BackupManager
|
||||
from seedpass.core.config_manager import ConfigManager
|
||||
from seedpass.core.entry_management import EntryManager
|
||||
from seedpass.core.manager import EncryptionMode, PasswordManager
|
||||
from seedpass.core.encryption import EncryptionManager as EncMgr
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
@@ -94,3 +110,87 @@ def password_manager(vault, tmp_path):
|
||||
pm.is_dirty = False
|
||||
pm.secret_mode_enabled = False
|
||||
return pm
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def client(monkeypatch):
|
||||
dummy = SimpleNamespace(
|
||||
entry_manager=SimpleNamespace(
|
||||
search_entries=lambda q: [
|
||||
(1, "Site", "user", "url", False, EntryType.PASSWORD)
|
||||
],
|
||||
retrieve_entry=lambda i: {"label": "Site"},
|
||||
add_entry=lambda *a, **k: 1,
|
||||
modify_entry=lambda *a, **k: None,
|
||||
archive_entry=lambda i: None,
|
||||
restore_entry=lambda i: None,
|
||||
),
|
||||
config_manager=SimpleNamespace(
|
||||
load_config=lambda require_pin=False: {"k": "v"},
|
||||
set_pin=lambda v: None,
|
||||
set_password_hash=lambda v: None,
|
||||
set_relays=lambda v, require_pin=False: None,
|
||||
set_inactivity_timeout=lambda v: None,
|
||||
set_additional_backup_path=lambda v: None,
|
||||
set_secret_mode_enabled=lambda v: None,
|
||||
set_clipboard_clear_delay=lambda v: None,
|
||||
set_quick_unlock=lambda v: None,
|
||||
),
|
||||
fingerprint_manager=SimpleNamespace(list_fingerprints=lambda: ["fp"]),
|
||||
nostr_client=SimpleNamespace(
|
||||
key_manager=SimpleNamespace(get_npub=lambda: "np")
|
||||
),
|
||||
verify_password=lambda pw: True,
|
||||
)
|
||||
monkeypatch.setattr(api, "PasswordManager", lambda: dummy)
|
||||
monkeypatch.setenv("SEEDPASS_CORS_ORIGINS", "http://example.com")
|
||||
token = api.start_server()
|
||||
transport = ASGITransport(app=api.app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as ac:
|
||||
yield ac, token
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_dummy_nostr_client(monkeypatch):
|
||||
"""Factory to return a NostrClient wired to a DummyRelayClient."""
|
||||
from cryptography.fernet import Fernet
|
||||
from nostr.client import NostrClient
|
||||
|
||||
def _make(base_path):
|
||||
relay = DummyRelayClient()
|
||||
monkeypatch.setattr("nostr.client.Client", lambda signer: relay)
|
||||
monkeypatch.setattr("nostr.client.EventBuilder", DummyBuilder)
|
||||
monkeypatch.setattr("nostr.client.Filter", DummyFilter)
|
||||
monkeypatch.setattr("nostr.client.Tag", DummyTag)
|
||||
monkeypatch.setattr("nostr.client.Timestamp", DummyTimestamp)
|
||||
monkeypatch.setattr("nostr.client.EventId", DummyEventId)
|
||||
from nostr.backup_models import KIND_DELTA as KD
|
||||
|
||||
monkeypatch.setattr("nostr.client.KIND_DELTA", KD, raising=False)
|
||||
monkeypatch.setattr(NostrClient, "initialize_client_pool", lambda self: None)
|
||||
|
||||
enc_mgr = EncMgr(Fernet.generate_key(), base_path)
|
||||
|
||||
class DummyKeys:
|
||||
def private_key_hex(self):
|
||||
return "1" * 64
|
||||
|
||||
def public_key_hex(self):
|
||||
return "2" * 64
|
||||
|
||||
class DummyKeyManager:
|
||||
def __init__(self, *a, **k):
|
||||
self.keys = DummyKeys()
|
||||
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.setattr("nostr.client.KeyManager", DummyKeyManager)
|
||||
mp.setattr(enc_mgr, "decrypt_parent_seed", lambda: TEST_SEED)
|
||||
client = NostrClient(enc_mgr, "fp")
|
||||
return client, relay
|
||||
|
||||
return _make
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_nostr_client(make_dummy_nostr_client, tmp_path):
|
||||
return make_dummy_nostr_client(tmp_path)
|
||||
Reference in new issue
Block a user