def test_write(self): h = self.handler expected_location = os.path.join(self.root, 'a/9/4/a', 'test', '1x1.png') image = Canvas.from_bytes(ONExONE_PNG) h.write('test', image) try: self.assertTrue(os.path.exists(expected_location)) self.assertEqual(open(expected_location, 'rb').read(), ONExONE_PNG) finally: cleanup = os.path.join(self.root, 'a') shutil.rmtree(cleanup)
def handle_image(self, req): request_format = req.get_image_format() request_id = req.get_image_id() request_size = req.get_image_size() request_filename = get_filename(request_id, request_size, request_format) if not self.filehandler.exists(request_id): raise FileNotFoundError('File "%s" does not exist on filesystem' % request_filename) elif self.filehandler.exists(request_id, request_size, request_format): image_data = self.filehandler.read(request_id, request_size, request_format) else: image_data = self.filehandler.read_best(request_id, request_size) image = Canvas.from_bytes(image_data) image.smart_resize(request_size) image_data = image.to_bytes(format=request_format) return SuccessResponse(image_data, request_format)