def test_get_dataset_download_action(self, async_get_object_mock): # bogus model url = self._get_url(id=101010, action='dataset_download') resp = self.client.get(url, headers=HTTP_HEADERS) self.assertEquals(resp.status_code, httplib.NOT_FOUND) # existing model dataset = DataSet.query.filter_by( name=DataSetData.dataset_01.name).first() from api.async_tasks.models import AsyncTask task = AsyncTask() task.args = [self.obj.id, dataset.id] task.object_id = self.obj.id async_get_object_mock.return_value = [task] self.obj.status = Model.STATUS_TRAINING url = self._get_url(id=self.obj.id, action='dataset_download') resp = self.client.get(url, headers=HTTP_HEADERS) self.assertEquals(resp.status_code, httplib.OK) resp_obj = json.loads(resp.data) self.assertEqual(async_get_object_mock.call_args_list[0][0][1], TRANSFORM_DATASET_TASK) self.assertTrue('downloads' in resp_obj) self.assertEqual(resp_obj['downloads'][0]['dataset']['id'], dataset.id)
def task_prerun_handler(sender=None, task_id=None, task=None, args=None, kwargs=None, **kwds): # pragma: no cover obj = get_object_from_task(task.name, args, kwargs) if obj: task_obj = AsyncTask.create_by_task_and_object( task.name, task_id, args, kwargs, obj) task_obj.save()
def test_get_transformers_download_action(self, async_get_object_mock): # bogus model url = self._get_url(id=101010, action='transformers_download') resp = self.client.get(url, headers=HTTP_HEADERS) self.assertEquals(resp.status_code, httplib.NOT_FOUND) # existing model segment = Segment.query.filter_by( name=SegmentData.segment_01.name).first() from api.async_tasks.models import AsyncTask task = AsyncTask() task.args = [self.obj.id, segment.id] task.object_id = segment.id async_get_object_mock.return_value = [task] url = self._get_url(id=self.obj.id, action='transformers_download') resp = self.client.get(url, headers=HTTP_HEADERS) self.assertEquals(resp.status_code, httplib.OK) resp_obj = json.loads(resp.data) self.assertEqual(async_get_object_mock.call_args_list[0][0][1], TRANSFORMERS_UPLOAD_TASK) self.assertTrue('downloads' in resp_obj) self.assertEqual(resp_obj['downloads'][0]['segment']['id'], segment.id)
def _get_dataset_download_action(self, **kwargs): model = self._get_details_query(None, **kwargs) if model is None: raise NotFound('Model not found') from api.tasks import TRANSFORM_DATASET_TASK tasks = AsyncTask.get_current_by_object(model, TRANSFORM_DATASET_TASK) downloads = [] for task in tasks: downloads.append({ 'dataset': DataSet.query.get(task.args[1]), 'task': task }) return self._render({ self.OBJECT_NAME: model.id, 'downloads': downloads })
def _get_transformers_download_action(self, **kwargs): model = self._get_details_query(None, **kwargs) if model is None: raise NotFound('Model not found') from api.tasks import TRANSFORMERS_UPLOAD_TASK tasks = [] for segment in model.segments: tasks.extend( AsyncTask.get_current_by_object(segment, TRANSFORMERS_UPLOAD_TASK)) downloads = [] for task in sorted(tasks, key=lambda x: x.created_on, reverse=True): downloads.append({ 'segment': Segment.query.get(task.args[1]), 'task': task }) return self._render({ self.OBJECT_NAME: model.id, 'downloads': downloads })
def tunnels(self): from api.async_tasks.models import AsyncTask return AsyncTask.get_current_by_object( self, 'api.instances.tasks.run_ssh_tunnel', )
def pig_fields(self): from api.async_tasks.models import AsyncTask return AsyncTask.get_current_by_object( self, 'api.import_handlers.tasks.load_pig_fields', )
def exports(self): from api.async_tasks.models import AsyncTask return AsyncTask.get_current_by_object( self, 'api.model_tests.tasks.get_csv_results', )
def confusion_matrix_calculations(self): from api.async_tasks.models import AsyncTask return AsyncTask.get_current_by_object( self, 'api.model_tests.tasks.calculate_confusion_matrix', statuses=AsyncTask.STATUSES)
def db_exports(self): from api.async_tasks.models import AsyncTask return AsyncTask.get_current_by_object( self, 'api.model_tests.tasks.export_results_to_db', )