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

@ -3,6 +3,7 @@ from pathlib import Path
from rich.console import Console
from rich.markdown import Markdown
from halig import utils
from halig.commands.base import BaseCommand
from halig.encryption import Encryptor
from halig.settings import Settings
@ -16,7 +17,7 @@ class ShowCommand(BaseCommand):
self.encryptor = Encryptor(self.settings)
self.console = Console()
if self.note_path.is_dir():
self.note_path /= f"{self.today.date()}.age"
self.note_path /= f"{utils.now().date()}.age"
if not self.note_path.exists():
err = f"File {self.note_path.name} does not exist"
@ -26,9 +27,11 @@ class ShowCommand(BaseCommand):
err = f"File {self.note_path.name} is not a valid AGE file"
raise ValueError(err)
def run(self):
def decrypt(self) -> str:
with self.note_path.open("rb") as f:
data = f.read()
contents = self.encryptor.decrypt(data)
md_contents = Markdown(contents.decode())
return self.encryptor.decrypt(data).decode()
def run(self): # pragma: no cover
md_contents = Markdown(self.decrypt())
self.console.print(md_contents)