Skip to content

Commit

Permalink
Fix issue with protected return, add tests, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedmcse committed Mar 21, 2024
1 parent ea2e2c1 commit df93a66
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "waifuvault"
version = "1.2.4"
version = "1.2.5"
authors = [
{ name="Walker Aldridge", email="[email protected]" },
]
Expand All @@ -24,3 +24,6 @@ classifiers = [
[project.urls]
Homepage = "https://github.com/waifuvault/waifuVault-python-api"
Issues = "https://github.com/waifuvault/waifuVault-python-api/issues"

[pytest]
pythonpath = "src"
2 changes: 1 addition & 1 deletion src/waifuvault/waifuvault.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ def __dict_to_obj(dict_obj: any):
return FileResponse(
dict_obj["token"],
dict_obj["url"],
dict_obj["protected"] == "true",
dict_obj["protected"],
dict_obj["retentionPeriod"])
84 changes: 84 additions & 0 deletions tests/test_waifuvault.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import io
import time

import waifuvault


# URL Upload Tests
def test_upload_url():
upload_file = waifuvault.FileUpload("https://twistedsisterscleaning.walker.moe/assets/sunflowers.png", expires="10m")
upload_res = waifuvault.upload_file(upload_file)
assert (upload_res.url.startswith('http')), "not a URL returned"
assert ('-' in upload_res.token), "not a token returned"
time.sleep(1)

upload_info = waifuvault.file_info(upload_res.token,True)
assert ('seconds' in upload_info.retentionPeriod), "not a human readable timestamp returned"
time.sleep(1)

update_info = waifuvault.file_update(upload_res.token,"dangerWaifu")
assert update_info.protected, "encryption returned false"
time.sleep(1)

file_down = waifuvault.get_file(upload_res,"dangerWaifu")
assert (isinstance(file_down, io.BytesIO)), "not a buffer returned"
assert (file_down.__sizeof__() > 0), "zero size buffer returned"
time.sleep(1)

del_file = waifuvault.delete_file(upload_res.token)
assert del_file, "delete returned false"
time.sleep(1)


# File Upload Tests
def test_upload_file():
upload_file = waifuvault.FileUpload("tests/testfile.png", expires="10m")
upload_res = waifuvault.upload_file(upload_file)
assert (upload_res.url.startswith('http')), "not a URL returned"
assert ('-' in upload_res.token), "not a token returned"
time.sleep(1)

upload_info = waifuvault.file_info(upload_res.token,True)
assert ('seconds' in upload_info.retentionPeriod), "not a human readable timestamp returned"
time.sleep(1)

update_info = waifuvault.file_update(upload_res.token,"dangerWaifu")
assert update_info.protected, "encryption returned false"
time.sleep(1)

file_down = waifuvault.get_file(upload_res, "dangerWaifu")
assert (isinstance(file_down, io.BytesIO)), "not a buffer returned"
assert (file_down.__sizeof__() > 0), "zero size buffer"
time.sleep(1)

del_file = waifuvault.delete_file(upload_res.token)
assert del_file, "delete file returned false"
time.sleep(1)


# Buffer Upload Tests
def test_upload_buffer():
with open("tests/testfile.png", "rb") as fh:
buf = io.BytesIO(fh.read())
upload_file = waifuvault.FileUpload(buf,"testfile_buf.png",expires="10m")
upload_res = waifuvault.upload_file(upload_file)
assert (upload_res.url.startswith('http')), "not a URL returned"
assert ('-' in upload_res.token), "not a token returned"
time.sleep(1)

upload_info = waifuvault.file_info(upload_res.token,True)
assert ('seconds' in upload_info.retentionPeriod), "not a human readable timestamp returned"
time.sleep(1)

update_info = waifuvault.file_update(upload_res.token,"dangerWaifu")
assert update_info.protected, "encryption returned false"
time.sleep(1)

file_down = waifuvault.get_file(upload_res, "dangerWaifu")
assert (isinstance(file_down, io.BytesIO)), "not a buffer returned"
assert (file_down.__sizeof__() > 0), "zero size buffer"
time.sleep(1)

del_file = waifuvault.delete_file(upload_res.token)
assert del_file
time.sleep(1)
Binary file added tests/testfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit df93a66

Please sign in to comment.