def test_before_expiration_returns_something(self): options.STORAGE_EXPIRATION_SECONDS = 1000 image_url = 'www.globo.com/media/globocom/img/sprite1.png?8' http_loaded = http.load(image_url) storage = Storage() storage.put(image_url, http_loaded) assert storage.get(image_url)
def test_after_expiration_returns_none(self): options.STORAGE_EXPIRATION_SECONDS = 1 image_url = 'www.globo.com/media/globocom/img/sprite1.png?9' http_loaded = http.load(image_url) storage = Storage() storage.put(image_url, http_loaded) time.sleep(2) assert storage.get(image_url) is None
def test_get_crypto_for_url(self): image_url = 'www.globo.com/media/globocom/img/sprite1.png?6' http_loaded = http.load(image_url) storage = Storage() storage.put(image_url, http_loaded) assert storage.get_crypto(image_url) == options.SECURITY_KEY
def test_gets_image(self): options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = False image_url = 'www.globo.com/media/globocom/img/sprite1.png?2' 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'
def test_stores_image_does_not_store_crypt_key_if_not_in_options(self): options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = False image_url = 'www.globo.com/media/globocom/img/sprite1.png?3' http_loaded = http.load(image_url) storage = Storage() storage.put(image_url, http_loaded) image = get_image_by_path(image_url) assert not image['security_key']
def test_stores_image(self): options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = False image_url = 'www.globo.com/media/globocom/img/sprite1.png?1' http_loaded = http.load(image_url) storage = Storage() storage.put(image_url, http_loaded) image = get_image_by_path(image_url) assert image['url'] == image_url assert image['contents'] assert image['last_update']
def test_storing_an_empty_key_raises(self): options.SECURITY_KEY = False options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True image_url = 'www.globo.com/media/globocom/img/sprite1.png?4' 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
def test_finding_crypto_file(self): options.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True options.SECURITY_KEY = 'MY-SECURITY-KEY-5' image_url = 'www.globo.com/media/globocom/img/sprite1.png?5' http_loaded = http.load(image_url) storage = Storage() storage.put(image_url, http_loaded) image = get_image_by_path(image_url) assert image['security_key'] == options.SECURITY_KEY
def test_get_crypto_for_url_returns_None_if_urls_was_never_seen(self): image_url = 'www.globo.com/media/globocom/img/sprite1.png?7' storage = Storage() assert not storage.get_crypto(image_url)