Skip to content

Commit

Permalink
Add check_file method
Browse files Browse the repository at this point in the history
  • Loading branch information
jrrodri committed Mar 10, 2024
1 parent 70cccd5 commit 36f3f69
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions abraia/abraia.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def upload_file(self, src, path=''):
return file_path({'name': name, 'source': f"{self.userid}/{path}"}, self.userid)
return file_path(resp['file'], self.userid)

def check_file(self, path):
url = f"{API_URL}/files/{self.userid}/{path}"
resp = requests.head(url, auth=self.auth)
if resp.status_code == 404:
return False
if resp.status_code in [307, 400, 403]:
return True
raise APIError(resp.text, resp.status_code)

def move_file(self, old_path, new_path):
json = {'store': f"{self.userid}/{old_path}"}
url = f"{API_URL}/files/{self.userid}/{new_path}"
Expand Down
Binary file modified images/screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ click>=8.0.3
numpy>=1.21.0
Pillow>=8.0.0
tifffile>=2020.9.4
python-dotenv>=0.19.2
python-dotenv>=0.21.1
requests>=2.27.1
tqdm>=4.62.3
7 changes: 7 additions & 0 deletions tests/test_abraia.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def test_upload_file():
assert path == 'tiger.jpg'


def test_check_file():
path = 'lion.jpg'
assert abraia.check_file(path)
path = '_lion.jpg'
assert not abraia.check_file(path)


def test_download_file():
stream = abraia.download_file('tiger.jpg')
assert isinstance(stream, BytesIO)
Expand Down

0 comments on commit 36f3f69

Please sign in to comment.