Skip to content

Commit

Permalink
#28 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamarton committed Jan 20, 2023
1 parent b8a4a9b commit 5c05a4b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 0 additions & 3 deletions gwbackupy/storage/file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ def remove(self, link: FileLink, as_new_mutation: bool = True) -> bool:
)
try:
with self.get(link) as f:
if not f:
logging.error(f"{link.get_file_path()} not found or not readable")
return False
return self.put(dst, f)
except BaseException as e:
logging.exception(
Expand Down
26 changes: 25 additions & 1 deletion gwbackupy/tests/test_file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from os.path import exists

from gwbackupy.storage.file_storage import FileStorage
from gwbackupy.storage.storage_interface import LinkInterface


def test_find_empty():
Expand Down Expand Up @@ -136,8 +137,10 @@ def test_find_not_valid_files():
fs = FileStorage(root=temproot)
with open(os.path.join(temproot, ".gitignore"), "w") as f:
f.write("a")
with open(os.path.join(temproot, "without-extension"), "w") as f:
with open(os.path.join(temproot, "invalid"), "w") as f:
f.write("b")
with open(os.path.join(temproot, "without-extension."), "w") as f:
f.write("c")
links = fs.find()
assert len(links) == 0

Expand Down Expand Up @@ -221,3 +224,24 @@ def test_remove_fail():
fs.put(link, "data")
os.remove(link.get_file_path())
assert not fs.remove(link)


def test_link_props():
with tempfile.TemporaryDirectory(prefix="myapp-") as temproot:
fs = FileStorage(root=temproot)
link = fs.new_link("test", "ext")
assert not link.is_metadata()
assert not link.is_object()
link.set_properties({LinkInterface.property_metadata: True})
assert link.is_metadata()
assert not link.is_object()
link.set_properties({LinkInterface.property_object: True})
assert link.is_metadata()
assert link.is_object()
assert link.get_property(LinkInterface.property_object) is True
assert link.get_property("not-exists") is None
assert link.get_property("not-exists", 33) is 33

link.set_properties({LinkInterface.property_object: True}, replace=True)
assert not link.is_metadata()
assert link.is_object()

0 comments on commit 5c05a4b

Please sign in to comment.