<s> """<STR_LIT>""" <EOL> from cafe . drivers . unittest . decorators import memoized <EOL> from cafe . drivers . unittest . fixtures import BaseTestFixture <EOL> from cloudcafe . objectstorage . composites import ObjectStorageComposite <EOL> class ObjectStorageUser ( object ) : <EOL> def __init__ ( self , name , id_ , password ) : <EOL> self . name = name <EOL> self . id_ = id_ <EOL> self . passwd = password <EOL> self . token = None <EOL> self . storage_url = None <EOL> self . client = None <EOL> self . behaviors = None <EOL> self . roles = [ ] <EOL> class ObjectStorageFixture ( BaseTestFixture ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> @ memoized <EOL> def required_version ( cls , * required_versions ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> required_version = required_versions [ <NUM_LIT:0> ] <EOL> objectstorage_api_config = ObjectStorageComposite ( ) . config <EOL> behaviors = ObjectStorageComposite ( ) . behaviors <EOL> swift_version = objectstorage_api_config . version <EOL> if not swift_version and objectstorage_api_config . use_swift_info : <EOL> info = behaviors . get_swift_info ( ) <EOL> swift_version = info . get ( <EOL> '<STR_LIT>' , { '<STR_LIT:version>' : None } ) . get ( '<STR_LIT:version>' , None ) <EOL> if not swift_version : <EOL> return func <EOL> if required_version . startswith ( '<STR_LIT:<>' ) : <EOL> required_version = required_version . lstrip ( '<STR_LIT:<>' ) <EOL> compare_func = lambda sv , tv : sv < tv <EOL> extra_message = '<STR_LIT>' <EOL> elif required_version . startswith ( '<STR_LIT:>>' ) : <EOL> required_version = required_version . lstrip ( '<STR_LIT:>>' ) <EOL> compare_func = lambda sv , tv : sv > tv <EOL> extra_message = '<STR_LIT>' <EOL> else : <EOL> required_version = required_version . lstrip ( '<STR_LIT:=>' ) <EOL> compare_func = lambda sv , tv : sv . startswith ( tv ) <EOL> extra_message = '<STR_LIT>' <EOL> if compare_func ( swift_version , required_version ) : <EOL> func <EOL> setattr ( func , '<STR_LIT>' , True ) <EOL> setattr ( <EOL> func , '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( <EOL> swift_version , extra_message , required_version ) ) <EOL> return func <EOL> return decorator <EOL> @ classmethod <EOL> @ memoized <EOL> def required_features ( cls , * required_features ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> objectstorage_api_config = ObjectStorageComposite ( ) . config <EOL> behaviors = ObjectStorageComposite ( ) . behaviors <EOL> features = behaviors . get_configured_features ( ) <EOL> if features == objectstorage_api_config . ALL_FEATURES : <EOL> return func <EOL> if features == objectstorage_api_config . NO_FEATURES : <EOL> setattr ( func , '<STR_LIT>' , True ) <EOL> setattr ( func , '<STR_LIT>' , '<STR_LIT>' ) <EOL> features = features . split ( ) <EOL> missing_reqs = False <EOL> for req in required_features : <EOL> if req not in features : <EOL> missing_reqs = True <EOL> break <EOL> if missing_reqs : <EOL> setattr ( func , '<STR_LIT>' , True ) <EOL> setattr ( <EOL> func , '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( required_features ) ) ) <EOL> return func <EOL> return decorator <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( ObjectStorageFixture , cls ) . setUpClass ( ) <EOL> object_storage_api = ObjectStorageComposite ( ) <EOL> cls . auth_info = object_storage_api . auth_info <EOL> cls . objectstorage_api_config = object_storage_api . config <EOL> cls . storage_url = object_storage_api . storage_url <EOL> cls . auth_token = object_storage_api . auth_token <EOL> cls . base_container_name = ( <EOL> cls . objectstorage_api_config . base_container_name ) <EOL> cls . client = object_storage_api . client <EOL> cls . behaviors = object_storage_api . behaviors <EOL> def create_temp_container ( self , descriptor = '<STR_LIT>' , headers = None ) : <EOL> """<STR_LIT>""" <EOL> container_name = self . behaviors . generate_unique_container_name ( descriptor ) <EOL> self . client . create_container ( container_name , headers = headers ) <EOL> self . addCleanup ( <EOL> self . behaviors . force_delete_containers , <EOL> [ container_name ] ) <EOL> return container_name </s>
