コード例 #1
0
def test_input_parameters_for_valid_image_ids(args_dict):
    # TODO consider replacing this with an get_document_with_exception, and modifying GDWE to optionally accept an error string
    if not item_exists(args_dict['img1_id'], 'picture'):  # TODO add testing for no picture id and invalid picture id
        err_msg = 'Source image 1 not found.  A valid id for a source image must be supplied to this endpoint as a get '\
                  'parameter named img1_id in order to call this endpoint'
        raise NotFoundError(err_msg)

    if not item_exists(args_dict['img2_id'], 'picture'):  # TODO add testing for no picture id and invalid picture id
        err_msg = 'Source image 2 not found.  A valid id for a source image must be supplied to this endpoint as a get '\
                  'parameter named img2_id in order to call this endpoint'
        raise NotFoundError(err_msg)
コード例 #2
0
ファイル: services.py プロジェクト: dcaulton/thermal
def update_generic(document_in, document_type):
    '''
    requires document to have at least _id and type
    '''
    if '_id' in document_in:
        the_id = cast_uuid_to_string(document_in['_id'])
        if not item_exists(the_id, 'any'):
            raise DocumentConfigurationError('trying to update {0} when no document exists for that id'.format(the_id))
        if not item_exists(the_id, document_type):
            raise DocumentConfigurationError('trying to alter document type for id {0} during update'.format(the_id))
        save_document(document_in)
    else:
         raise DocumentConfigurationError('trying to update a document with no id')
コード例 #3
0
    def test_item_exists_returns_false_when_item_exists_but_doesnt_match_type(
            self):
        item_id = uuid.uuid4()
        doc_1 = {'_id': str(item_id), 'type': 'picture'}
        tu.save_document(doc_1)

        assert not tu.item_exists(item_id, 'exterminator')
コード例 #4
0
ファイル: test_utils.py プロジェクト: dcaulton/thermal
    def test_save_document_works_when_document_is_complete(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'wookie'}
        tu.save_document(dict_in)

        assert tu.item_exists(doc_id, 'any')
コード例 #5
0
def merge_images(img1_primary_id_in, img1_alternate_id_in, img2_id_in,
                 img_id_out, group_id, **kwargs):
    # TODO deal more elegantly with the fact that different merge methods require different parameters
    # the assumption is that the merged picture will be saved in the directory with the snap of image 1
    # it also assumes that both images have not yet been deleted with clean_up_files
    merge_type = get_merge_type(group_id, **kwargs)
    merge_method = get_merge_method(merge_type)

    img1_id_in = img1_primary_id_in
    if item_exists(img1_alternate_id_in, 'picture'):
        img1_id_in = img1_alternate_id_in

    paths_dict = get_image_paths_and_snap_id(img1_id_in, img2_id_in,
                                             img_id_out)

    do_image_merge(paths_dict, merge_method)

    img_dict_out = {
        '_id': str(img_id_out),
        'type': 'picture',
        'source': 'merge',
        'source_image_id_1': str(img1_id_in),
        'source_image_id_2': str(img2_id_in),
        'merge_type': merge_type,
        'group_id': group_id,
        'snap_id': paths_dict['snap_id'],
        'filename': paths_dict['img_out_filename'],
        'uri': paths_dict['img_out_path'],
        'created': str(datetime.datetime.now())
    }
    save_generic(img_dict_out, 'picture')
コード例 #6
0
 def build_three_pictures(self, snap_id):
     pic_ids = []
     for i in range(1, 3):
         pic_id = uuid.uuid4()
         filename = build_picture_name(pic_id)
         picture_path = build_picture_path(picture_name=filename, snap_id=snap_id)
         the_doc = {
             '_id': str(pic_id),
             'snap_id': str(snap_id),
             'uri': picture_path,
             'filename': filename,
             'source': 'whatever',
             'type': 'picture'
         }
         save_generic(the_doc, 'picture')
         pic_ids.append(pic_id)
         # touch the picture file in the temp directory
         with open(picture_path, 'a'):
             os.utime(picture_path, None)
         if not item_exists(snap_id, 'snap'):
             snap_doc = {'_id': snap_id,
                         'type': 'snap',
                         'clean_up_files': True}
             save_generic(snap_doc, 'snap')
     return pic_ids
コード例 #7
0
ファイル: services.py プロジェクト: dcaulton/thermal
def merge_images(img1_primary_id_in, img1_alternate_id_in, img2_id_in, img_id_out, group_id, **kwargs):
    # TODO deal more elegantly with the fact that different merge methods require different parameters
    # the assumption is that the merged picture will be saved in the directory with the snap of image 1
    # it also assumes that both images have not yet been deleted with clean_up_files
        merge_type = get_merge_type(group_id, **kwargs)
        merge_method = get_merge_method(merge_type)

        img1_id_in = img1_primary_id_in
        if item_exists(img1_alternate_id_in, 'picture'):
            img1_id_in = img1_alternate_id_in

        paths_dict = get_image_paths_and_snap_id(img1_id_in, img2_id_in, img_id_out)

        do_image_merge(paths_dict, merge_method)

        img_dict_out = {
            '_id': str(img_id_out),
            'type': 'picture',
            'source': 'merge',
            'source_image_id_1': str(img1_id_in),
            'source_image_id_2': str(img2_id_in),
            'merge_type': merge_type,
            'group_id': group_id,
            'snap_id': paths_dict['snap_id'],
            'filename': paths_dict['img_out_filename'],
            'uri': paths_dict['img_out_path'],
            'created': str(datetime.datetime.now())
        }
        save_generic(img_dict_out, 'picture')
コード例 #8
0
ファイル: test_utils.py プロジェクト: dcaulton/thermal
    def test_item_exists_returns_true_when_item_exists_type_any(self):
        item_id = uuid.uuid4()
        doc_1 = {
            '_id': str(item_id),
            'type': 'picture'
        }
        tu.save_document(doc_1)

        assert tu.item_exists(item_id, 'any')
コード例 #9
0
ファイル: test_utils.py プロジェクト: dcaulton/thermal
    def test_item_exists_returns_false_when_item_exists_but_doesnt_match_type(self):
        item_id = uuid.uuid4()
        doc_1 = {
            '_id': str(item_id),
            'type': 'picture'
        }
        tu.save_document(doc_1)

        assert not tu.item_exists(item_id, 'exterminator')
コード例 #10
0
ファイル: views.py プロジェクト: dcaulton/thermal
def call_scale_image(image_id=None):
    '''
    Scales an image according to the current group settings
    '''
    result_id = uuid.uuid4()

    if not item_exists(image_id, 'picture'):  # TODO add testing for no picture id and invalid picture id
        err_msg = 'Image not found.  A valid image_id must be supplied as the last segment of the url in order to call'\
                  ' this endpoint'
        return Response(json.dumps(err_msg), status=404, mimetype='application/json')
    else:
        ans.scale_image_task.delay(img_id_in=image_id,
                                   img_id_out=result_id,
                                   group_id='current')
        resp_json = {
            'scale_image_output_image_id': str(result_id)
        }
        return Response(json.dumps(resp_json), status=202, mimetype='application/json')
コード例 #11
0
ファイル: views.py プロジェクト: dcaulton/thermal
def create_distortion_pair():
    try:
        if 'distortion_set_id' not in request.json:
            distortion_set_id = cast_uuid_to_string(uuid.uuid4())
            request.json['distortion_set_id'] = distortion_set_id
        else:
            distortion_set_id = request.json['distortion_set_id']

        if not item_exists(distortion_set_id, 'distortion_set'):
            distortion_set_dict = {'_id': distortion_set_id, 'type': 'distortion_set'}
            save_generic(distortion_set_dict, 'distortion_set')

        # TODO add a lot more tests to the request json, we need start_x, y, end_x, y and they need to be ints, range tests, etc
        #  ^^^^^ have this be a validation function which is optionally passed to save_generic
        return_value = generic_save_view(document_type='distortion_pair')
        return return_value
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
コード例 #12
0
ファイル: views.py プロジェクト: ibivibiv/thermal
def call_scale_image(image_id=None):
    '''
    Scales an image according to the current group settings
    '''
    result_id = uuid.uuid4()

    if not item_exists(
            image_id, 'picture'
    ):  # TODO add testing for no picture id and invalid picture id
        err_msg = 'Image not found.  A valid image_id must be supplied as the last segment of the url in order to call'\
                  ' this endpoint'
        return Response(json.dumps(err_msg),
                        status=404,
                        mimetype='application/json')
    else:
        ans.scale_image_task.delay(img_id_in=image_id,
                                   img_id_out=result_id,
                                   group_id='current')
        resp_json = {'scale_image_output_image_id': str(result_id)}
        return Response(json.dumps(resp_json),
                        status=202,
                        mimetype='application/json')
コード例 #13
0
def create_distortion_pair():
    try:
        if 'distortion_set_id' not in request.json:
            distortion_set_id = cast_uuid_to_string(uuid.uuid4())
            request.json['distortion_set_id'] = distortion_set_id
        else:
            distortion_set_id = request.json['distortion_set_id']

        if not item_exists(distortion_set_id, 'distortion_set'):
            distortion_set_dict = {
                '_id': distortion_set_id,
                'type': 'distortion_set'
            }
            save_generic(distortion_set_dict, 'distortion_set')

        # TODO add a lot more tests to the request json, we need start_x, y, end_x, y and they need to be ints, range tests, etc
        #  ^^^^^ have this be a validation function which is optionally passed to save_generic
        return_value = generic_save_view(document_type='distortion_pair')
        return return_value
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
コード例 #14
0
ファイル: test_utils.py プロジェクト: dcaulton/thermal
    def test_item_exists_returns_false_when_item_doesnt_exist_type_any(self):
        item_id = uuid.uuid4()

        assert not tu.item_exists(item_id, 'any')
コード例 #15
0
    def test_item_exists_returns_true_when_item_exists_type_any(self):
        item_id = uuid.uuid4()
        doc_1 = {'_id': str(item_id), 'type': 'picture'}
        tu.save_document(doc_1)

        assert tu.item_exists(item_id, 'any')
コード例 #16
0
    def test_item_exists_returns_false_when_item_doesnt_exist_type_any(self):
        item_id = uuid.uuid4()

        assert not tu.item_exists(item_id, 'any')
コード例 #17
0
ファイル: services.py プロジェクト: dcaulton/thermal
def get_generic(item_id, document_type):
    if not item_exists(item_id, document_type):
        raise NotFoundError("{0} not found for id {1}".format(document_type, item_id))
    item_dict = get_document(item_id)
    return item_dict
コード例 #18
0
    def test_save_document_works_when_document_is_complete(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'wookie'}
        tu.save_document(dict_in)

        assert tu.item_exists(doc_id, 'any')