feat: add -c/--config flag to every command

This commit is contained in:
cătălin 2023-03-04 23:16:00 +02:00
commit 6f45b76579
Signed by: catalin
GPG key ID: 686088EF78EE4083
10 changed files with 163 additions and 51 deletions

View file

@ -10,15 +10,15 @@ from halig.settings import Settings
@pytest.fixture()
def notes(notebooks_path: Path):
personal = (notebooks_path / "Personal")
work = (notebooks_path / "Work")
personal = notebooks_path / "Personal"
work = notebooks_path / "Work"
personal.mkdir()
work.mkdir()
personal_todos = (personal / "todos.age")
personal_todos = personal / "todos.age"
personal_todos.touch()
work_todos = (work / "todos.age")
work_todos = work / "todos.age"
work_todos.touch()
dailies = work / "Dailies"
@ -47,7 +47,9 @@ def current_note(notes, settings, encryptor) -> Path:
@pytest.fixture
def current_daily(notes, settings, encryptor) -> Path:
note_path = settings.notebooks_root_path / "Work" / "Dailies" / f"{utils.now().date()}.age"
note_path = (
settings.notebooks_root_path / "Work" / "Dailies" / f"{utils.now().date()}.age"
)
data = encryptor.encrypt("foo".encode())
with note_path.open("wb") as f:
f.write(data)
@ -60,4 +62,4 @@ def mock_edit(mocker):
with open(callargs[1], "wb") as f:
f.write("edited".encode())
mocker.patch('halig.commands.edit.subprocess.call', side_effect=edit)
mocker.patch("halig.commands.edit.subprocess.call", side_effect=edit)

View file

@ -8,11 +8,16 @@ 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, )
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)
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:

View file

@ -8,18 +8,26 @@ from halig.settings import Settings
def test_show_raises_note_path_does_not_exist(notes, settings: Settings):
with pytest.raises(ValueError, match="does not exist"):
ShowCommand(Path('foo'), settings=settings, )
ShowCommand(
Path("foo"),
settings=settings,
)
def test_show_raises_note_path_is_not_age_valid(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"):
ShowCommand(note_path, settings=settings, )
ShowCommand(
note_path,
settings=settings,
)
def test_show_current_note(current_note, settings):
show_command = ShowCommand(note_path=settings.notebooks_root_path, settings=settings)
show_command = ShowCommand(
note_path=settings.notebooks_root_path, settings=settings
)
assert show_command.note_path == current_note
assert show_command.decrypt() == "foo"

View file

@ -12,9 +12,11 @@ from halig.settings import Settings
@pytest.fixture()
def halig_ssh_public_key():
return "ssh-ed25519 " \
"AAAAC3NzaC1lZDI1NTE5AAAAIGjHhIF/DlVCb2dRFMlKia7nij1Aq+zRDCaMIwe/VKDh" \
" foo@bar"
return (
"ssh-ed25519 "
"AAAAC3NzaC1lZDI1NTE5AAAAIGjHhIF/DlVCb2dRFMlKia7nij1Aq+zRDCaMIwe/VKDh"
" foo@bar"
)
@pytest.fixture()