<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com <EMAIL>
from thumbor.storages.file_storage import Storage as FileStorage
from os.path import abspath, join, dirname
import shutil

from pyvows import Vows, expect
from tornado_pyvows.context import TornadoHTTPContext

from thumbor.app import ThumborServiceApp
from thumbor.importer import Importer
from thumbor.config import Config
from thumbor.context import Context, ServerParameters

storage_path = abspath(join(dirname(__file__), 'fixtures/'))

class BaseContext(TornadoHTTPContext):
    def __init__(self, *args, **kw):
        super(BaseContext, self).__init__(*args, **kw)

@Vows.batch
class GetImage(BaseContext):
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path

        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)

        return application


    class WithRegularImage(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/unsafe/smart/image.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class WithSignedRegularImage(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/_wIUeSaeHw8dricKG2MGhqu5thk=/smart/image.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class with_UTF8_URLEncoded_image_name(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/lc6e3kkm_2Ww7NWho8HPOe-sqLU=/smart/alabama1_ap620%C3%A9.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class without_unsafe_url_image(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/alabama1_ap620%C3%A9.jpg')
            return (rsp.code, rsp.headers)

        def should_be_404(self, (code, _)):
            expect(code).to_equal(404)

    class without_image(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/unsafe/')
            return (rsp.code, rsp.headers)

        def should_be_404(self, (code, _)):
            expect(code).to_equal(404)

    class with_UTF8_URLEncoded_image_name(TornadoHTTPContext):
        def topic(self):
            rsp = self.get(u'/unsafe/smart/alabama1_ap620é.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class with_UTF8_URLEncoded_image_name(TornadoHTTPContext):
        def topic(self):
            rsp = self.get(u'/lc6e3kkm_2Ww7NWho8HPOe-sqLU=/smart/alabama1_ap620é.jpg')
            return (rsp.code, rsp.headers)

        def should_be_404(self, (code, _)):
            expect(code).to_equal(404)

    class with_spaces_on_url(TornadoHTTPContext):
        def topic(self):
            rsp = self.get(u'/unsafe/image%20space.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class with_filter(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/VONFlQofX_4VJyejqS7U64nMpRE=/filters:filters:fill(blue)/image.jpg')
            return (rsp.code, rsp.headers)
        
        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

@Vows.batch
class GetImageWithoutUnsafe(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.ALLOW_UNSAFE_URL = False
<commit_msg>Fix url in vows GetImage with filter<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com <EMAIL>
from thumbor.storages.file_storage import Storage as FileStorage
from os.path import abspath, join, dirname
import shutil

from pyvows import Vows, expect
from tornado_pyvows.context import TornadoHTTPContext

from thumbor.app import ThumborServiceApp
from thumbor.importer import Importer
from thumbor.config import Config
from thumbor.context import Context, ServerParameters

storage_path = abspath(join(dirname(__file__), 'fixtures/'))

class BaseContext(TornadoHTTPContext):
    def __init__(self, *args, **kw):
        super(BaseContext, self).__init__(*args, **kw)

@Vows.batch
class GetImage(BaseContext):
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path

        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)

        return application


    class WithRegularImage(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/unsafe/smart/image.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class WithSignedRegularImage(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/_wIUeSaeHw8dricKG2MGhqu5thk=/smart/image.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class with_UTF8_URLEncoded_image_name(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/lc6e3kkm_2Ww7NWho8HPOe-sqLU=/smart/alabama1_ap620%C3%A9.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class without_unsafe_url_image(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/alabama1_ap620%C3%A9.jpg')
            return (rsp.code, rsp.headers)

        def should_be_404(self, (code, _)):
            expect(code).to_equal(404)

    class without_image(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/unsafe/')
            return (rsp.code, rsp.headers)

        def should_be_404(self, (code, _)):
            expect(code).to_equal(404)

    class with_UTF8_URLEncoded_image_name(TornadoHTTPContext):
        def topic(self):
            rsp = self.get(u'/unsafe/smart/alabama1_ap620é.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class with_UTF8_URLEncoded_image_name(TornadoHTTPContext):
        def topic(self):
            rsp = self.get(u'/lc6e3kkm_2Ww7NWho8HPOe-sqLU=/smart/alabama1_ap620é.jpg')
            return (rsp.code, rsp.headers)

        def should_be_404(self, (code, _)):
            expect(code).to_equal(404)

    class with_spaces_on_url(TornadoHTTPContext):
        def topic(self):
            rsp = self.get(u'/unsafe/image%20space.jpg')
            return (rsp.code, rsp.headers)

        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

    class with_filter(TornadoHTTPContext):
        def topic(self):
            rsp = self.get('/5YRxzS2yxZxj9SZ50SoZ11eIdDI=/filters:fill(blue)/image.jpg')
            return (rsp.code, rsp.headers)
        
        def should_be_200(self, (code, _)):
            expect(code).to_equal(200)

@Vows.batch
class GetImageWithoutUnsafe(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.ALLOW_UNSAFE_URL = False

{'fraction_non_alphanumeric': 0.11534263189812008, 'fraction_numerical': 0.02583383869011522, 'mean_word_length': 2.873179896665101, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2856671', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2777, 'n_words': 468}