Added download assets API methods, tests

pull/43/head
Piero Toffanin 2016-11-05 16:23:54 -04:00
rodzic a91e2bd108
commit ea78c03b70
4 zmienionych plików z 40 dodań i 1 usunięć

Wyświetl plik

@ -40,6 +40,13 @@ class ApiClient:
def task_restart(self, uuid):
return requests.post(self.url('/task/restart'), data={'uuid': uuid}).json()
def task_download(self, uuid, asset):
res = requests.get(self.url('/task/{}/download/{}').format(uuid, asset))
if "Content-Type" in res.headers and "application/json" in res.headers['Content-Type']:
return res.json()
else:
return res.content
def new_task(self, images, name=None, options=[]):
"""
Starts processing of a new task

@ -1 +1 @@
Subproject commit 038940860d043439b184c4fbd990f8a71b60c324
Subproject commit c056dee4857066e4c3b65a9a3cbf1b5aa1282ac9

Wyświetl plik

@ -115,6 +115,17 @@ class ProcessingNode(models.Model):
api_client = self.api_client()
return self.handle_generic_post_response(api_client.task_remove(uuid))
def download_task_asset(self, uuid, asset):
"""
Downloads a task asset
"""
api_client = self.api_client()
res = api_client.task_download(uuid, asset)
if isinstance(res, dict) and 'error' in res:
raise ProcessingException(res['error'])
else:
return res
def restart_task(self, uuid):
"""
Restarts a task that was previously canceled or that had failed to process

Wyświetl plik

@ -6,6 +6,8 @@ from .models import ProcessingNode
from .api_client import ApiClient
from requests.exceptions import ConnectionError
from .exceptions import ProcessingException
import status_codes
current_dir = path.dirname(path.realpath(__file__))
@ -91,6 +93,25 @@ class TestClientApi(TestCase):
self.assertTrue(isinstance(task_info['dateCreated'], (int, long)))
self.assertTrue(isinstance(task_info['uuid'], (str, unicode)))
# Can download assets?
# Here we are waiting for the task to be completed
retries = 0
while True:
try:
task_info = api.task_info(uuid)
if task_info['status']['code'] == status_codes.COMPLETED:
asset = api.task_download(uuid, "all.zip")
self.assertTrue(isinstance(asset, (str, unicode))) # Binary content, really
break
except ProcessingException:
pass
time.sleep(0.5)
retries += 1
if retries >= 10:
self.assertTrue(False, "Could not download assets")
break
# task_output
self.assertTrue(isinstance(api.task_output(uuid, 0), list))
self.assertTrue(isinstance(online_node.get_task_console_output(uuid, 0), (str, unicode)))