Ejemplo n.º 1
0
    def test_scale_image(self):
        class MockImage(object):
            pass

        group_id = uuid.uuid4()
        snap_id = uuid.uuid4()
        ans.save_generic = Mock()
        the_picture_path = build_picture_path(picture_name='whatever',
                                              snap_id=snap_id,
                                              create_directory=False)
        ans.get_document_with_exception = Mock(
            return_value={
                'filename': 'whatever',
                'group_id': str(group_id),
                'snap_id': str(snap_id),
                'uri': the_picture_path
            })
        ans.get_group_document = Mock(
            return_value={
                '_id': str(group_id),
                'colorize_range_low': 1.1,
                'colorize_range_high': 2.2
            })
        the_mock_image = MockImage()
        Image.open = Mock(return_value=the_mock_image)
        MockImage.resize = Mock(return_value=the_mock_image)
        MockImage.save = Mock()
        ImageOps.colorize = Mock(return_value=the_mock_image)
        img_id_in = uuid.uuid4()
        img_id_out = uuid.uuid4()
        image_width = current_app.config['STILL_IMAGE_WIDTH']
        image_height = current_app.config['STILL_IMAGE_HEIGHT']
        img_filename_out = ans.build_picture_name(img_id_out)
        pic_path_out = ans.build_picture_path(picture_name=img_filename_out,
                                              snap_id=snap_id)
        test_img_dict_out = {
            '_id': str(img_id_out),
            'type': 'picture',
            'source': 'analysis',
            'source_image_id': str(img_id_in),
            'analysis_type': 'colorize_bicubic',
            'group_id': str(group_id),
            'snap_id': str(snap_id),
            'filename': img_filename_out,
            'uri': ANY,
            'created': ANY
        }

        ans.scale_image(img_id_in, img_id_out, 'whatever')

        ans.get_group_document.assert_called_once_with('whatever')
        ans.get_document_with_exception.assert_called_once_with(
            str(img_id_in), 'picture')
        Image.open.assert_called_once_with(
            ans.build_picture_path(picture_name='whatever', snap_id=snap_id))
        MockImage.resize.assert_called_once_with((image_width, image_height),
                                                 Image.BICUBIC)
        ImageOps.colorize.assert_called_once_with(the_mock_image, 1.1, 2.2)
        MockImage.save.assert_called_once_with(pic_path_out)
        ans.save_generic.assert_called_once_with(test_img_dict_out, 'picture')
Ejemplo n.º 2
0
    def test_scale_image(self):
        class MockImage(object):
            pass

        group_id = uuid.uuid4()
        snap_id = uuid.uuid4()
        ans.save_picture_document = Mock()
        the_picture_path = build_picture_path(picture_name='whatever', snap_id=snap_id, create_directory=False)
        ans.find_picture = Mock(return_value={'filename': 'whatever',
                                              'group_id': str(group_id),
                                              'snap_id': str(snap_id),
                                              'uri': the_picture_path
                                             }
                           )
        ans.get_group_document = Mock(return_value={
                                  '_id': str(group_id),
                                  'colorize_range_low': 1.1,
                                  'colorize_range_high': 2.2
                                  }
                                 )
        the_mock_image = MockImage()
        Image.open = Mock(return_value=the_mock_image)
        MockImage.resize = Mock(return_value=the_mock_image)
        MockImage.save = Mock()
        ImageOps.colorize = Mock(return_value=the_mock_image)
        img_id_in = uuid.uuid4()
        img_id_out = uuid.uuid4()
        image_width = current_app.config['STILL_IMAGE_WIDTH']
        image_height = current_app.config['STILL_IMAGE_HEIGHT']
        img_filename_out = ans.build_picture_name(img_id_out)
        pic_path_out = ans.build_picture_path(picture_name=img_filename_out, snap_id=snap_id)
        test_img_dict_out = {
            '_id': str(img_id_out),
            'type': 'picture',
            'source': 'analysis',
            'source_image_id': str(img_id_in),
            'analysis_type': 'colorize_bicubic',
            'group_id': str(group_id),
            'snap_id': str(snap_id),
            'filename': img_filename_out,
            'uri': ANY,
            'created': ANY
        }

        ans.scale_image(img_id_in, img_id_out, 'whatever')

        ans.get_group_document.assert_called_once_with('whatever')
        ans.find_picture.assert_called_once_with(str(img_id_in))
        Image.open.assert_called_once_with(ans.build_picture_path(picture_name='whatever', snap_id=snap_id))
        MockImage.resize.assert_called_once_with((image_width, image_height), Image.BICUBIC) 
        ImageOps.colorize.assert_called_once_with(the_mock_image, 1.1, 2.2)
        MockImage.save.assert_called_once_with(pic_path_out)
        ans.save_picture_document.assert_called_once_with(test_img_dict_out)
Ejemplo n.º 3
0
    def test_scale_image_accepts_scale_type_through_group_record(
            self, as_scale_image_subtask, as_build_picture_path,
            as_build_picture_name, as_get_document_with_exception,
            as_get_group_document):

        as_get_group_document.return_value = {
            '_id': 'd1',
            'scale_type': 'group_scale_type'
        }
        as_scale_image_subtask.side_effect = ThermalBaseError('wocka_wocka')
        Image.open = Mock(return_value='ali_baba')
        as_build_picture_path.return_value = 'steve_mcnair'
        as_build_picture_name.return_value = 'mongo_mcmichael'
        as_get_document_with_exception.return_value = {
            'filename': 'a1',
            'uri': 'b1',
            'snap_id': 'c1'
        }

        with pytest.raises(ThermalBaseError) as exception_info:
            return_value = ans.scale_image('a', 'b', 'c')

        as_scale_image_subtask.assert_called_once_with('group_scale_type', ANY)