コード例 #1
0
ファイル: test_gif.py プロジェクト: Bladrak/thumbor
    def test_is_multiple_should_returns_false_if_gif_has_many_frames(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'animated-one-frame.gif'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        expect(engine.is_multiple()).to_be_false()
コード例 #2
0
    def test_is_multiple_should_returns_false_if_gif_has_many_frames(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'animated-one-frame.gif'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        expect(engine.is_multiple()).to_be_false()
コード例 #3
0
ファイル: test_gif.py プロジェクト: thumbor/thumbor
    def test_is_multiple_should_returns_true_if_gif_has_many_frames(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file:
            buffer = image_file.read()

        engine.load(buffer, ".gif")
        expect(engine.is_multiple()).to_be_true()
コード例 #4
0
ファイル: test_gif.py プロジェクト: thumbor/thumbor
    def test_is_multiple_should_returns_true_if_gif_has_many_frames(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, "animated.gif"), "r") as im:
            buffer = im.read()

        engine.load(buffer, ".gif")
        expect(engine.is_multiple()).to_be_true()
コード例 #5
0
    def validate(self, body):
        conf = self.context.config
        mime = BaseEngine.get_mimetype(body)

        if mime == '.gif' and self.context.config.USE_GIFSICLE_ENGINE:
            engine = GifEngine(self.context)
        else:
            engine = self.context.modules.engine

        # Check if image is valid
        try:
            engine.load(body, None)
        except IOError:
            self._error(415, 'Unsupported Media Type')
            return False

        # Check weight constraints
        if (conf.UPLOAD_MAX_SIZE != 0 and len(self.request.body) > conf.UPLOAD_MAX_SIZE):
            self._error(
                412,
                'Image exceed max weight (Expected : %s, Actual : %s)' % (conf.UPLOAD_MAX_SIZE, len(self.request.body)))
            return False

        # Check size constraints
        size = engine.size
        if (conf.MIN_WIDTH > size[0] or conf.MIN_HEIGHT > size[1]):
            self._error(
                412,
                'Image is too small (Expected: %s/%s , Actual : %s/%s) % (conf.MIN_WIDTH, conf.MIN_HEIGHT, size[0], size[1])')
            return False
        return True
コード例 #6
0
    def test_errors_on_gifsicle_should_not_raises_errors_when_output(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'SmallFullColourGIF.gif'), 'rb') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        result = engine.run_gifsicle('--some-invalid-opt')
        expect(result).Not.to_be_null()
コード例 #7
0
ファイル: test_gif.py プロジェクト: caeugusmao/thumbor
    def test_errors_on_gifsicle_should_not_raises_errors_when_output(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'SmallFullColourGIF.gif'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        result = engine.run_gifsicle('--some-invalid-opt')
        expect(result).Not.to_be_null()
コード例 #8
0
ファイル: test_gif.py プロジェクト: thumbor/thumbor
    def test_errors_on_gifsicle_should_not_raises_errors_when_output(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, "SmallFullColourGIF.gif"),
                  "rb") as image_file:
            buffer = image_file.read()

        engine.load(buffer, ".gif")
        result = engine.run_gifsicle("--some-invalid-opt")
        expect(result).Not.to_be_null()
コード例 #9
0
ファイル: test_gif.py プロジェクト: thumbor/thumbor
    def test_errors_on_gifsicle_should_raises_errors(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, "animated.gif"), "r") as im:
            buffer = im.read()

        engine.load(buffer, ".gif")
        with expect.error_to_happen(
            GifSicleError,
            message="gifsicle command returned errorlevel 1 for command"
            ' "{0} --some-invalid-opt /foo/'
            'bar.gif" (image maybe corrupted?)'.format(self.server.gifsicle_path),
        ):
            engine.run_gifsicle("--some-invalid-opt")
コード例 #10
0
    def test_convert_to_grayscale_should_update_image(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'animated.gif'), 'rb') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        buffer = engine.read()
        engine.convert_to_grayscale()

        expect(buffer).not_to_equal(engine.read())
コード例 #11
0
ファイル: test_gif.py プロジェクト: thumbor/thumbor
    def test_convert_to_grayscale_should_update_image(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file:
            buffer = image_file.read()

        engine.load(buffer, ".gif")
        buffer = engine.read()
        engine.convert_to_grayscale()

        expect(buffer).not_to_equal(engine.read())
コード例 #12
0
ファイル: gif_engine_vows.py プロジェクト: y2khjh/thumbor
        def topic(self):
            config = Config()
            server = ServerParameters(
                8889, 'localhost', 'thumbor.conf', None, 'info', None
            )

            context = Context(server, config, Importer(config))
            context.server.gifsicle_path = which('gifsicle')

            context.request = RequestParameters()

            with open("%s/animated_image.gif" % FIXTURES_FOLDER, "rb") as f:
                buffer = f.read()

            engine = GifEngine(context=context)
            engine.load(buffer, '.gif')

            return engine.read()
コード例 #13
0
ファイル: test_gif.py プロジェクト: caeugusmao/thumbor
    def test_convert_to_grayscale_should_update_image(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        buffer = engine.read()
        engine.convert_to_grayscale()

        expect(buffer).not_to_equal(engine.read())
コード例 #14
0
    def test_errors_on_gifsicle_should_raises_errors(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, '.gif')
        with expect.error_to_happen(
                GifSicleError,
                message='gifsicle command returned errorlevel 1 for command'
                ' "{0} --some-invalid-opt /foo/'
                'bar.gif" (image maybe corrupted?)'.format(
                    self.server.gifsicle_path)):
            engine.run_gifsicle('--some-invalid-opt')
コード例 #15
0
ファイル: test_gif.py プロジェクト: thumbor/thumbor
 def test_load_image(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file:
         buffer = image_file.read()
     image = engine.create_image(buffer)
     expect(image.format).to_equal("GIF")
コード例 #16
0
 def test_load_image(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im:
         buffer = im.read()
     image = engine.create_image(buffer)
     expect(image.format).to_equal('GIF')
コード例 #17
0
 def test_create_engine(self):
     engine = Engine(self.context)
     expect(engine).to_be_instance_of(Engine)
コード例 #18
0
ファイル: test_gif.py プロジェクト: Bladrak/thumbor
 def test_load_image(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im:
         buffer = im.read()
     image = engine.create_image(buffer)
     expect(image.format).to_equal('GIF')