Skip to content

Commit

Permalink
Add move method to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
jrrodri committed Nov 21, 2018
1 parent e2fb682 commit 871ee9f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
7 changes: 0 additions & 7 deletions .pytest_cache/v/cache/lastfailed

This file was deleted.

15 changes: 0 additions & 15 deletions .pytest_cache/v/cache/nodeids

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Abraia
Copyright (c) 2017 Abraia Software

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 7 additions & 0 deletions abraia/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def download(self, path):
raise APIError('GET {} {}'.format(url, resp.status_code))
return resp

def move(self, old_path, new_path):
url = '{}/files/{}'.format(config.API_URL, new_path)
resp = requests.post(url, json={'store': old_path}, auth=self.auth)
if resp.status_code != 201:
raise APIError('POST {} {}'.format(url, resp.status_code))
return resp.json()

def remove(self, path):
url = '{}/files/{}'.format(config.API_URL, path)
resp = requests.delete(url, auth=self.auth)
Expand Down
2 changes: 1 addition & 1 deletion scripts/abraia
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def process_remove(path):

def parse_input():
parser = argparse.ArgumentParser(description='Abraia image optimization tool')
parser.add_argument('-V', '--version', action='version', version='0.3.1')
parser.add_argument('-V', '--version', action='version', version='0.3.3')
subparser = parser.add_subparsers(dest='command')
subparser.add_parser('configure', help='configure the access keys')
parser_optimize = subparser.add_parser('optimize', help='optimize an image or a directory of images')
Expand Down
9 changes: 8 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ def test_download_file():
assert resp.status_code == 200


def test_move_file():
"""Test an API call to move a stored file"""
client.move(userid + '/' + filename, userid + '/test/' + filename)
resp = client.move(userid + '/test/' + filename, userid + '/' + filename)
assert isinstance(resp, dict)
assert resp['file']['source'] == userid + '/' + filename


def test_remote_file():
"""Test an API call to upload a remote file"""
url = 'https://abraia.me/images/random.jpg'
resp = client.remote(url, userid+'/')
assert isinstance(resp, dict)
# assert source.path == 'random.jpg'


def test_transform():
Expand Down

0 comments on commit 871ee9f

Please sign in to comment.