def test_create_properties(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # # Arrange ts = TableServiceClient( self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) table_name = self._get_table_reference() # Act created = ts.create_table(table_name) # Assert assert created.table_name == table_name # properties = ts.get_service_properties() ts.set_service_properties(analytics_logging=TableAnalyticsLogging( write=True)) p = ts.get_service_properties() ts.set_service_properties(minute_metrics=Metrics( enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))) ps = ts.get_service_properties() ts.delete_table(table_name) if self.is_live: sleep(SLEEP_DELAY)
def _assert_properties_default(self, prop): assert prop is not None self._assert_logging_equal(prop['analytics_logging'], TableAnalyticsLogging()) self._assert_metrics_equal(prop['hour_metrics'], Metrics()) self._assert_metrics_equal(prop['minute_metrics'], Metrics()) self._assert_cors_equal(prop['cors'], list())
def test_create_properties(self, resource_group, location, storage_account, storage_account_key): # # Arrange ts = TableServiceClient(self.account_url(storage_account, "table"), storage_account_key) table_name = self._get_table_reference() # Act created = ts.create_table(table_name) # Assert assert created.table_name == table_name properties = ts.get_service_properties() print(properties) ts.set_service_properties(analytics_logging=TableAnalyticsLogging( write=True)) # have to wait for return to service p = ts.get_service_properties() # have to wait for return to service ts.set_service_properties(minute_metrics=Metrics( enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))) ps = ts.get_service_properties() print(ps) print(p) ts.delete_table(table_name)
async def test_aad_service_properties(self, tables_storage_account_name): try: account_url = self.account_url(tables_storage_account_name, "table") ts = TableServiceClient(credential=self.get_token_credential(), endpoint=account_url) table_name = self._get_table_reference() created = await ts.create_table(table_name) assert created.table_name == table_name properties = await ts.get_service_properties() await ts.set_service_properties( analytics_logging=TableAnalyticsLogging(write=True)) # have to wait async for return to service p = await ts.get_service_properties() # have to wait async for return to service await ts.set_service_properties(minute_metrics=TableMetrics( enabled=True, include_apis=True, retention_policy=TableRetentionPolicy(enabled=True, days=5))) ps = await ts.get_service_properties() finally: await ts.delete_table(table_name)
def test_create_properties(self, tables_storage_account_name, tables_primary_storage_account_key): # # Arrange account_url = self.account_url(tables_storage_account_name, "table") ts = self.create_client_from_credential(TableServiceClient, tables_primary_storage_account_key, endpoint=account_url) table_name = self._get_table_reference() # Act created = ts.create_table(table_name) # Assert assert created.table_name == table_name properties = ts.get_service_properties() ts.set_service_properties(analytics_logging=TableAnalyticsLogging(write=True)) # have to wait for return to service p = ts.get_service_properties() # have to wait for return to service ts.set_service_properties( minute_metrics=Metrics( enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) ) ) ps = ts.get_service_properties() ts.delete_table(table_name)
def _assert_properties_default(self, prop): assert prop is not None self._assert_logging_equal(prop["analytics_logging"], TableAnalyticsLogging()) self._assert_metrics_equal(prop["hour_metrics"], TableMetrics()) self._assert_metrics_equal(prop["minute_metrics"], TableMetrics()) self._assert_cors_equal(prop["cors"], list())
def test_set_logging(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange url = self.account_url(tables_cosmos_account_name, "cosmos") tsc = TableServiceClient(url, tables_primary_cosmos_account_key) logging = TableAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Act tsc.set_service_properties(analytics_logging=logging) # Assert received_props = tsc.get_service_properties() self._assert_logging_equal(received_props['analytics_logging'], logging) if self.is_live: time.sleep(30)
def test_table_service_properties(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange url = self.account_url(tables_cosmos_account_name, "cosmos") tsc = TableServiceClient(url, tables_primary_cosmos_account_key) # Act resp = tsc.set_service_properties( analytics_logging=TableAnalyticsLogging(), hour_metrics=Metrics(), minute_metrics=Metrics(), cors=list()) # Assert assert resp is None self._assert_properties_default(tsc.get_service_properties()) if self.is_live: sleep(SLEEP_DELAY)
def test_table_service_properties(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange url = self.account_url(tables_storage_account_name, "table") tsc = TableServiceClient(url, tables_primary_storage_account_key) # Act resp = tsc.set_service_properties( analytics_logging=TableAnalyticsLogging(), hour_metrics=Metrics(), minute_metrics=Metrics(), cors=list()) # Assert assert resp is None if self.is_live: time.sleep(30) self._assert_properties_default(tsc.get_service_properties())
async def test_table_service_properties_async( self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange url = self.account_url(tables_storage_account_name, "table") tsc = TableServiceClient(url, credential=tables_primary_storage_account_key, logging_enable=True) # Act resp = await tsc.set_service_properties( analytics_logging=TableAnalyticsLogging(), hour_metrics=TableMetrics(), minute_metrics=TableMetrics(), cors=list()) # Assert assert resp is None if self.is_live: time.sleep(45) self._assert_properties_default(await tsc.get_service_properties())
def table_service_properties(self): # Instantiate the TableServiceClient from a connection string from azure.data.tables import TableServiceClient table_service = TableServiceClient.from_connection_string(conn_str=self.connection_string) # [START set_table_service_properties] # Create service properties from azure.data.tables import TableAnalyticsLogging, Metrics, CorsRule, RetentionPolicy # Create logging settings logging = TableAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create metrics for requests statistics hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create CORS rules cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] allowed_methods = ['GET', 'PUT'] max_age_in_seconds = 500 exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] cors_rule2 = CorsRule( allowed_origins, allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, allowed_headers=allowed_headers ) cors = [cors_rule1, cors_rule2] # Set the service properties table_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) # [END set_table_service_properties] # [START get_table_service_properties] properties = table_service.get_service_properties()
async def test_set_logging_async(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange url = self.account_url(tables_storage_account_name, "table") tsc = TableServiceClient(url, credential=tables_primary_storage_account_key) logging = TableAnalyticsLogging(read=True, write=True, delete=True, retention_policy=TableRetentionPolicy( enabled=True, days=5)) # Act await tsc.set_service_properties(analytics_logging=logging) # Assert if self.is_live: time.sleep(45) received_props = await tsc.get_service_properties() self._assert_logging_equal(received_props['analytics_logging'], logging)