예제 #1
0
 def test_before_expiration_returns_something(self):
     rm_storage()
     options.STORAGE_EXPIRATION_SECONDS = 1000
     image_url = 'www.globo.com/media/globocom/img/sprite1.png'
     http_loaded = http.load(image_url)
     storage = file_storage.Storage()
     storage.put(image_url, http_loaded)
     assert storage.get(image_url)
예제 #2
0
 def test_after_expiration_returns_none(self):
     rm_storage()
     options.STORAGE_EXPIRATION_SECONDS = 1
     image_url = 'www.globo.com/media/globocom/img/sprite1.png'
     http_loaded = http.load(image_url)
     storage = file_storage.Storage()
     storage.put(image_url, http_loaded)
     time.sleep(2)
     assert storage.get(image_url) is None
예제 #3
0
    def test_get_crypto_for_url(self):
        rm_storage()
        image_url = 'www.globo.com/media/globocom/img/sprite1.png'
        http_loaded = http.load(image_url)
        storage = file_storage.Storage()

        storage.put(image_url, http_loaded)

        assert storage.get_crypto(image_url) == options.SECURITY_KEY
예제 #4
0
 def test_stores_image_does_not_store_crypt_key_if_not_in_options(self):
     rm_storage()
     options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = False
     image_url = 'www.globo.com/media/globocom/img/sprite1.png'
     http_loaded = http.load(image_url)
     storage = file_storage.Storage()
     storage.put(image_url, http_loaded)
     assert not exists(
         '/tmp/thumbor/storage/www.globo.com/media/globocom/img/sprite1.txt'
     ), 'crypto key was found into the storage'
예제 #5
0
 def test_stores_image(self):
     rm_storage()
     options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = False
     image_url = 'www.globo.com/media/globocom/img/sprite1.png'
     http_loaded = http.load(image_url)
     storage = file_storage.Storage()
     storage.put(image_url, http_loaded)
     assert exists(
         '/tmp/thumbor/storage/www.globo.com/media/globocom/img/sprite1.png'
     ), 'image not found into the storage'
예제 #6
0
    def test_finding_crypto_file(self):
        rm_storage()
        image_url = 'www.globo.com/media/globocom/img/sprite1.png'
        http_loaded = http.load(image_url)
        storage = file_storage.Storage()

        storage.put(image_url, http_loaded)

        crypto_file = '/tmp/thumbor/storage/www.globo.com/media/globocom/img/sprite1.txt'
        assert exists(crypto_file), 'crypto key was not found into the storage'

        assert file(crypto_file).read() == options.SECURITY_KEY
예제 #7
0
    def test_storing_an_empty_key_raises(self):
        rm_storage()
        options.SECURITY_KEY = False
        image_url = 'www.globo.com/media/globocom/img/sprite1.png'
        http_loaded = http.load(image_url)
        storage = file_storage.Storage()

        try:
            storage.put(image_url, http_loaded)
        except RuntimeError, err:
            assert str(
                err
            ) == "STORES_CRYPTO_KEY_FOR_EACH_IMAGE can't be True if no SECURITY_KEY specified"
            return
예제 #8
0
        def topic(self):
            config = Config(FILE_STORAGE_ROOT_PATH="/tmp/thumbor/file_storage/")
            root_path = join(config.FILE_STORAGE_ROOT_PATH, dirname(SAME_IMAGE_URL % 999))
            if exists(root_path):
                shutil.rmtree(root_path)

            old_exists = Storage.storages.exists
            Storage.storages.exists = lambda path: False
            try:
                storage = Storage.Storage(Context(config=config, server=get_server('ACME-SEC')))

                storage.put(SAME_IMAGE_URL % 998, IMAGE_BYTES)
                storage.put(SAME_IMAGE_URL % 999, IMAGE_BYTES)
            finally:
                Storage.storages.exists = old_exists

            return storage.get(SAME_IMAGE_URL % 999)
예제 #9
0
    def test_get_crypto_for_url_returns_None_if_urls_was_never_seen(self):
        rm_storage()
        image_url = 'www.globo.com/media/globocom/img/sprite1.png'
        storage = file_storage.Storage()

        assert not storage.get_crypto(image_url)