Exemple #1
0
    def get_job_progress(self):
        '''
        Generates Segmentation Progress response protobuf message from the stored Segmentation Job.

        Parameters: none

        Returns:
            response - Model_pb2.Segmentationprogress - Protobuf Segmentation Progress object.
        '''
        response = Model_pb2.SegmentationProgress()
        if self.model_output != "":
            # 100 progress
            response.Progress = 100
            response.Errors = ""
            response.ErrorCode = 0
            return response
        # Mock response with 0 progress
        response.Progress = 0
        response.Errors = ""
        response.ErrorCode = 0
        return response
Exemple #2
0
    def test_post_job_retrieve_results_json(self):
        '''
        Test for endpoints:
            /api/v2/Model/{modelId}/segmentation
            /api/v2/Model/{modelId}/segmentation/{segmentationId}
            /api/v2/Model/{modelId}/segmentation/{segmentationId}/result

        Since database objects are not maintained between test cases, 3 end-points are tested
        here.
        Retrieve JSON results
        '''

        #----------------------------------------------------------------------
        # Testing POST /api/v2/Model/{modelId}/segmentation
        #----------------------------------------------------------------------
        # Post job to temporary server
        model_id = PostSegmentationTestCase.model_version.model_version_id.replace(" ", "%20")
        post_response = self.client.post('/api/v2/Model/{}/segmentation'.format(model_id), \
            self.seg_job, \
            content_type='application/x-protobuf', \
            **{'HTTP_ACCEPT':'application/x-protobuf'})
        self.assertEqual(post_response.status_code, 200, \
            msg='/api/v2/Model/{}/segmentation endpoint did not return 200 status code.'.format(\
                model_id))
        # Append orphaned segmentation job file path to path list for teardown.
        db_seg_path = SegmentationJob.objects.all()[0].model_input.path
        self.path_list.append(db_seg_path)
        # Parse protobuf message output
        seg_task = Model_pb2.SegmentationTask()
        seg_task.ParseFromString(post_response.content)
        seg_id = seg_task.SegmentationID

        #----------------------------------------------------------------------
        # Testing /api/v2/Model/{modelId}/segmentation/{segmentationId}
        #----------------------------------------------------------------------
        # Get progress from temporary server.  Since the test client is running with eager Celery
        # scheduling, it should always return 100% progress.
        get_response = self.client.get('/api/v2/Model/{}/segmentation/{}'.format( \
            model_id, seg_id), \
            **{'HTTP_ACCEPT':'application/x-protobuf'})
        self.assertEqual(get_response.status_code, 200, \
            msg='/api/v2/Model/{}/segmentation/{} endpoint did not return 200 status code.'.format(\
                model_id, seg_id))
        # Parse protobuf message output
        progress = Model_pb2.SegmentationProgress()
        progress.ParseFromString(get_response.content)
        self.assertEqual(progress.Progress, 100, \
            msg='/api/v2/Model/{}/segmentation/{} endpoint did not return 100% progress.'.format(\
                model_id, seg_id))
        # Append orphaned segmentation job file path to path list for teardown.
        db_results_path = SegmentationJob.objects.all()[0].model_output.path
        self.path_list.append(db_results_path)

        #----------------------------------------------------------------------
        # Testing /api/v2/Model/{modelId}/segmentation/{segmentationId}/result
        #----------------------------------------------------------------------
        seg_response = self.client.get('/api/v2/Model/{}/segmentation/{}/result'.format( \
            model_id, seg_id), \
            **{'HTTP_ACCEPT':'application/json'})
        self.assertEqual(seg_response.status_code, 200, \
            msg='/api/v2/Model/{}/segmentation/{}/result endpoint did not return 200 status code.'\
            .format(model_id, seg_id))
        seg_result = seg_response.json()
        self.assertEqual(seg_result['ModelID'], model_id.replace("%20"," "), \
            msg='/api/v2/Model/{}/segmentation/{}/result endpoint did not fetch correct result.'\
            .format(model_id, seg_id))