tests: test commands
This commit is contained in:
parent
d3ad87211e
commit
570c29d9f1
16 changed files with 235 additions and 52 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue