async def test_async_mgmt_topic_list_runtime_properties(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topics = await async_pageable_to_list(mgmt_service.list_topics()) topics_infos = await async_pageable_to_list(mgmt_service.list_topics_runtime_properties()) assert len(topics) == len(topics_infos) == 0 await mgmt_service.create_topic("test_topic") topics = await async_pageable_to_list(mgmt_service.list_topics()) topics_infos = await async_pageable_to_list(mgmt_service.list_topics_runtime_properties()) assert len(topics) == 1 and len(topics_infos) == 1 assert topics[0].name == topics_infos[0].name == "test_topic" info = topics_infos[0] assert info.accessed_at_utc is not None assert info.updated_at_utc is not None assert info.subscription_count is 0 assert info.size_in_bytes == 0 assert info.scheduled_message_count == 0 await mgmt_service.delete_topic("test_topic") topics_infos = await async_pageable_to_list(mgmt_service.list_topics_runtime_properties()) assert len(topics_infos) == 0
async def test_async_mgmt_subscription_create_with_subscription_description( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "iweidk" subscription_name = "kdosako" try: await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription( topic_name, name=subscription_name, auto_delete_on_idle=datetime.timedelta(minutes=10), dead_lettering_on_message_expiration=True, default_message_time_to_live=datetime.timedelta(minutes=11), enable_batched_operations=True, lock_duration=datetime.timedelta(seconds=13), max_delivery_count=14, requires_session=True) subscription = await mgmt_service.get_subscription( topic_name, subscription_name) assert subscription.name == subscription_name assert subscription.auto_delete_on_idle == datetime.timedelta( minutes=10) assert subscription.dead_lettering_on_message_expiration == True assert subscription.default_message_time_to_live == datetime.timedelta( minutes=11) assert subscription.enable_batched_operations == True assert subscription.lock_duration == datetime.timedelta(seconds=13) assert subscription.max_delivery_count == 14 assert subscription.requires_session == True finally: await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_topic_basic_v2017_04(self, servicebus_namespace_connection_string, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string, api_version=ApiVersion.V2017_04) await clear_topics(mgmt_service) await mgmt_service.create_topic("test_topic") topics = await async_pageable_to_list(mgmt_service.list_topics()) assert len(topics) == 1 and topics[0].name == "test_topic" topic = await mgmt_service.get_topic("test_topic") assert topic.name == "test_topic" await mgmt_service.delete_topic("test_topic") topics = await async_pageable_to_list(mgmt_service.list_topics()) assert len(topics) == 0 with pytest.raises(HttpResponseError): await mgmt_service.create_topic("topic_can_not_be_created", max_message_size_in_kilobytes=1024) fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net' mgmt_service = ServiceBusAdministrationClient( fully_qualified_namespace, credential=ServiceBusSharedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key), api_version=ApiVersion.V2017_04 ) await mgmt_service.create_topic("test_topic") topics = await async_pageable_to_list(mgmt_service.list_topics()) assert len(topics) == 1 and topics[0].name == "test_topic" topic = await mgmt_service.get_topic("test_topic") assert topic.name == "test_topic" await mgmt_service.delete_topic("test_topic") topics = await async_pageable_to_list(mgmt_service.list_topics()) assert len(topics) == 0 with pytest.raises(HttpResponseError): await mgmt_service.create_topic("topic_can_not_be_created", max_message_size_in_kilobytes=1024)
async def test_async_mgmt_rule_create_duplicate( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "dqkodq" subscription_name = 'kkaqo' rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") try: await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription(topic_name, subscription_name) await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) with pytest.raises(ResourceExistsError): await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) finally: await mgmt_service.delete_rule(topic_name, subscription_name, rule_name) await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_queue_list_with_negative_credential( self, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key): # invalid_conn_str = 'Endpoint=sb://invalid.servicebus.windows.net/;SharedAccessKeyName=invalid;SharedAccessKey=invalid' # mgmt_service = ServiceBusAdministrationClient.from_connection_string(invalid_conn_str) # with pytest.raises(ServiceRequestError): # await async_pageable_to_list(mgmt_service.list_queues()) invalid_conn_str = 'Endpoint=sb://{}.servicebus.windows.net/;SharedAccessKeyName=invalid;SharedAccessKey=invalid'.format( servicebus_namespace.name) mgmt_service = ServiceBusAdministrationClient.from_connection_string( invalid_conn_str) with pytest.raises(HttpResponseError): await async_pageable_to_list(mgmt_service.list_queues()) # fully_qualified_namespace = 'invalid.servicebus.windows.net' # mgmt_service = ServiceBusAdministrationClient( # fully_qualified_namespace, # credential=ServiceBusSharedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key) # ) # with pytest.raises(ServiceRequestError): # await async_pageable_to_list(mgmt_service.list_queues()) fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net' mgmt_service = ServiceBusAdministrationClient( fully_qualified_namespace, credential=ServiceBusSharedKeyCredential("invalid", "invalid")) with pytest.raises(HttpResponseError): await async_pageable_to_list(mgmt_service.list_queues())
async def test_async_mgmt_subscription_list( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = 'lkoqxc' subscription_name_1 = 'testsub1' subscription_name_2 = 'testsub2' await mgmt_service.create_topic(topic_name) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions) == 0 await mgmt_service.create_subscription(topic_name, subscription_name_1) await mgmt_service.create_subscription(topic_name, subscription_name_2) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions) == 2 assert subscriptions[0].name == subscription_name_1 assert subscriptions[1].name == subscription_name_2 await mgmt_service.delete_subscription(topic_name, subscription_name_1) await mgmt_service.delete_subscription(topic_name, subscription_name_2) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions) == 0 await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_subscription_get_runtime_properties_basic( self, servicebus_namespace_connection_string): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = 'dcvxqa' subscription_name = 'xvazzag' await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription(topic_name, subscription_name) sub_runtime_properties = await mgmt_service.get_subscription_runtime_properties( topic_name, subscription_name) assert sub_runtime_properties assert sub_runtime_properties.name == subscription_name assert sub_runtime_properties.created_at_utc is not None assert sub_runtime_properties.accessed_at_utc is not None assert sub_runtime_properties.updated_at_utc is not None assert sub_runtime_properties.total_message_count == 0 assert sub_runtime_properties.active_message_count == 0 assert sub_runtime_properties.dead_letter_message_count == 0 assert sub_runtime_properties.transfer_dead_letter_message_count == 0 assert sub_runtime_properties.transfer_message_count == 0 await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)
async def main(): async with ServiceBusAdministrationClient.from_connection_string( CONNECTION_STR) as servicebus_mgmt_client: await create_rule(servicebus_mgmt_client) await list_rules(servicebus_mgmt_client) await get_and_update_rule(servicebus_mgmt_client) await delete_rule(servicebus_mgmt_client)
async def test_async_mgmt_subscription_delete( self, servicebus_namespace_connection_string): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = 'test_topicgda' subscription_name_1 = 'test_sub1da' subscription_name_2 = 'test_sub2gcv' await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription(topic_name, subscription_name_1) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions) == 1 await mgmt_service.create_subscription(topic_name, subscription_name_2) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions) == 2 description = await mgmt_service.get_subscription( topic_name, subscription_name_1) await mgmt_service.delete_subscription(topic_name, description) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions ) == 1 and subscriptions[0].name == subscription_name_2 await mgmt_service.delete_subscription(topic_name, subscription_name_2) subscriptions = await async_pageable_to_list( mgmt_service.list_subscriptions(topic_name)) assert len(subscriptions) == 0 await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_subscription_create_with_forward_to(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "iweidkforward" subscription_name = "kdosakoforward" queue_name = "dkfthj" try: await mgmt_service.create_queue(queue_name) await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription( topic_name, subscription_name=subscription_name, forward_dead_lettered_messages_to=queue_name, forward_to=queue_name, ) subscription = await mgmt_service.get_subscription(topic_name, subscription_name) # Test forward_to (separately, as it changes auto_delete_on_idle when you enable it.) # Note: We endswith to avoid the fact that the servicebus_namespace_name is replacered locally but not in the properties bag, and still test this. assert subscription.forward_to.endswith(".servicebus.windows.net/{}".format(queue_name)) assert subscription.forward_dead_lettered_messages_to.endswith(".servicebus.windows.net/{}".format(queue_name)) finally: await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name) await mgmt_service.delete_queue(queue_name) mgmt_service.close()
async def test_async_mgmt_topic_update_invalid(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "dfjfj" try: topic_description = await mgmt_service.create_topic(topic_name) # handle a null update properly. with pytest.raises(TypeError): await mgmt_service.update_topic(None) # handle an invalid type update properly. with pytest.raises(TypeError): await mgmt_service.update_topic(Exception("test")) # change the name to a topic that doesn't exist; should fail. topic_description.name = "iewdm" with pytest.raises(HttpResponseError): await mgmt_service.update_topic(topic_description) topic_description.name = topic_name # change the name to a topic with an invalid name exist; should fail. topic_description.name = '' with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.update_topic(topic_description) topic_description.name = topic_name # change to a setting with an invalid value; should still fail. topic_description.duplicate_detection_history_time_window = datetime.timedelta(days=25) with pytest.raises(HttpResponseError): await mgmt_service.update_topic(topic_description) topic_description.duplicate_detection_history_time_window = datetime.timedelta(minutes=5) finally: await mgmt_service.delete_topic(topic_name)
async def test_mgmt_rule_async_update_dict_error( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "fjrui" subscription_name = "eqkovc" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") try: topic_description = await mgmt_service.create_topic(topic_name) subscription_description = await mgmt_service.create_subscription( topic_description.name, subscription_name) await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) # send in rule dict without non-name keyword args rule_description_only_name = {"name": topic_name} with pytest.raises(TypeError): await mgmt_service.update_rule(topic_description.name, subscription_description.name, rule_description_only_name) finally: await mgmt_service.delete_rule(topic_name, subscription_name, rule_name) await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)
async def test_mgmt_rule_async_update_dict_success(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "fjruid" subscription_name = "eqkovcd" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") try: topic_description = await mgmt_service.create_topic(topic_name) subscription_description = await mgmt_service.create_subscription(topic_description.name, subscription_name) await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name) assert type(rule_desc.filter) == SqlRuleFilter assert rule_desc.filter.sql_expression == "Priority = 'low'" correlation_fitler = CorrelationRuleFilter(correlation_id='testcid') sql_rule_action = SqlRuleAction(sql_expression="SET Priority = 'low'") rule_desc.filter = correlation_fitler rule_desc.action = sql_rule_action rule_desc_dict = dict(rule_desc) await mgmt_service.update_rule(topic_description.name, subscription_description.name, rule_desc_dict) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name) assert type(rule_desc.filter) == CorrelationRuleFilter assert rule_desc.filter.correlation_id == 'testcid' assert rule_desc.action.sql_expression == "SET Priority = 'low'" finally: await mgmt_service.delete_rule(topic_name, subscription_name, rule_name) await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_queue_list_basic( self, servicebus_namespace_connection_string, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_queues(mgmt_service) queues = await async_pageable_to_list(mgmt_service.list_queues()) assert len(queues) == 0 await mgmt_service.create_queue("test_queue") queues = await async_pageable_to_list(mgmt_service.list_queues()) assert len(queues) == 1 and queues[0].name == "test_queue" await mgmt_service.delete_queue("test_queue") queues = await async_pageable_to_list(mgmt_service.list_queues()) assert len(queues) == 0 fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net' mgmt_service = ServiceBusAdministrationClient( fully_qualified_namespace, credential=ServiceBusSharedKeyCredential( servicebus_namespace_key_name, servicebus_namespace_primary_key)) queues = await async_pageable_to_list(mgmt_service.list_queues()) assert len(queues) == 0 await mgmt_service.create_queue("test_queue") queues = await async_pageable_to_list(mgmt_service.list_queues()) assert len(queues) == 1 and queues[0].name == "test_queue" await mgmt_service.delete_queue("test_queue") queues = await async_pageable_to_list(mgmt_service.list_queues()) assert len(queues) == 0
async def test_async_mgmt_queue_list_runtime_properties_basic(self, servicebus_namespace_connection_string): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_queues(mgmt_service) queues = await async_pageable_to_list(mgmt_service.list_queues()) queues_infos = await async_pageable_to_list(mgmt_service.list_queues_runtime_properties()) assert len(queues) == len(queues_infos) == 0 await mgmt_service.create_queue("test_queue") queues = await async_pageable_to_list(mgmt_service.list_queues()) queues_infos = await async_pageable_to_list(mgmt_service.list_queues_runtime_properties()) assert len(queues) == 1 and len(queues_infos) == 1 assert queues[0].name == queues_infos[0].name == "test_queue" info = queues_infos[0] assert info.size_in_bytes == 0 assert info.created_at_utc is not None assert info.accessed_at_utc is not None assert info.updated_at_utc is not None assert info.total_message_count == 0 assert info.active_message_count == 0 assert info.dead_letter_message_count == 0 assert info.transfer_dead_letter_message_count == 0 assert info.transfer_message_count == 0 assert info.scheduled_message_count == 0 await mgmt_service.delete_queue("test_queue") queues_infos = await async_pageable_to_list(mgmt_service.list_queues_runtime_properties()) assert len(queues_infos) == 0
async def test_async_mgmt_topic_create_with_topic_description(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "iweidk" try: await mgmt_service.create_topic( topic_name=topic_name, auto_delete_on_idle=datetime.timedelta(minutes=10), default_message_time_to_live=datetime.timedelta(minutes=11), duplicate_detection_history_time_window=datetime.timedelta(minutes=12), enable_batched_operations=True, enable_express=True, enable_partitioning=True, max_size_in_megabytes=3072 ) topic = await mgmt_service.get_topic(topic_name) assert topic.name == topic_name assert topic.auto_delete_on_idle == datetime.timedelta(minutes=10) assert topic.default_message_time_to_live == datetime.timedelta(minutes=11) assert topic.duplicate_detection_history_time_window == datetime.timedelta(minutes=12) assert topic.enable_batched_operations assert topic.enable_express assert topic.enable_partitioning assert topic.max_size_in_megabytes % 3072 == 0 finally: await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_queue_create_with_queue_description(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_queues(mgmt_service) queue_name = "dkldf" await mgmt_service.create_queue(queue_name, auto_delete_on_idle=datetime.timedelta(minutes=10), dead_lettering_on_message_expiration=True, default_message_time_to_live=datetime.timedelta(minutes=11), duplicate_detection_history_time_window=datetime.timedelta(minutes=12), enable_batched_operations=True, enable_express=True, enable_partitioning=True, lock_duration=datetime.timedelta(seconds=13), max_delivery_count=14, max_size_in_megabytes=3072, #requires_duplicate_detection=True, requires_session=True ) try: queue = await mgmt_service.get_queue(queue_name) assert queue.name == queue_name assert queue.auto_delete_on_idle == datetime.timedelta(minutes=10) assert queue.dead_lettering_on_message_expiration == True assert queue.default_message_time_to_live == datetime.timedelta(minutes=11) assert queue.duplicate_detection_history_time_window == datetime.timedelta(minutes=12) assert queue.enable_batched_operations == True assert queue.enable_express == True assert queue.enable_partitioning == True assert queue.lock_duration == datetime.timedelta(seconds=13) assert queue.max_delivery_count == 14 assert queue.max_size_in_megabytes % 3072 == 0 #assert queue.requires_duplicate_detection == True assert queue.requires_session == True finally: await mgmt_service.delete_queue(queue_name)
async def main(): async with ServiceBusAdministrationClient.from_connection_string( CONNECTION_STR) as servicebus_mgmt_client: await create_subscription(servicebus_mgmt_client) await list_subscriptions(servicebus_mgmt_client) await get_and_update_subscription(servicebus_mgmt_client) await get_subscription_runtime_properties(servicebus_mgmt_client) await delete_subscription(servicebus_mgmt_client)
async def test_async_mgmt_queue_create_with_invalid_name(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.create_queue(Exception()) with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.create_queue('')
async def test_async_mgmt_namespace_get_properties( self, servicebus_namespace_connection_string, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) properties = await mgmt_service.get_namespace_properties() assert properties assert properties.messaging_sku == 'Standard'
async def test_async_mgmt_namespace_get_properties(self, servicebus_namespace_connection_string, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) properties = await mgmt_service.get_namespace_properties() assert properties assert properties.messaging_sku == 'Standard' # assert properties.name == servicebus_namespace.name # This is disabled pending investigation of why it isn't getting scrubbed despite expected scrubber use.
def __init__(self, arguments): super().__init__(arguments) connection_string = self.get_from_env( "AZURE_SERVICEBUS_CONNECTION_STRING") self.async_mgmt_client = ServiceBusAdministrationClient.from_connection_string( connection_string) self.sender = self.service_client.get_queue_sender(self.queue_name) self.async_sender = self.async_service_client.get_queue_sender( self.queue_name)
async def test_async_mgmt_queue_list_with_parameters( self, servicebus_namespace_connection_string): pytest.skip( "start_idx and max_count are currently removed, they might come back in the future." ) mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await run_test_async_mgmt_list_with_parameters( AsyncMgmtQueueListTestHelper(mgmt_service))
async def test_async_mgmt_topic_create_with_topic_description(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "iweidk" topic_name_2 = "dkozq" topic_name_3 = "famviq" try: await mgmt_service.create_topic( topic_name=topic_name, auto_delete_on_idle=datetime.timedelta(minutes=10), default_message_time_to_live=datetime.timedelta(minutes=11), duplicate_detection_history_time_window=datetime.timedelta(minutes=12), enable_batched_operations=True, enable_express=True, enable_partitioning=True, max_size_in_megabytes=3072 ) topic = await mgmt_service.get_topic(topic_name) assert topic.name == topic_name assert topic.auto_delete_on_idle == datetime.timedelta(minutes=10) assert topic.default_message_time_to_live == datetime.timedelta(minutes=11) assert topic.duplicate_detection_history_time_window == datetime.timedelta(minutes=12) assert topic.enable_batched_operations assert topic.enable_express assert topic.enable_partitioning assert topic.max_size_in_megabytes % 3072 == 0 await mgmt_service.create_topic( topic_name=topic_name_2, auto_delete_on_idle="PT10M", default_message_time_to_live="PT11M", duplicate_detection_history_time_window="PT12M", enable_batched_operations=True, enable_express=True, enable_partitioning=True, max_size_in_megabytes=3072 ) topic_2 = await mgmt_service.get_topic(topic_name_2) assert topic_2.name == topic_name_2 assert topic_2.auto_delete_on_idle == datetime.timedelta(minutes=10) assert topic_2.default_message_time_to_live == datetime.timedelta(minutes=11) assert topic_2.duplicate_detection_history_time_window == datetime.timedelta(minutes=12) assert topic_2.enable_batched_operations assert topic_2.enable_express assert topic_2.enable_partitioning assert topic_2.max_size_in_megabytes % 3072 == 0 with pytest.raises(HttpResponseError): await mgmt_service.create_topic( topic_name_3, max_message_size_in_kilobytes=1024 # basic/standard ties does not support ) finally: await mgmt_service.delete_topic(topic_name) await mgmt_service.delete_topic(topic_name_2)
async def test_async_mgmt_topic_create_duplicate(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "dqkodq" try: await mgmt_service.create_topic(topic_name) with pytest.raises(ResourceExistsError): await mgmt_service.create_topic(topic_name) finally: await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_queue_create_duplicate(self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) await clear_queues(mgmt_service) queue_name = "eriodk" await mgmt_service.create_queue(queue_name) try: with pytest.raises(ResourceExistsError): await mgmt_service.create_queue(queue_name) finally: await mgmt_service.delete_queue(queue_name)
async def test_async_mgmt_queue_get_runtime_properties_negative(self, servicebus_namespace_connection_string): mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string) with pytest.raises(TypeError): await mgmt_service.get_queue_runtime_properties(None) with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.get_queue_runtime_properties("") with pytest.raises(ResourceNotFoundError): await mgmt_service.get_queue_runtime_properties("non_existing_queue")
async def test_mgmt_topic_async_update_dict_success( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "fjruid" try: topic_description = await mgmt_service.create_topic(topic_name) topic_description_dict = dict(topic_description) # Try updating one setting. topic_description_dict[ "default_message_time_to_live"] = datetime.timedelta(minutes=2) await mgmt_service.update_topic(topic_description_dict) topic_description = await mgmt_service.get_topic(topic_name) assert topic_description.default_message_time_to_live == datetime.timedelta( minutes=2) # Now try updating all settings. topic_description_dict = dict(topic_description) topic_description_dict["auto_delete_on_idle"] = datetime.timedelta( minutes=10) topic_description_dict[ "default_message_time_to_live"] = datetime.timedelta( minutes=11) topic_description_dict[ "duplicate_detection_history_time_window"] = datetime.timedelta( minutes=12) topic_description_dict["enable_batched_operations"] = True topic_description_dict["enable_express"] = True # topic_description_dict["enable_partitioning"] = True # Cannot be changed after creation topic_description_dict["max_size_in_megabytes"] = 3072 # topic_description_dict["requires_duplicate_detection"] = True # Read only # topic_description_dict["requires_session"] = True # Cannot be changed after creation topic_description_dict["support_ordering"] = True await mgmt_service.update_topic(topic_description_dict) topic_description = await mgmt_service.get_topic(topic_name) assert topic_description.auto_delete_on_idle == datetime.timedelta( minutes=10) assert topic_description.default_message_time_to_live == datetime.timedelta( minutes=11) assert topic_description.duplicate_detection_history_time_window == datetime.timedelta( minutes=12) assert topic_description.enable_batched_operations == True assert topic_description.enable_express == True # assert topic_description.enable_partitioning == True assert topic_description.max_size_in_megabytes == 3072 # assert topic_description.requires_duplicate_detection == True # assert topic_description.requires_session == True assert topic_description.support_ordering == True finally: await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_rule_update_invalid( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "fjrui" subscription_name = "eqkovc" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") try: topic_description = await mgmt_service.create_topic(topic_name) subscription_description = await mgmt_service.create_subscription( topic_name, subscription_name) await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name) # handle a null update properly. with pytest.raises(TypeError): await mgmt_service.update_rule(topic_name, subscription_name, None) # handle an invalid type update properly. with pytest.raises(TypeError): await mgmt_service.update_rule(topic_name, subscription_name, Exception("test")) # change the name to a topic that doesn't exist; should fail. rule_desc.name = "iewdm" with pytest.raises(HttpResponseError): await mgmt_service.update_rule(topic_name, subscription_description.name, rule_desc) rule_desc.name = rule_name # change the name to a topic with an invalid name exist; should fail. rule_desc.name = '' with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.update_rule(topic_name, subscription_description.name, rule_desc) rule_desc.name = rule_name finally: await mgmt_service.delete_rule(topic_name, subscription_name, rule_name) await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)
async def test_async_mgmt_subscription_update_success( self, servicebus_namespace_connection_string, **kwargs): mgmt_service = ServiceBusAdministrationClient.from_connection_string( servicebus_namespace_connection_string) await clear_topics(mgmt_service) topic_name = "fjrui" subscription_name = "eqkovc" try: topic_description = await mgmt_service.create_topic(topic_name) subscription_description = await mgmt_service.create_subscription( topic_description, subscription_name) # Try updating one setting. subscription_description.lock_duration = datetime.timedelta( minutes=2) await mgmt_service.update_subscription(topic_description, subscription_description) subscription_description = await mgmt_service.get_subscription( topic_name, subscription_name) assert subscription_description.lock_duration == datetime.timedelta( minutes=2) # Now try updating all settings. subscription_description.auto_delete_on_idle = datetime.timedelta( minutes=10) subscription_description.dead_lettering_on_message_expiration = True subscription_description.default_message_time_to_live = datetime.timedelta( minutes=11) subscription_description.lock_duration = datetime.timedelta( seconds=12) subscription_description.max_delivery_count = 14 # topic_description.enable_partitioning = True # Cannot be changed after creation # topic_description.requires_session = True # Cannot be changed after creation await mgmt_service.update_subscription(topic_description, subscription_description) subscription_description = await mgmt_service.get_subscription( topic_description, subscription_name) assert subscription_description.auto_delete_on_idle == datetime.timedelta( minutes=10) assert subscription_description.dead_lettering_on_message_expiration == True assert subscription_description.default_message_time_to_live == datetime.timedelta( minutes=11) assert subscription_description.max_delivery_count == 14 assert subscription_description.lock_duration == datetime.timedelta( seconds=12) # assert topic_description.enable_partitioning == True # assert topic_description.requires_session == True finally: await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name)