def create_app(self): """Create the app.""" from flask_iiif import IIIF from flask_restful import Api from flask_iiif.cache.simple import ImageSimpleCache app = Flask(__name__) app.config['DEBUG'] = True app.config['TESTING'] = True app.config['SERVER_NAME'] = "shield.worker.node.1" app.config['SITE_URL'] = "http://shield.worker.node.1" app.config['IIIF_CACHE_HANDLER'] = ImageSimpleCache() app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False app.logger.disabled = True api = Api(app=app) iiif = IIIF(app=app) iiif.uuid_to_image_opener_handler(self.create_image) def api_decorator_test(*args, **kwargs): if 'decorator' in kwargs.get('uuid'): abort(403) iiif.api_decorator_handler(api_decorator_test) iiif.init_restful(api) return app
def __init__(self, app, base_url): self.options = {'bind': '0.0.0.0:5000', 'workers': cpu_count() * 2 + 1} self.application = app app.config['IIIF_CACHE_HANDLER'] = ImageSimpleCache() app.config['BASE_URL'] = base_url ext.uuid_to_image_opener_handler(locate_image) super(HocrViewerApplication, self).__init__()
def setUp(self): """Run before the test.""" # Create a simple cache object from PIL import Image from flask_iiif.cache.simple import ImageSimpleCache # Initialize the cache object self.cache = ImageSimpleCache() # Create an image in memory tmp_file = BytesIO() # create a new image image = Image.new("RGBA", (1280, 1024), (255, 0, 0, 0)) image.save(tmp_file, 'png') # Store the image tmp_file.seek(0) self.image_file = tmp_file