<s> import unittest <EOL> from azure . storage . blob import ( <EOL> BlockBlobService , <EOL> PageBlobService , <EOL> AppendBlobService , <EOL> ) <EOL> from azure . storage . queue import QueueService <EOL> from azure . storage . table import TableService <EOL> from azure . storage . file import FileService <EOL> from tests . testcase import StorageTestCase <EOL> SERVICES = { <EOL> BlockBlobService : '<STR_LIT>' , <EOL> PageBlobService : '<STR_LIT>' , <EOL> AppendBlobService : '<STR_LIT>' , <EOL> QueueService : '<STR_LIT>' , <EOL> TableService : '<STR_LIT>' , <EOL> FileService : '<STR_LIT:file>' <EOL> } <EOL> class StorageClientTest ( StorageTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( StorageClientTest , self ) . setUp ( ) <EOL> self . account_name = self . settings . STORAGE_ACCOUNT_NAME <EOL> self . account_key = self . settings . STORAGE_ACCOUNT_KEY <EOL> self . sas_token = '<STR_LIT>' <EOL> def validate_standard_account_endpoints ( self , service , type ) : <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . account_key , self . account_key ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' . format ( self . account_name , type ) ) <EOL> self . assertEqual ( service . secondary_endpoint , '<STR_LIT>' . format ( self . account_name , type ) ) <EOL> def test_create_service_with_key ( self ) : <EOL> for type in SERVICES . items ( ) : <EOL> service = type [ <NUM_LIT:0> ] ( self . account_name , self . account_key ) <EOL> self . validate_standard_account_endpoints ( service , type [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT>' ) <EOL> def test_create_service_with_sas ( self ) : <EOL> for type in SERVICES : <EOL> service = type ( self . account_name , sas_token = self . sas_token ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . sas_token , self . sas_token ) <EOL> self . assertIsNone ( service . account_key ) <EOL> def test_create_service_china ( self ) : <EOL> for type in SERVICES . items ( ) : <EOL> service = type [ <NUM_LIT:0> ] ( self . account_name , self . account_key , endpoint_suffix = '<STR_LIT>' ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . account_key , self . account_key ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' . format ( self . account_name , type [ <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( service . secondary_endpoint , '<STR_LIT>' . format ( self . account_name , type [ <NUM_LIT:1> ] ) ) <EOL> def test_create_service_protocol ( self ) : <EOL> for type in SERVICES . items ( ) : <EOL> service = type [ <NUM_LIT:0> ] ( self . account_name , self . account_key , protocol = '<STR_LIT:http>' ) <EOL> self . validate_standard_account_endpoints ( service , type [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT:http>' ) <EOL> def test_create_service_with_emulator ( self ) : <EOL> service = BlockBlobService ( is_emulated = True ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , '<STR_LIT>' ) <EOL> self . assertIsNotNone ( service . account_key ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT:http>' ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> self . assertEqual ( service . secondary_endpoint , '<STR_LIT>' ) <EOL> def test_create_blob_service_anonymous ( self ) : <EOL> BLOB_SERVICES = [ BlockBlobService , PageBlobService , AppendBlobService ] <EOL> for type in BLOB_SERVICES : <EOL> service = type ( self . account_name ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertIsNone ( service . account_key ) <EOL> self . assertIsNone ( service . sas_token ) <EOL> def test_create_blob_service_custom_domain ( self ) : <EOL> BLOB_SERVICES = [ BlockBlobService , PageBlobService , AppendBlobService ] <EOL> for type in BLOB_SERVICES : <EOL> service = type ( self . account_name , self . account_key , custom_domain = '<STR_LIT>' ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . account_key , self . account_key ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> self . assertEqual ( service . secondary_endpoint , self . account_name + '<STR_LIT>' ) <EOL> def test_create_service_empty_key ( self ) : <EOL> NON_BLOB_SERVICES = [ QueueService , TableService , FileService ] <EOL> for type in NON_BLOB_SERVICES : <EOL> try : <EOL> table_service = type ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except ValueError as e : <EOL> self . assertTrue ( str ( e ) == '<STR_LIT>' ) <EOL> def test_create_service_missing_arguments ( self ) : <EOL> for type in SERVICES : <EOL> with self . assertRaises ( ValueError ) : <EOL> service = type ( ) <EOL> def test_create_service_with_connection_string_key ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . account_key ) <EOL> for type in SERVICES . items ( ) : <EOL> service = type [ <NUM_LIT:0> ] ( connection_string = conn_string ) <EOL> self . validate_standard_account_endpoints ( service , type [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT>' ) <EOL> def test_create_service_with_connection_string_sas ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . sas_token ) <EOL> for type in SERVICES : <EOL> service = type ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . sas_token , self . sas_token ) <EOL> self . assertIsNone ( service . account_key ) <EOL> def test_create_service_with_connection_string_endpoint_protocol ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . account_key ) <EOL> for type in SERVICES . items ( ) : <EOL> service = type [ <NUM_LIT:0> ] ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . account_key , self . account_key ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' . format ( self . account_name , type [ <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( service . secondary_endpoint , '<STR_LIT>' . format ( self . account_name , type [ <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT:http>' ) <EOL> def test_create_service_with_connection_string_emulated ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . account_key ) <EOL> service = BlockBlobService ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , '<STR_LIT>' ) <EOL> self . assertIsNotNone ( service . account_key ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT:http>' ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> self . assertEqual ( service . secondary_endpoint , '<STR_LIT>' ) <EOL> def test_create_service_with_connection_string_emulated_explicit ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . account_key ) <EOL> service = BlockBlobService ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , '<STR_LIT>' ) <EOL> self . assertIsNotNone ( service . account_key ) <EOL> self . assertEqual ( service . protocol , '<STR_LIT:http>' ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> def test_create_service_with_connection_string_anonymous ( self ) : <EOL> conn_string = '<STR_LIT>' <EOL> service = BlockBlobService ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertIsNone ( service . account_name ) <EOL> self . assertIsNone ( service . account_key ) <EOL> self . assertIsNone ( service . sas_token ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> def test_create_service_with_connection_string_custom_domain ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . account_key ) <EOL> service = BlockBlobService ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . account_key , self . account_key ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> self . assertEqual ( service . secondary_endpoint , self . account_name + '<STR_LIT>' ) <EOL> def test_create_service_with_connection_string_custom_domain_trailing_slash ( self ) : <EOL> conn_string = '<STR_LIT>' . format ( self . account_name , self . account_key ) <EOL> service = BlockBlobService ( connection_string = conn_string ) <EOL> self . assertIsNotNone ( service ) <EOL> self . assertEqual ( service . account_name , self . account_name ) <EOL> self . assertEqual ( service . account_key , self . account_key ) <EOL> self . assertEqual ( service . primary_endpoint , '<STR_LIT>' ) <EOL> self . assertEqual ( service . secondary_endpoint , self . account_name + '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
