Files
SeedPass/src/tests/test_generate_test_profile_sync.py
T
google-labs-jules[bot]andPR0M3TH3AN 49c4da7ff0 Fix CI formatting failure and linting issues
- Reformatted `src/tests/helpers.py`, `src/tests/test_generate_test_profile_sync.py`, `src/tests/test_manifest_id_privacy.py`, and `src/tests/test_restore_from_nostr_setup.py` using `black`.
- Refactored `src/tests/helpers.py` to fix dispersed imports and remove unused imports (`time`, `asyncio`), resolving `flake8` warnings.
- Split long lines in `src/tests/helpers.py` to improve readability and compliance with style guides.
- Verified formatting with `black --check .`.
- Verified all tests pass with `pytest`.
- Confirmed `flake8` errors related to line length in `helpers.py` are acceptable as CI does not enforce strict 79-char limit (using `black` defaults).

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 04:05:16 +00:00

71 lines
2.2 KiB
Python

import importlib
import importlib.util
from pathlib import Path
from tempfile import TemporaryDirectory
import asyncio
import gzip
def load_script():
script_path = (
Path(__file__).resolve().parents[2] / "scripts" / "generate_test_profile.py"
)
spec = importlib.util.spec_from_file_location("generate_test_profile", script_path)
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
return module
def test_generate_test_profile_sync(monkeypatch, dummy_nostr_client):
client, _relay = dummy_nostr_client
with TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
monkeypatch.setattr(Path, "home", lambda: tmp_path)
constants = importlib.import_module("constants")
importlib.reload(constants)
gtp = load_script()
monkeypatch.setattr(gtp, "NostrClient", lambda *a, **k: client)
seed, entry_mgr, dir_path, fingerprint, cfg_mgr = gtp.initialize_profile("test")
gtp.populate(entry_mgr, seed, 5)
encrypted = entry_mgr.vault.get_encrypted_index()
nc = gtp.NostrClient(
entry_mgr.vault.encryption_manager,
fingerprint,
parent_seed=seed,
config_manager=cfg_mgr,
)
asyncio.run(nc.publish_snapshot(encrypted))
from nostr.client import NostrClient as RealClient
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()
monkeypatch.setattr("nostr.client.KeyManager", DummyKeyManager)
client2 = RealClient(
entry_mgr.vault.encryption_manager,
fingerprint,
parent_seed=seed,
config_manager=cfg_mgr,
)
result = asyncio.run(client2.fetch_latest_snapshot())
assert result is not None
_manifest, chunks = result
assert _manifest.delta_since is None
retrieved = gzip.decompress(b"".join(chunks))
assert retrieved == encrypted