def call_distort_image(image_id=None): ''' Distorts an image according to the distortion pairs in the specified distortion set ''' try: new_image_id = uuid.uuid4() picture_dict = get_document_with_exception(image_id, document_type='picture') args_dict = gather_and_enforce_request_args([{ 'name': 'distortion_set_id', 'required': True }]) distortion_set_id = args_dict['distortion_set_id'] distortion_set_dict = get_document_with_exception( distortion_set_id, document_type='distortion_set') # TODO call this async via distort_image_shepards_task.delay as soon as it's working ans.distort_image_shepards(image_id_in=image_id, image_id_out=new_image_id, distortion_set_id=distortion_set_id) resp_json = {'distorted_image_id': str(new_image_id)} return Response(json.dumps(resp_json), status=202, mimetype='application/json') except Exception as e: return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
def test_distort_image_shepards_calls_expected_methods( self, as_save_generic, os_system, as_build_command_string, as_build_picture_path, as_build_picture_name, as_get_document_with_exception): as_get_document_with_exception.return_value = { 'group_id': 'some_group_id', 'uri': 'the_uri', 'snap_id': 'some_snap_id' } as_build_picture_name.return_value = 'some_picture_name' as_build_picture_path.return_value = 'some_picture_path' as_build_command_string.return_value = 'the_command_string' ans.distort_image_shepards(image_id_in='img_id_in', image_id_out='img_id_out', distortion_set_id='dist_set_id') as_get_document_with_exception.assert_called_once_with( 'img_id_in', 'picture') as_build_picture_name.assert_called_once_with('img_id_out') as_build_picture_path.assert_called_once_with( picture_name='some_picture_name', snap_id='some_snap_id') as_build_command_string.assert_called_once_with( 'dist_set_id', 'the_uri', 'some_picture_path') os_system.assert_called_once_with('the_command_string') as_save_generic.assert_called_once_with( { '_id': 'img_id_out', 'type': 'picture', 'source': 'analysis', 'source_image_id': 'img_id_in', 'analysis_type': 'distort', 'group_id': 'some_group_id', 'snap_id': 'some_snap_id', 'filename': 'some_picture_name', 'uri': 'some_picture_path', 'created': ANY }, 'picture')
def call_distort_image(image_id=None): ''' Distorts an image according to the distortion pairs in the specified distortion set ''' try: new_image_id = uuid.uuid4() picture_dict = get_document_with_exception(image_id, document_type='picture') args_dict = gather_and_enforce_request_args([{'name': 'distortion_set_id', 'required': True}]) distortion_set_id = args_dict['distortion_set_id'] distortion_set_dict = get_document_with_exception(distortion_set_id, document_type='distortion_set') # TODO call this async via distort_image_shepards_task.delay as soon as it's working ans.distort_image_shepards(image_id_in=image_id, image_id_out=new_image_id, distortion_set_id=distortion_set_id) resp_json = { 'distorted_image_id': str(new_image_id) } return Response(json.dumps(resp_json), status=202, mimetype='application/json') except Exception as e: return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')