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 test_retention_too_long(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): tsc = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=366)) with pytest.raises(HttpResponseError): tsc.set_service_properties(None, None, minute_metrics) self.sleep(SLEEP_DELAY)
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)
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 test_retention_too_long(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange tsc = TableServiceClient(self.account_url(tables_storage_account_name, "table"), tables_primary_storage_account_key) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=366)) # Assert pytest.raises(HttpResponseError, tsc.set_service_properties, None, None, minute_metrics)
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()
def test_set_hour_metrics(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) hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Act tsc.set_service_properties(hour_metrics=hour_metrics) # Assert received_props = tsc.get_service_properties() self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics) if self.is_live: sleep(SLEEP_DELAY)
async def test_retention_too_long_async(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange tsc = TableServiceClient( self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=366)) # Assert with pytest.raises(HttpResponseError): await tsc.set_service_properties(None, None, minute_metrics)
def test_set_minute_metrics(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) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Act tsc.set_service_properties(minute_metrics=minute_metrics) # Assert if self.is_live: time.sleep(30) received_props = tsc.get_service_properties() self._assert_metrics_equal(received_props['minute_metrics'], minute_metrics)
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, tables_primary_storage_account_key) logging = TableAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy( enabled=True, days=5)) # Act await tsc.set_service_properties(analytics_logging=logging) # Assert if self.is_live: time.sleep(30) received_props = await tsc.get_service_properties() self._assert_logging_equal(received_props['analytics_logging'], logging)