Able to connect to perform operations on local files

This commit is contained in:
Stanislas Jouffroy 2024-09-23 23:46:15 +02:00
parent a5c99c2d06
commit 3eb045cd4a
3 changed files with 51 additions and 0 deletions

View file

View file

@ -0,0 +1,24 @@
from pathlib import Path
from losoup.models import Software, Asset
class LocalFile:
def __init__(self, software: Software):
self.software = software
def get_files_in_folder(self) -> list[str]:
return [file.name for file in Path(self.software.folder).glob("*")]
def is_file_present(self):
files = self.get_files_in_folder()
return self.software.filename in files
def is_file_absent(self):
return not self.is_file_present()
def write_file(self, file: Asset) -> None:
self.software.absolute_path.write_bytes(file.content)
def delete_file(self):
self.software.absolute_path.unlink()

View file

@ -0,0 +1,27 @@
from losoup.file_operations.local_files import LocalFile
from losoup.models import Asset
import typer
def test_local_files_init(keepassxc):
local_file = LocalFile(keepassxc)
assert local_file.software == keepassxc
def test_get_local_files(local_file):
assert "KeePassXC-2.7.9-x86_64.AppImage" in local_file.get_files_in_folder()
def test_is_file_present(local_file):
assert local_file.is_file_present()
def test_is_file_absent(local_file_not_present):
assert local_file_not_present.is_file_absent()
def test_write_file(keepassxc_digest_file: LocalFile, asset_to_write: Asset):
assert keepassxc_digest_file.is_file_absent()
keepassxc_digest_file.write_file(asset_to_write)
assert keepassxc_digest_file.is_file_present()
keepassxc_digest_file.delete_file()