<s> import os <EOL> import pytest <EOL> from libcloud . storage . base import ( StorageDriver , Container ) <EOL> from flask_cloudy import ( get_file_extension , <EOL> get_file_extension_type , <EOL> get_file_name , <EOL> get_driver_class , <EOL> get_provider_name , <EOL> Storage , <EOL> Object , <EOL> InvalidExtensionError ) <EOL> from tests import config <EOL> CWD = os . path . dirname ( __file__ ) <EOL> CONTAINER = "<STR_LIT>" % ( CWD , config . CONTAINER ) if config . PROVIDER == "<STR_LIT>" else config . CONTAINER <EOL> class App ( object ) : <EOL> config = dict ( <EOL> STORAGE_PROVIDER = config . PROVIDER , <EOL> STORAGE_KEY = config . KEY , <EOL> STORAGE_SECRET = config . SECRET , <EOL> STORAGE_CONTAINER = CONTAINER , <EOL> STORAGE_SERVER = False , <EOL> STORAGE_ALLOWED_EXTENSIONS = [ ] ) <EOL> def test_get_file_extension ( ) : <EOL> filename = "<STR_LIT>" <EOL> assert get_file_extension ( filename ) == "<STR_LIT>" <EOL> def test_get_file_extension_type ( ) : <EOL> filename = "<STR_LIT>" <EOL> assert get_file_extension_type ( filename ) == "<STR_LIT>" <EOL> def test_get_file_name ( ) : <EOL> filename = "<STR_LIT>" <EOL> assert get_file_name ( filename ) == "<STR_LIT>" <EOL> def test_get_provider_name ( ) : <EOL> class GoogleStorageDriver ( object ) : <EOL> pass <EOL> driver = GoogleStorageDriver ( ) <EOL> assert get_provider_name ( driver ) == "<STR_LIT>" <EOL> app = App ( ) <EOL> def app_storage ( ) : <EOL> return Storage ( app = App ( ) ) <EOL> def test_get_driver_class ( ) : <EOL> driver = get_driver_class ( "<STR_LIT>" ) <EOL> assert isinstance ( driver , type ) <EOL> def test_driver ( ) : <EOL> storage = app_storage ( ) <EOL> assert isinstance ( storage . driver , StorageDriver ) <EOL> def test_container ( ) : <EOL> storage = app_storage ( ) <EOL> assert isinstance ( storage . container , Container ) <EOL> def test_flask_app ( ) : <EOL> storage = app_storage ( ) <EOL> assert isinstance ( storage . driver , StorageDriver ) <EOL> def test_iter ( ) : <EOL> storage = app_storage ( ) <EOL> l = [ o for o in storage ] <EOL> assert isinstance ( l , list ) <EOL> def test_storage_object_not_exists ( ) : <EOL> object_name = "<STR_LIT>" <EOL> storage = app_storage ( ) <EOL> assert object_name not in storage <EOL> def test_storage_object ( ) : <EOL> object_name = "<STR_LIT>" <EOL> storage = app_storage ( ) <EOL> o = storage . create ( object_name ) <EOL> assert isinstance ( o , Object ) <EOL> def test_object_type_extension ( ) : <EOL> object_name = "<STR_LIT>" <EOL> storage = app_storage ( ) <EOL> o = storage . create ( object_name ) <EOL> assert o . type == "<STR_LIT>" <EOL> assert o . extension == "<STR_LIT>" <EOL> def test_object_provider_name ( ) : <EOL> object_name = "<STR_LIT>" <EOL> storage = app_storage ( ) <EOL> o = storage . create ( object_name ) <EOL> assert o . provider_name == config . PROVIDER . lower ( ) <EOL> def test_object_object_path ( ) : <EOL> object_name = "<STR_LIT>" <EOL> storage = app_storage ( ) <EOL> o = storage . create ( object_name ) <EOL> p = "<STR_LIT>" % ( o . container . name , o . name ) <EOL> assert o . path . endswith ( p ) <EOL> def test_storage_upload_invalid ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> with pytest . raises ( InvalidExtensionError ) : <EOL> storage . upload ( CWD + "<STR_LIT>" , name = object_name ) <EOL> def test_storage_upload_ovewrite ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> o = storage . upload ( CWD + "<STR_LIT>" , name = object_name , overwrite = True ) <EOL> assert isinstance ( o , Object ) <EOL> assert o . name == object_name <EOL> def test_storage_get ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> o = storage . upload ( CWD + "<STR_LIT>" , name = object_name , overwrite = True ) <EOL> o2 = storage . get ( o . name ) <EOL> assert isinstance ( o2 , Object ) <EOL> def test_storage_get_none ( ) : <EOL> storage = app_storage ( ) <EOL> o2 = storage . get ( "<STR_LIT>" ) <EOL> assert o2 is None <EOL> def test_storage_upload ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> storage . upload ( CWD + "<STR_LIT>" , name = object_name ) <EOL> o = storage . upload ( CWD + "<STR_LIT>" , name = object_name ) <EOL> assert isinstance ( o , Object ) <EOL> assert o . name != object_name <EOL> def test_storage_upload_use_filename_name ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> o = storage . upload ( CWD + "<STR_LIT>" , overwrite = True , allowed_extensions = [ "<STR_LIT>" ] ) <EOL> assert o . name == object_name <EOL> def test_storage_upload_append_extension ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> o = storage . upload ( CWD + "<STR_LIT>" , object_name , overwrite = True ) <EOL> assert get_file_extension ( o . name ) == "<STR_LIT>" <EOL> def test_storage_upload_with_prefix ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> prefix = "<STR_LIT>" <EOL> full_name = "<STR_LIT>" % ( prefix , object_name , "<STR_LIT>" ) <EOL> o = storage . upload ( CWD + "<STR_LIT>" , name = object_name , prefix = prefix , overwrite = True ) <EOL> assert full_name in storage <EOL> assert o . name == full_name <EOL> def test_save_to ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> o = storage . upload ( CWD + "<STR_LIT>" , name = object_name ) <EOL> file = o . save_to ( CWD + "<STR_LIT>" , overwrite = True ) <EOL> file2 = o . save_to ( CWD + "<STR_LIT>" , name = "<STR_LIT>" , overwrite = True ) <EOL> assert os . path . isfile ( file ) <EOL> assert file2 == CWD + "<STR_LIT>" <EOL> def test_delete ( ) : <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> o = storage . upload ( CWD + "<STR_LIT>" , name = object_name ) <EOL> assert object_name in storage <EOL> o . delete ( ) <EOL> assert object_name not in storage <EOL> def test_werkzeug_upload ( ) : <EOL> try : <EOL> import werkzeug <EOL> except ImportError : <EOL> return <EOL> storage = app_storage ( ) <EOL> object_name = "<STR_LIT>" <EOL> filepath = CWD + "<STR_LIT>" <EOL> file = None <EOL> with open ( filepath , '<STR_LIT:rb>' ) as fp : <EOL> file = werkzeug . datastructures . FileStorage ( fp ) <EOL> file . filename = object_name <EOL> o = storage . upload ( file , overwrite = True ) <EOL> assert isinstance ( o , Object ) <EOL> assert o . name == object_name </s>
