mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 00:09:04 +00:00
Remove duplicate import in test
This commit is contained in:
44
src/tests/test_cli_clipboard_flag.py
Normal file
44
src/tests/test_cli_clipboard_flag.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from seedpass.cli import app, entry as cli_entry
|
||||
from seedpass.core.entry_types import EntryType
|
||||
from utils.clipboard import ClipboardUnavailableError
|
||||
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def _stub_service(ctx, raise_error=True):
|
||||
class Service:
|
||||
def search_entries(self, query, kinds=None):
|
||||
return [(1, "label", None, None, False, EntryType.PASSWORD)]
|
||||
|
||||
def retrieve_entry(self, idx):
|
||||
return {"type": EntryType.PASSWORD.value, "length": 12}
|
||||
|
||||
def generate_password(self, length, index):
|
||||
if raise_error and not ctx.obj.get("no_clipboard"):
|
||||
raise ClipboardUnavailableError("missing")
|
||||
return "pwd"
|
||||
|
||||
return Service()
|
||||
|
||||
|
||||
def test_entry_get_handles_missing_clipboard(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
cli_entry, "_get_entry_service", lambda ctx: _stub_service(ctx, True)
|
||||
)
|
||||
result = runner.invoke(app, ["entry", "get", "label"], catch_exceptions=False)
|
||||
assert result.exit_code == 1
|
||||
assert "no-clipboard" in result.stderr.lower()
|
||||
|
||||
|
||||
def test_entry_get_no_clipboard_flag(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
cli_entry, "_get_entry_service", lambda ctx: _stub_service(ctx, True)
|
||||
)
|
||||
result = runner.invoke(
|
||||
app, ["--no-clipboard", "entry", "get", "label"], catch_exceptions=False
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "pwd" in result.stdout
|
@@ -7,7 +7,9 @@ import sys
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from utils.clipboard import copy_to_clipboard
|
||||
import pytest
|
||||
|
||||
from utils.clipboard import ClipboardUnavailableError, copy_to_clipboard
|
||||
|
||||
|
||||
def test_copy_to_clipboard_clears(monkeypatch):
|
||||
@@ -69,7 +71,7 @@ def test_copy_to_clipboard_does_not_clear_if_changed(monkeypatch):
|
||||
assert clipboard["text"] == "other"
|
||||
|
||||
|
||||
def test_copy_to_clipboard_missing_dependency(monkeypatch, capsys):
|
||||
def test_copy_to_clipboard_missing_dependency(monkeypatch):
|
||||
def fail_copy(*args, **kwargs):
|
||||
raise pyperclip.PyperclipException("no copy")
|
||||
|
||||
@@ -77,6 +79,5 @@ def test_copy_to_clipboard_missing_dependency(monkeypatch, capsys):
|
||||
monkeypatch.setattr(pyperclip, "paste", lambda: "")
|
||||
monkeypatch.setattr(shutil, "which", lambda cmd: None)
|
||||
|
||||
copy_to_clipboard("secret", 1)
|
||||
out = capsys.readouterr().out
|
||||
assert "install xclip" in out.lower()
|
||||
with pytest.raises(ClipboardUnavailableError):
|
||||
copy_to_clipboard("secret", 1)
|
||||
|
Reference in New Issue
Block a user