def test_create_service_with_custom_account_endpoint_path(self): token = self.generate_sas_token() custom_account_url = "http://local-machine:11002/custom/account/path/" + token for service_type in SERVICES.items(): conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};TableEndpoint={};'.format( self.tables_storage_account_name, self.tables_primary_storage_account_key, custom_account_url) # Act service = service_type[0].from_connection_string(conn_string, table_name="foo") # Assert assert service.account_name == self.tables_storage_account_name assert service.credential.named_key.name == self.tables_storage_account_name assert service.credential.named_key.key == self.tables_primary_storage_account_key assert service._primary_hostname == 'local-machine:11002/custom/account/path' service = TableServiceClient(endpoint=custom_account_url) assert service.account_name == "custom" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path') service = TableClient(endpoint=custom_account_url, table_name="foo") assert service.account_name == "custom" assert service.table_name == "foo" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path') service = TableClient.from_table_url("http://local-machine:11002/custom/account/path/foo" + token) assert service.account_name == "custom" assert service.table_name == "foo" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith('http://local-machine:11002/custom/account/path')
def test_create_service_with_custom_account_endpoint_path(self, resource_group, location, storage_account, storage_account_key): custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};TableEndpoint={};'.format( storage_account.name, storage_account_key, custom_account_url) # Act service = service_type[0].from_connection_string(conn_string, table_name="foo") # Assert self.assertEqual(service.account_name, storage_account.name) self.assertEqual(service.credential.account_name, storage_account.name) self.assertEqual(service.credential.account_key, storage_account_key) self.assertEqual(service._primary_hostname, 'local-machine:11002/custom/account/path') service = TableServiceClient(account_url=custom_account_url) self.assertEqual(service.account_name, None) self.assertEqual(service.credential, None) self.assertEqual(service._primary_hostname, 'local-machine:11002/custom/account/path') self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path')) service = TableClient(account_url=custom_account_url, table_name="foo") self.assertEqual(service.account_name, None) self.assertEqual(service.table_name, "foo") self.assertEqual(service.credential, None) self.assertEqual(service._primary_hostname, 'local-machine:11002/custom/account/path') self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path')) service = TableClient.from_table_url("http://local-machine:11002/custom/account/path/foo" + self.sas_token) self.assertEqual(service.account_name, None) self.assertEqual(service.table_name, "foo") self.assertEqual(service.credential, None) self.assertEqual(service._primary_hostname, 'local-machine:11002/custom/account/path') self.assertTrue(service.url.startswith('http://local-machine:11002/custom/account/path'))
def test_create_client_for_cosmos_emulator(self): emulator_credential = AzureNamedKeyCredential( 'localhost', self.tables_primary_cosmos_account_key) emulator_connstr = "DefaultEndpointsProtocol=http;AccountName=localhost;AccountKey={};TableEndpoint=http://localhost:8902/;".format( self.tables_primary_cosmos_account_key) client = TableServiceClient.from_connection_string(emulator_connstr) assert client.url == "http://localhost:8902" assert client.account_name == 'localhost' assert client.credential.named_key.name == 'localhost' assert client.credential.named_key.key == self.tables_primary_cosmos_account_key assert client._cosmos_endpoint assert client.scheme == 'http' client = TableServiceClient("http://localhost:8902/", credential=emulator_credential) assert client.url == "http://localhost:8902" assert client.account_name == 'localhost' assert client.credential.named_key.name == 'localhost' assert client.credential.named_key.key == self.tables_primary_cosmos_account_key assert client._cosmos_endpoint assert client.scheme == 'http' table = TableClient.from_connection_string(emulator_connstr, 'tablename') assert table.url == "http://localhost:8902" assert table.account_name == 'localhost' assert table.table_name == 'tablename' assert table.credential.named_key.name == 'localhost' assert table.credential.named_key.key == self.tables_primary_cosmos_account_key assert table._cosmos_endpoint assert table.scheme == 'http' table = TableClient("http://localhost:8902/", "tablename", credential=emulator_credential) assert table.url == "http://localhost:8902" assert table.account_name == 'localhost' assert table.table_name == 'tablename' assert table.credential.named_key.name == 'localhost' assert table.credential.named_key.key == self.tables_primary_cosmos_account_key assert table._cosmos_endpoint assert table.scheme == 'http' table = TableClient.from_table_url( "http://localhost:8902/Tables('tablename')", credential=emulator_credential) assert table.url == "http://localhost:8902" assert table.account_name == 'localhost' assert table.table_name == 'tablename' assert table.credential.named_key.name == 'localhost' assert table.credential.named_key.key == self.tables_primary_cosmos_account_key assert table._cosmos_endpoint assert table.scheme == 'http'
def test_create_service_with_custom_account_endpoint_path( self, tables_cosmos_account_name, tables_primary_cosmos_account_key): custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};TableEndpoint={};'.format( tables_cosmos_account_name, tables_primary_cosmos_account_key, custom_account_url) # Act service = service_type[0].from_connection_string(conn_string, table_name="foo") # Assert assert service.account_name == tables_cosmos_account_name assert service.credential.account_name == tables_cosmos_account_name assert service.credential.account_key == tables_primary_cosmos_account_key assert service._primary_hostname == 'local-machine:11002/custom/account/path' service = TableServiceClient(account_url=custom_account_url) assert service.account_name == None assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' # mine doesnt have a question mark at the end assert service.url.startswith( 'http://local-machine:11002/custom/account/path') service = TableClient(account_url=custom_account_url, table_name="foo") assert service.account_name == None assert service.table_name == "foo" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith( 'http://local-machine:11002/custom/account/path') service = TableClient.from_table_url( "http://local-machine:11002/custom/account/path/foo" + self.sas_token) assert service.account_name == None assert service.table_name == "foo" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith( 'http://local-machine:11002/custom/account/path') if self.is_live: sleep(SLEEP_DELAY)
def test_create_service_with_custom_account_endpoint_path(self): self.sas_token = AzureSasCredential(self.generate_sas_token()) custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token.signature for service_type in SERVICES.items(): conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};TableEndpoint={};'.format( self.tables_cosmos_account_name, self.tables_primary_cosmos_account_key, custom_account_url) # Act service = service_type[0].from_connection_string(conn_string, table_name="foo") # Assert assert service.account_name == self.tables_cosmos_account_name assert service.credential.named_key.name == self.tables_cosmos_account_name assert service.credential.named_key.key == self.tables_primary_cosmos_account_key assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.scheme == 'http' service = TableServiceClient(endpoint=custom_account_url) assert service.account_name == "custom" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' # mine doesnt have a question mark at the end assert service.url.startswith( 'http://local-machine:11002/custom/account/path') assert service.scheme == 'http' service = TableClient(endpoint=custom_account_url, table_name="foo") assert service.account_name == "custom" assert service.table_name == "foo" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith( 'http://local-machine:11002/custom/account/path') assert service.scheme == 'http' service = TableClient.from_table_url( "http://local-machine:11002/custom/account/path/foo" + self.sas_token.signature) assert service.account_name == "custom" assert service.table_name == "foo" assert service.credential == None assert service._primary_hostname == 'local-machine:11002/custom/account/path' assert service.url.startswith( 'http://local-machine:11002/custom/account/path') assert service.scheme == 'http'
def test_create_client_for_azurite(self): azurite_credential = AzureNamedKeyCredential("myaccount", self.tables_primary_storage_account_key) http_connstr = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey={};TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;".format( self.tables_primary_storage_account_key ) https_connstr = "DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey={};TableEndpoint=https://127.0.0.1:10002/devstoreaccount1;".format( self.tables_primary_storage_account_key ) account_url = "https://127.0.0.1:10002/myaccount" client = TableServiceClient(account_url, credential=azurite_credential) assert client.account_name == "myaccount" assert client.url == "https://127.0.0.1:10002/myaccount" assert client._location_mode == "primary" assert client._secondary_endpoint == "https://127.0.0.1:10002/myaccount-secondary" assert client.credential.named_key.key == azurite_credential.named_key.key assert client.credential.named_key.name == azurite_credential.named_key.name assert not client._cosmos_endpoint client = TableServiceClient.from_connection_string(http_connstr) assert client.account_name == "devstoreaccount1" assert client.url == "http://127.0.0.1:10002/devstoreaccount1" assert client._location_mode == "primary" assert client._secondary_endpoint == "http://127.0.0.1:10002/devstoreaccount1-secondary" assert client.credential.named_key.key == self.tables_primary_storage_account_key assert client.credential.named_key.name == "devstoreaccount1" assert not client._cosmos_endpoint client = TableServiceClient.from_connection_string(https_connstr) assert client.account_name == "devstoreaccount1" assert client.url == "https://127.0.0.1:10002/devstoreaccount1" assert client._location_mode == "primary" assert client._secondary_endpoint == "https://127.0.0.1:10002/devstoreaccount1-secondary" assert client.credential.named_key.key == self.tables_primary_storage_account_key assert client.credential.named_key.name == "devstoreaccount1" assert not client._cosmos_endpoint table = TableClient(account_url, "tablename", credential=azurite_credential) assert table.account_name == "myaccount" assert table.table_name == "tablename" assert table.url == "https://127.0.0.1:10002/myaccount" assert table._location_mode == "primary" assert table._secondary_endpoint == "https://127.0.0.1:10002/myaccount-secondary" assert table.credential.named_key.key == azurite_credential.named_key.key assert table.credential.named_key.name == azurite_credential.named_key.name assert not table._cosmos_endpoint table = TableClient.from_connection_string(http_connstr, "tablename") assert table.account_name == "devstoreaccount1" assert table.table_name == "tablename" assert table.url == "http://127.0.0.1:10002/devstoreaccount1" assert table._location_mode == "primary" assert table._secondary_endpoint == "http://127.0.0.1:10002/devstoreaccount1-secondary" assert table.credential.named_key.key == self.tables_primary_storage_account_key assert table.credential.named_key.name == "devstoreaccount1" assert not table._cosmos_endpoint table = TableClient.from_connection_string(https_connstr, "tablename") assert table.account_name == "devstoreaccount1" assert table.table_name == "tablename" assert table.url == "https://127.0.0.1:10002/devstoreaccount1" assert table._location_mode == "primary" assert table._secondary_endpoint == "https://127.0.0.1:10002/devstoreaccount1-secondary" assert table.credential.named_key.key == self.tables_primary_storage_account_key assert table.credential.named_key.name == "devstoreaccount1" assert not table._cosmos_endpoint table_url = "https://127.0.0.1:10002/myaccount/Tables('tablename')" table = TableClient.from_table_url(table_url, azurite_credential) assert table.account_name == "myaccount" assert table.table_name == "tablename" assert table.url == "https://127.0.0.1:10002/myaccount" assert table._location_mode == "primary" assert table._secondary_endpoint == "https://127.0.0.1:10002/myaccount-secondary" assert table.credential.named_key.key == azurite_credential.named_key.key assert table.credential.named_key.name == azurite_credential.named_key.name assert not table._cosmos_endpoint