def test_mgmt_topic_list_runtime_properties(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topics = list(mgmt_service.list_topics())
        topics_infos = list(mgmt_service.list_topics_runtime_properties())

        assert len(topics) == len(topics_infos) == 0

        mgmt_service.create_topic("test_topic")

        topics = list(mgmt_service.list_topics())
        topics_infos = 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

        mgmt_service.delete_topic("test_topic")
        topics_infos = list(mgmt_service.list_topics_runtime_properties())
        assert len(topics_infos) == 0
Ejemplo n.º 2
0
    def test_mgmt_rule_update_success(self,
                                      servicebus_namespace_connection_string,
                                      **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "fjrui"
        subscription_name = "eqkovc"
        rule_name = 'rule'
        sql_filter = SqlRuleFilter("Priority = 'low'")

        try:
            topic_description = mgmt_service.create_topic(topic_name)
            subscription_description = mgmt_service.create_subscription(
                topic_description.name, subscription_name)
            mgmt_service.create_rule(topic_name,
                                     subscription_name,
                                     rule_name,
                                     filter=sql_filter)

            rule_desc = 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
            mgmt_service.update_rule(topic_description.name,
                                     subscription_description.name, rule_desc)

            rule_desc = 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'"

            mgmt_service.update_rule(
                topic_description.name,
                subscription_description.name,
                rule_desc,
                filter=CorrelationRuleFilter(correlation_id='updatedcid'),
                action=None)

            rule_desc = mgmt_service.get_rule(topic_name, subscription_name,
                                              rule_name)
            assert type(rule_desc.filter) == CorrelationRuleFilter
            assert rule_desc.filter.correlation_id == 'updatedcid'
            assert rule_desc.action == None

        finally:
            mgmt_service.delete_rule(topic_name, subscription_name, rule_name)
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
            mgmt_service.close()
    def test_mgmt_topic_update_invalid(self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "dfjfj"
        try:
            topic_description = mgmt_service.create_topic(topic_name)

            # handle a null update properly.
            with pytest.raises(TypeError):
                mgmt_service.update_topic(None)

            # handle an invalid type update properly.
            with pytest.raises(TypeError):
                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):
                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):
                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):
                mgmt_service.update_topic(topic_description)
            topic_description.duplicate_detection_history_time_window = datetime.timedelta(minutes=5)
        finally:
            mgmt_service.delete_topic(topic_name)
    def test_mgmt_rule_update_dict_error(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "fjruid"
        subscription_name = "eqkovcd"
        rule_name = 'rule'
        sql_filter = SqlRuleFilter("Priority = 'low'")

        try:
            topic_description = mgmt_service.create_topic(topic_name)
            subscription_description = mgmt_service.create_subscription(
                topic_description.name, subscription_name)
            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):
                mgmt_service.update_rule(topic_description.name,
                                         subscription_description.name,
                                         rule_description_only_name)

        finally:
            mgmt_service.delete_rule(topic_name, subscription_name, rule_name)
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
    def test_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)
        clear_topics(mgmt_service)

        mgmt_service.create_topic("test_topic")
        topics = list(mgmt_service.list_topics())
        assert len(topics) == 1 and topics[0].name == "test_topic"
        topic = mgmt_service.get_topic("test_topic")
        assert topic.name == "test_topic"
        mgmt_service.delete_topic("test_topic")
        topics = list(mgmt_service.list_topics())
        assert len(topics) == 0

        with pytest.raises(HttpResponseError):
            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
        )

        mgmt_service.create_topic("test_topic")
        topics = list(mgmt_service.list_topics())
        assert len(topics) == 1 and topics[0].name == "test_topic"
        topic = mgmt_service.get_topic("test_topic")
        assert topic.name == "test_topic"
        mgmt_service.delete_topic("test_topic")
        topics = list(mgmt_service.list_topics())
        assert len(topics) == 0

        with pytest.raises(HttpResponseError):
            mgmt_service.create_topic("topic_can_not_be_created", max_message_size_in_kilobytes=1024)
Ejemplo n.º 6
0
 def test_mgmt_subscription_create_with_subscription_description(
         self, servicebus_namespace_connection_string, **kwargs):
     mgmt_service = ServiceBusAdministrationClient.from_connection_string(
         servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topic_name = "iweidk"
     subscription_name = "kdosako"
     try:
         mgmt_service.create_topic(topic_name)
         mgmt_service.create_subscription(
             topic_name,
             subscription_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 = 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:
         mgmt_service.delete_subscription(topic_name, subscription_name)
         mgmt_service.delete_topic(topic_name)
 def test_mgmt_rule_create_duplicate(self,
                                     servicebus_namespace_connection_string,
                                     **kwargs):
     mgmt_service = ServiceBusAdministrationClient.from_connection_string(
         servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topic_name = "dqkodq"
     subscription_name = 'kkaqo'
     rule_name = 'rule'
     sql_filter = SqlRuleFilter("Priority = 'low'")
     try:
         mgmt_service.create_topic(topic_name)
         mgmt_service.create_subscription(topic_name, subscription_name)
         mgmt_service.create_rule(topic_name,
                                  subscription_name,
                                  rule_name,
                                  filter=sql_filter)
         with pytest.raises(ResourceExistsError):
             mgmt_service.create_rule(topic_name,
                                      subscription_name,
                                      rule_name,
                                      filter=sql_filter)
     finally:
         mgmt_service.delete_rule(topic_name, subscription_name, rule_name)
         mgmt_service.delete_subscription(topic_name, subscription_name)
         mgmt_service.delete_topic(topic_name)
Ejemplo n.º 8
0
    def test_mgmt_subscription_get_runtime_properties_basic(
            self, servicebus_namespace_connection_string):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = 'dcvxqa'
        subscription_name = 'xvazzag'

        mgmt_service.create_topic(topic_name)
        mgmt_service.create_subscription(topic_name, subscription_name)
        sub_runtime_properties = 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.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

        mgmt_service.delete_subscription(topic_name, subscription_name)
        mgmt_service.delete_topic(topic_name)
Ejemplo n.º 9
0
    def test_mgmt_subscription_delete(self,
                                      servicebus_namespace_connection_string):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = 'test_topicgda'
        subscription_name_1 = 'test_sub1da'
        subscription_name_2 = 'test_sub2gcv'
        mgmt_service.create_topic(topic_name)

        mgmt_service.create_subscription(topic_name, subscription_name_1)
        subscriptions = list(mgmt_service.list_subscriptions(topic_name))
        assert len(subscriptions) == 1

        mgmt_service.create_subscription(topic_name, subscription_name_2)
        subscriptions = list(mgmt_service.list_subscriptions(topic_name))
        assert len(subscriptions) == 2

        description = mgmt_service.get_subscription(topic_name,
                                                    subscription_name_1)
        mgmt_service.delete_subscription(topic_name, description.name)

        subscriptions = list(mgmt_service.list_subscriptions(topic_name))
        assert len(subscriptions
                   ) == 1 and subscriptions[0].name == subscription_name_2

        mgmt_service.delete_subscription(topic_name, subscription_name_2)

        subscriptions = list(mgmt_service.list_subscriptions(topic_name))
        assert len(subscriptions) == 0
        mgmt_service.delete_topic(topic_name)
Ejemplo n.º 10
0
    def test_mgmt_subscription_create_with_forward_to(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "iweidkforward"
        subscription_name = "kdosakoforward"
        queue_name = "dkfthj"
        try:
            mgmt_service.create_queue(queue_name)
            mgmt_service.create_topic(topic_name)
            mgmt_service.create_subscription(
                topic_name,
                subscription_name=subscription_name,
                forward_dead_lettered_messages_to=queue_name,
                forward_to=queue_name,
            )
            subscription = 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:
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
            mgmt_service.delete_queue(queue_name)
 def test_mgmt_topic_create_with_topic_description(
         self, servicebus_namespace_connection_string, **kwargs):
     mgmt_service = ServiceBusAdministrationClient.from_connection_string(
         servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topic_name = "iweidk"
     try:
         mgmt_service.create_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 = 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:
         mgmt_service.delete_topic(topic_name)
Ejemplo n.º 12
0
    def test_mgmt_rule_list_and_delete(self,
                                       servicebus_namespace_connection_string):
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "topic_testaddf"
        subscription_name = "sub_testkkk"
        rule_name_1 = 'test_rule_1'
        rule_name_2 = 'test_rule_2'
        rule_name_3 = 'test_rule_3'

        sql_filter_1 = SqlRuleFilter("Priority = 'low'")
        sql_filter_2 = SqlRuleFilter("Priority = 'middle'")
        sql_filter_3 = SqlRuleFilter("Priority = 'high'")
        rule_1 = RuleDescription(name=rule_name_1, filter=sql_filter_1)
        rule_2 = RuleDescription(name=rule_name_2, filter=sql_filter_2)
        rule_3 = RuleDescription(name=rule_name_3, filter=sql_filter_3)

        try:
            mgmt_service.create_topic(topic_name)
            mgmt_service.create_subscription(topic_name, subscription_name)

            rules = list(mgmt_service.list_rules(topic_name,
                                                 subscription_name))
            assert len(rules) == 1  # by default there is a True filter

            mgmt_service.create_rule(topic_name, subscription_name, rule_1)
            mgmt_service.create_rule(topic_name, subscription_name, rule_2)
            mgmt_service.create_rule(topic_name, subscription_name, rule_3)

            rules = list(mgmt_service.list_rules(topic_name,
                                                 subscription_name))
            assert len(rules) == 3 + 1

            mgmt_service.delete_rule(topic_name, subscription_name,
                                     rule_name_2)
            rules = list(mgmt_service.list_rules(topic_name,
                                                 subscription_name))
            assert len(rules) == 2 + 1
            assert rules[0].name == "$Default"
            assert rules[1].name == rule_name_1
            assert type(rules[1].filter) == SqlRuleFilter
            assert rules[1].filter.sql_expression == "Priority = 'low'"
            assert rules[2].name == rule_name_3
            assert type(rules[2].filter) == SqlRuleFilter
            assert rules[2].filter.sql_expression == "Priority = 'high'"

            mgmt_service.delete_rule(topic_name, subscription_name,
                                     rule_name_1)
            mgmt_service.delete_rule(topic_name, subscription_name,
                                     rule_name_3)

            rules = list(mgmt_service.list_rules(topic_name,
                                                 subscription_name))
            assert len(rules) == 1

        finally:
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
    def test_mgmt_topic_create_with_topic_description(self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "iweidk"
        topic_name_2 = "djsadq"
        topic_name_3 = "famviq"

        try:
            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 = 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

            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 = 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):
                mgmt_service.create_topic(
                    topic_name_3,
                    max_message_size_in_kilobytes=1024  # basic/standard ties does not support
                )

        finally:
            mgmt_service.delete_topic(topic_name)
            mgmt_service.delete_topic(topic_name_2)
 def test_mgmt_topic_create_duplicate(self, servicebus_namespace_connection_string, **kwargs):
     mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topic_name = "dqkodq"
     try:
         mgmt_service.create_topic(topic_name)
         with pytest.raises(ResourceExistsError):
             mgmt_service.create_topic(topic_name)
     finally:
         mgmt_service.delete_topic(topic_name)
    def test_mgmt_topic_update_dict_success(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "fjruid"

        try:
            topic_description = 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)
            mgmt_service.update_topic(topic_description_dict)
            topic_description = 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

            mgmt_service.update_topic(topic_description_dict)
            topic_description = 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:
            mgmt_service.delete_topic(topic_name)
 def test_mgmt_topic_update_dict_error(self, servicebus_namespace_connection_string, **kwargs):
     mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topic_name = "dfjdfj"
     try:
         topic_description = mgmt_service.create_topic(topic_name)
         # send in topic dict without non-name keyword args
         topic_description_only_name = {"name": topic_name}
         with pytest.raises(TypeError):
             mgmt_service.update_topic(topic_description_only_name)
     finally:
         mgmt_service.delete_topic(topic_name)
Ejemplo n.º 17
0
    def test_mgmt_subscription_update_success(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "fjrui"
        subscription_name = "eqkovc"

        try:
            topic_description = mgmt_service.create_topic(topic_name)
            subscription_description = mgmt_service.create_subscription(
                topic_description, subscription_name)

            # Try updating one setting.
            subscription_description.lock_duration = datetime.timedelta(
                minutes=2)
            mgmt_service.update_subscription(topic_description,
                                             subscription_description)
            subscription_description = 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

            mgmt_service.update_subscription(topic_description,
                                             subscription_description)
            subscription_description = 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:
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
    def test_mgmt_rule_update_invalid(self,
                                      servicebus_namespace_connection_string,
                                      **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "fjrui"
        subscription_name = "eqkovc"
        rule_name = 'rule'
        sql_filter = SqlRuleFilter("Priority = 'low'")

        try:
            topic_description = mgmt_service.create_topic(topic_name)
            subscription_description = mgmt_service.create_subscription(
                topic_name, subscription_name)
            mgmt_service.create_rule(topic_name,
                                     subscription_name,
                                     rule_name,
                                     filter=sql_filter)

            rule_desc = mgmt_service.get_rule(topic_name, subscription_name,
                                              rule_name)

            # handle a null update properly.
            with pytest.raises(AttributeError):
                mgmt_service.update_rule(topic_name, subscription_name, None)

            # handle an invalid type update properly.
            with pytest.raises(AttributeError):
                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):
                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):
                mgmt_service.update_rule(topic_name,
                                         subscription_description.name,
                                         rule_desc)
            rule_desc.name = rule_name

        finally:
            mgmt_service.delete_rule(topic_name, subscription_name, rule_name)
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
Ejemplo n.º 19
0
 def test_mgmt_subscription_create_duplicate(self, servicebus_namespace_connection_string, **kwargs):
     mgmt_service = ServiceBusManagementClient.from_connection_string(servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topic_name = "dqkodq"
     subscription_name = 'kkaqo'
     try:
         mgmt_service.create_topic(topic_name)
         mgmt_service.create_subscription(topic_name, subscription_name)
         with pytest.raises(ResourceExistsError):
             mgmt_service.create_subscription(topic_name, subscription_name)
     finally:
         mgmt_service.delete_subscription(topic_name, subscription_name)
         mgmt_service.delete_topic(topic_name)
    def test_mgmt_topic_create_by_name(self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "topic_testaddf"

        try:
            mgmt_service.create_topic(topic_name)
            topic = mgmt_service.get_topic(topic_name)
            assert topic.name == topic_name
            assert topic.availability_status == 'Available'
            assert topic.status == 'Active'
        finally:
            mgmt_service.delete_topic(topic_name)
Ejemplo n.º 21
0
    def test_mgmt_subscription_update_dict_success(self, servicebus_namespace_connection_string, servicebus_namespace, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "fjruid"
        subscription_name = "eqkovcd"

        try:
            topic_description = mgmt_service.create_topic(topic_name)
            subscription_description = mgmt_service.create_subscription(topic_description.name, subscription_name)
            subscription_description_dict = dict(subscription_description)

            # Try updating one setting.
            subscription_description_dict["lock_duration"] = datetime.timedelta(minutes=2)
            mgmt_service.update_subscription(topic_description.name, subscription_description_dict)
            subscription_description = mgmt_service.get_subscription(topic_name, subscription_name)
            assert subscription_description.lock_duration == datetime.timedelta(minutes=2)

            # Now try updating all settings.
            subscription_description_dict = dict(subscription_description)
            subscription_description_dict["auto_delete_on_idle"] = datetime.timedelta(minutes=10)
            subscription_description_dict["dead_lettering_on_message_expiration"] = True
            subscription_description_dict["default_message_time_to_live"] = datetime.timedelta(minutes=11)
            subscription_description_dict["lock_duration"] = datetime.timedelta(seconds=12)
            subscription_description_dict["max_delivery_count"] = 14
            # topic_description.enable_partitioning = True # Cannot be changed after creation
            # topic_description.requires_session = True # Cannot be changed after creation

            mgmt_service.update_subscription(topic_description.name, subscription_description_dict)
            subscription_description = mgmt_service.get_subscription(topic_description.name, 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, test forward_to (separately, as it changes auto_delete_on_idle when you enable it.)
            subscription_description_dict = dict(subscription_description)
            subscription_description_dict["forward_to"] = "sb://{}.servicebus.windows.net/{}".format(servicebus_namespace.name, topic_name)
            subscription_description_dict["forward_dead_lettered_messages_to"] = "sb://{}.servicebus.windows.net/{}".format(servicebus_namespace.name, topic_name)
            mgmt_service.update_subscription(topic_description.name, subscription_description_dict)
            subscription_description = mgmt_service.get_subscription(topic_description.name, subscription_name)
            # 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_description.forward_to.endswith(".servicebus.windows.net/{}".format(topic_name))
            assert subscription_description.forward_dead_lettered_messages_to.endswith(".servicebus.windows.net/{}".format(topic_name))

        finally:
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
 def test_mgmt_topic_list(self, servicebus_namespace_connection_string, **kwargs):
     mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
     clear_topics(mgmt_service)
     topics = list(mgmt_service.list_topics())
     assert len(topics) == 0
     mgmt_service.create_topic("test_topic_1")
     mgmt_service.create_topic("test_topic_2")
     topics = list(mgmt_service.list_topics())
     assert len(topics) == 2
     assert topics[0].name == "test_topic_1"
     assert topics[1].name == "test_topic_2"
     mgmt_service.delete_topic("test_topic_1")
     mgmt_service.delete_topic("test_topic_2")
     topics = list(mgmt_service.list_topics())
     assert len(topics) == 0
    def test_mgmt_topic_get_runtime_properties_basic(self, servicebus_namespace_connection_string):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        mgmt_service.create_topic("test_topic")
        topic_runtime_properties = mgmt_service.get_topic_runtime_properties("test_topic")

        assert topic_runtime_properties
        assert topic_runtime_properties.name == "test_topic"
        assert topic_runtime_properties.created_at_utc is not None
        assert topic_runtime_properties.accessed_at_utc is not None
        assert topic_runtime_properties.updated_at_utc is not None
        assert topic_runtime_properties.size_in_bytes == 0
        assert topic_runtime_properties.subscription_count is 0
        assert topic_runtime_properties.scheduled_message_count == 0
        mgmt_service.delete_topic("test_topic")
Ejemplo n.º 24
0
    def test_mgmt_subscription_create_by_name(self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusManagementClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "topic_testaddf"
        subscription_name = "sub_testkkk"

        try:
            mgmt_service.create_topic(topic_name)
            mgmt_service.create_subscription(topic_name, subscription_name)
            subscription = mgmt_service.get_subscription(topic_name, subscription_name)
            assert subscription.name == subscription_name
            assert subscription.entity_availability_status == 'Available'
            assert subscription.status == 'Active'
        finally:
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
Ejemplo n.º 25
0
    def test_mgmt_topic_get_runtime_info_basic(
            self, servicebus_namespace_connection_string):
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        mgmt_service.create_topic("test_topic")
        topic_runtime_info = mgmt_service.get_topic_runtime_info("test_topic")

        assert topic_runtime_info
        assert topic_runtime_info.name == "test_topic"
        assert topic_runtime_info.created_at is not None
        assert topic_runtime_info.accessed_at is not None
        assert topic_runtime_info.updated_at is not None
        assert topic_runtime_info.size_in_bytes == 0
        assert topic_runtime_info.subscription_count is 0
        assert topic_runtime_info.scheduled_message_count == 0
        mgmt_service.delete_topic("test_topic")
Ejemplo n.º 26
0
    def test_mgmt_subscription_update_invalid(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = "dfjfj"
        subscription_name = "kwqxc"
        try:
            topic_description = mgmt_service.create_topic(topic_name)
            subscription_description = mgmt_service.create_subscription(
                topic_name, subscription_name)

            # handle a null update properly.
            with pytest.raises(AttributeError):
                mgmt_service.update_subscription(topic_name, None)

            # handle an invalid type update properly.
            with pytest.raises(AttributeError):
                mgmt_service.update_subscription(topic_name, Exception("test"))

            # change the name to a topic that doesn't exist; should fail.
            subscription_description.name = "iewdm"
            with pytest.raises(HttpResponseError):
                mgmt_service.update_subscription(topic_name,
                                                 subscription_description)
            subscription_description.name = subscription_name

            # change the name to a topic with an invalid name exist; should fail.
            subscription_description.name = ''
            with pytest.raises(msrest.exceptions.ValidationError):
                mgmt_service.update_subscription(topic_name,
                                                 subscription_description)
            subscription_description.name = topic_name

            # change to a setting with an invalid value; should still fail.
            subscription_description.lock_duration = datetime.timedelta(
                days=25)
            with pytest.raises(HttpResponseError):
                mgmt_service.update_subscription(topic_name,
                                                 subscription_description)
            subscription_description.lock_duration = datetime.timedelta(
                minutes=5)
        finally:
            mgmt_service.delete_subscription(topic_name, subscription_name)
            mgmt_service.delete_topic(topic_name)
Ejemplo n.º 27
0
    def test_mgmt_subscription_list_runtime_info(
            self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = 'dkoamv'
        subscription_name = 'cxqplc'
        mgmt_service.create_topic(topic_name)

        subs = list(mgmt_service.list_subscriptions(topic_name))
        subs_infos = list(
            mgmt_service.list_subscriptions_runtime_info(topic_name))

        assert len(subs) == len(subs_infos) == 0

        mgmt_service.create_subscription(topic_name, subscription_name)

        subs = list(mgmt_service.list_subscriptions(topic_name))
        subs_infos = list(
            mgmt_service.list_subscriptions_runtime_info(topic_name))

        assert len(subs) == 1 and len(subs_infos) == 1

        assert subs[0].name == subs_infos[0].name == subscription_name

        info = subs_infos[0]

        assert info.accessed_at is not None
        assert info.updated_at is not None

        assert info.message_count_details
        assert info.message_count_details.active_message_count == 0
        assert info.message_count_details.dead_letter_message_count == 0
        assert info.message_count_details.transfer_dead_letter_message_count == 0
        assert info.message_count_details.transfer_message_count == 0
        assert info.message_count_details.scheduled_message_count == 0

        mgmt_service.delete_subscription(topic_name, subscription_name)
        subs_infos = list(
            mgmt_service.list_subscriptions_runtime_info(topic_name))
        assert len(subs_infos) == 0

        mgmt_service.delete_topic(topic_name)
Ejemplo n.º 28
0
    def test_mgmt_subscription_list(self, servicebus_namespace_connection_string, **kwargs):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = 'lkoqxc'
        subscription_name_1 = 'testsub1'
        subscription_name_2 = 'testsub2'

        mgmt_service.create_topic(topic_name)
        subscriptions = list(mgmt_service.list_subscriptions(topic_name))
        assert len(subscriptions) == 0
        mgmt_service.create_subscription(topic_name, subscription_name_1)
        mgmt_service.create_subscription(topic_name, subscription_name_2)
        subscriptions = 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
        mgmt_service.delete_subscription(topic_name, subscription_name_1)
        mgmt_service.delete_subscription(topic_name, subscription_name_2)
        subscriptions = list(mgmt_service.list_subscriptions(topic_name))
        assert len(subscriptions) == 0
        mgmt_service.delete_topic(topic_name)
    def test_mgmt_topic_delete(self, servicebus_namespace_connection_string):
        mgmt_service = ServiceBusAdministrationClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        mgmt_service.create_topic('test_topic')
        topics = list(mgmt_service.list_topics())
        assert len(topics) == 1

        mgmt_service.create_topic('txt/.-_123')
        topics = list(mgmt_service.list_topics())
        assert len(topics) == 2

        description = mgmt_service.get_topic('test_topic')
        mgmt_service.delete_topic(description.name)

        topics = list(mgmt_service.list_topics())
        assert len(topics) == 1 and topics[0].name == 'txt/.-_123'

        description = mgmt_service.get_topic('txt/.-_123')
        mgmt_service.delete_topic(description.name)

        topics = list(mgmt_service.list_topics())
        assert len(topics) == 0
Ejemplo n.º 30
0
    def test_mgmt_subscription_get_runtime_info_basic(self, servicebus_namespace_connection_string):
        mgmt_service = ServiceBusManagementClient.from_connection_string(servicebus_namespace_connection_string)
        clear_topics(mgmt_service)
        topic_name = 'dcvxqa'
        subscription_name = 'xvazzag'

        mgmt_service.create_topic(topic_name)
        mgmt_service.create_subscription(topic_name, subscription_name)
        sub_runtime_info = mgmt_service.get_subscription_runtime_info(topic_name, subscription_name)

        assert sub_runtime_info
        assert sub_runtime_info.name == subscription_name
        assert sub_runtime_info.created_at is not None
        assert sub_runtime_info.accessed_at is not None
        assert sub_runtime_info.updated_at is not None

        assert sub_runtime_info.active_message_count == 0
        assert sub_runtime_info.dead_letter_message_count == 0
        assert sub_runtime_info.transfer_dead_letter_message_count == 0
        assert sub_runtime_info.transfer_message_count == 0

        mgmt_service.delete_subscription(topic_name, subscription_name)
        mgmt_service.delete_topic(topic_name)