feat: add --plain option to the show command in order to render notes as plaintext

This commit is contained in:
cătălin 2023-11-28 13:49:13 +01:00
commit af9a6d82f4
Signed by: catalin
GPG key ID: 686088EF78EE4083
14 changed files with 318 additions and 473 deletions

View file

@ -49,7 +49,7 @@ def unencrypted_notes(notebooks_path):
return unencrypted_root_path
@pytest.fixture
@pytest.fixture()
def notebooks_command(settings: Settings):
return NotebooksCommand(max_depth=float("inf"), settings=settings)
@ -58,27 +58,27 @@ def notebooks_command(settings: Settings):
def current_note(notes, settings, encryptor) -> Path:
note_path = settings.notebooks_root_path / f"{utils.now().date()}.age"
note_path.touch()
data = encryptor.encrypt("foo".encode())
data = encryptor.encrypt(b"foo")
with note_path.open("wb") as f:
f.write(data)
return note_path
@pytest.fixture
@pytest.fixture()
def current_daily(notes, settings, encryptor) -> Path:
note_path = (
settings.notebooks_root_path / "Work" / "Dailies" / f"{utils.now().date()}.age"
)
data = encryptor.encrypt("foo".encode())
data = encryptor.encrypt(b"foo")
with note_path.open("wb") as f:
f.write(data)
return note_path
@pytest.fixture
@pytest.fixture()
def mock_edit(mocker):
def edit(callargs: list):
with open(callargs[1], "wb") as f:
f.write("edited".encode())
f.write(b"edited")
mocker.patch("halig.commands.edit.subprocess.call", side_effect=edit)

View file

@ -16,7 +16,7 @@ def test_edit_raises_invalid_age_file(notes, settings: Settings):
def test_edit_current_note(mock_edit, current_note, settings: Settings, encryptor):
edit_command = EditCommand(
note_path=settings.notebooks_root_path, settings=settings
note_path=settings.notebooks_root_path, settings=settings,
)
assert edit_command.note_path == current_note
edit_command.run()

View file

@ -1,6 +1,7 @@
import pytest
from pathlib import Path
import pytest
from halig.commands.import_unencrypted import ImportCommand
from halig.encryption import Encryptor
@ -34,7 +35,7 @@ def test_import(unencrypted_notes: Path, command: ImportCommand, encryptor: Encr
def test_import_unlink(
unencrypted_notes: Path, command: ImportCommand, encryptor: Encryptor
unencrypted_notes: Path, command: ImportCommand, encryptor: Encryptor,
):
command.unlink = True
command.run()

View file

@ -26,7 +26,7 @@ def test_show_raises_note_path_is_not_age_valid(notes, settings: Settings):
def test_show_current_note(current_note, settings):
show_command = ShowCommand(
note_path=settings.notebooks_root_path, settings=settings
note_path=settings.notebooks_root_path, settings=settings,
)
assert show_command.note_path == current_note
assert show_command.decrypt() == "foo"

View file

@ -24,7 +24,7 @@ def test_instance_encryptor_from_age_keys(halig_path, notebooks_path):
f.write(str(identity.to_public()))
recipient_paths.append(recipient_path)
#cache_path = platformdirs.user_cache_path("halig", ensure_exists=True)
settings = Settings(
notebooks_root_path=notebooks_path,
identity_paths=identity_paths,

View file

@ -1,6 +1,4 @@
from typing import Callable
import pytest
from collections.abc import Callable
from halig.utils import capture