示例#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 = Storage()
     storage.put(image_url, http_loaded)
     assert storage.get(image_url)
示例#2
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 = Storage()
     storage.put(image_url, http_loaded)
     assert collection.find_one({'path': image_url
                                 }), 'image not found into the storage'
示例#3
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 = Storage()
     storage.put(image_url, http_loaded)
     time.sleep(2)
     assert storage.get(image_url) is None
示例#4
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 = Storage()

        storage.put(image_url, http_loaded)

        assert storage.get_crypto(image_url) == options.SECURITY_KEY
示例#5
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 = Storage()
     storage.put(image_url, http_loaded)
     assert not collection.find_one({
         'path': image_url
     }).has_key('crypto'), 'crypto key should not be found into the storage'
示例#6
0
 def test_gets_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 = Storage()
     storage.put(image_url, http_loaded)
     stored_image = storage.get(image_url)
     assert stored_image and not isinstance(
         stored_image, dict), 'image not found into the storage'
     assert http_loaded == stored_image, 'stored image did not match the loaded one'
示例#7
0
    def test_storing_an_empty_key_raises(self):
        rm_storage()
        options.SECURITY_KEY = False
        options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True
        image_url = 'www.globo.com/media/globocom/img/sprite1.png'
        http_loaded = http.load(image_url)
        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 test_finding_crypto_file(self):
        rm_storage()
        options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True
        options.SECURITY_KEY = 'MY-SECURITY-KEY'
        image_url = 'www.globo.com/media/globocom/img/sprite1.png'
        http_loaded = http.load(image_url)
        storage = Storage()

        storage.put(image_url, http_loaded)

        stored_crypto_key = collection.find_one({
            'path': image_url
        }).get('crypto')
        assert stored_crypto_key == options.SECURITY_KEY, '%s crypto key should be equal %s' % (
            stored_crypto_key, options.SECURITY_KEY)
示例#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 = Storage()

        assert not storage.get_crypto(image_url)