class GetImageWithAutoWebP(BaseContext): def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.AUTO_WEBP = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) self.engine = PILEngine(ctx) return application def topic(self): response = self.get('/unsafe/image.jpg', headers={"Accept": 'image/webp,*/*;q=0.8'}) return (response.code, response.body) def should_be_webp(self, response): code, image_buffer = response expect(code).to_equal(200) image = self.engine.create_image(image_buffer) expect(image.format.lower()).to_equal('webp')
class GetImageWithAutoWebP(BaseContext): def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.AUTO_WEBP = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) self.engine = PILEngine(ctx) return application def topic(self): return self.get('/unsafe/image.jpg', headers={ "Accept": 'image/webp,*/*;q=0.8' }) def should_be_webp(self, response): expect(response.code).to_equal(200) expect(response.headers).to_include('Vary') expect(response.headers['Vary']).to_include('Accept') image = self.engine.create_image(response.body) expect(image.format.lower()).to_equal('webp')
def test_load_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'image.jpg'), 'r') as im: buffer = im.read() image = engine.create_image(buffer) expect(image.format).to_equal('JPEG')
def test_load_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "image.jpg"), "rb") as image_file: buffer = image_file.read() image = engine.create_image(buffer) expect(image.format).to_equal("JPEG")