mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 08:19:23 +00:00
Return success status from Nostr publish
This commit is contained in:
27
src/tests/test_post_sync_messages.py
Normal file
27
src/tests/test_post_sync_messages.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
import main
|
||||
|
||||
|
||||
def test_handle_post_success(capsys):
|
||||
pm = SimpleNamespace(
|
||||
get_encrypted_data=lambda: b"data",
|
||||
nostr_client=SimpleNamespace(publish_json_to_nostr=lambda data: True),
|
||||
)
|
||||
main.handle_post_to_nostr(pm)
|
||||
out = capsys.readouterr().out
|
||||
assert "✅ Sync complete." in out
|
||||
|
||||
|
||||
def test_handle_post_failure(capsys):
|
||||
pm = SimpleNamespace(
|
||||
get_encrypted_data=lambda: b"data",
|
||||
nostr_client=SimpleNamespace(publish_json_to_nostr=lambda data: False),
|
||||
)
|
||||
main.handle_post_to_nostr(pm)
|
||||
out = capsys.readouterr().out
|
||||
assert "❌ Sync failed…" in out
|
52
src/tests/test_publish_json_result.py
Normal file
52
src/tests/test_publish_json_result.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import patch
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from password_manager.encryption import EncryptionManager
|
||||
from nostr.client import NostrClient
|
||||
|
||||
|
||||
def setup_client(tmp_path):
|
||||
key = Fernet.generate_key()
|
||||
enc_mgr = EncryptionManager(key, tmp_path)
|
||||
|
||||
with patch("nostr.client.ClientPool"), patch(
|
||||
"nostr.client.KeyManager"
|
||||
), patch.object(NostrClient, "initialize_client_pool"), patch.object(
|
||||
enc_mgr, "decrypt_parent_seed", return_value="seed"
|
||||
):
|
||||
client = NostrClient(enc_mgr, "fp")
|
||||
return client
|
||||
|
||||
|
||||
class FakeEvent:
|
||||
KIND_TEXT_NOTE = 1
|
||||
KIND_ENCRYPT = 2
|
||||
|
||||
def __init__(self, kind, content, pub_key):
|
||||
self.kind = kind
|
||||
self.content = content
|
||||
self.pub_key = pub_key
|
||||
self.id = "id"
|
||||
|
||||
def sign(self, _):
|
||||
pass
|
||||
|
||||
|
||||
def test_publish_json_success():
|
||||
with TemporaryDirectory() as tmpdir, patch("nostr.client.Event", FakeEvent):
|
||||
client = setup_client(Path(tmpdir))
|
||||
with patch.object(client, "publish_event") as mock_pub:
|
||||
assert client.publish_json_to_nostr(b"data") is True
|
||||
mock_pub.assert_called()
|
||||
|
||||
|
||||
def test_publish_json_failure():
|
||||
with TemporaryDirectory() as tmpdir, patch("nostr.client.Event", FakeEvent):
|
||||
client = setup_client(Path(tmpdir))
|
||||
with patch.object(client, "publish_event", side_effect=Exception("boom")):
|
||||
assert client.publish_json_to_nostr(b"data") is False
|
Reference in New Issue
Block a user