tests: test commands

This commit is contained in:
cătălin 2023-04-03 18:40:11 +02:00
commit 570c29d9f1
Signed by: catalin
GPG key ID: 686088EF78EE4083
16 changed files with 235 additions and 52 deletions

View file

@ -0,0 +1,30 @@
import pytest
from halig.commands.edit import EditCommand
from halig.settings import Settings
def test_edit_raises_invalid_age_file(notes, settings: Settings):
note_path = settings.notebooks_root_path / "foo.txt"
note_path.touch()
with pytest.raises(ValueError, match="is not a valid AGE file"):
EditCommand(note_path, 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)
assert edit_command.note_path == current_note
edit_command.run()
with current_note.open("rb") as f:
contents = encryptor.decrypt(f.read()).decode()
assert contents == "edited"
def test_edit_current_daily(mock_edit, current_daily, settings, encryptor):
current_daily.unlink()
edit_command = EditCommand(note_path=current_daily, settings=settings)
assert edit_command.note_path == current_daily
edit_command.run()
with current_daily.open("rb") as f:
contents = encryptor.decrypt(f.read()).decode()
assert contents == "edited"