tests: test commands
This commit is contained in:
parent
d3ad87211e
commit
570c29d9f1
16 changed files with 235 additions and 52 deletions
30
tests/commands/test_edit.py
Normal file
30
tests/commands/test_edit.py
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue