1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
|
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import logging
import pytest
import datetime
import secrets
import base64
from azure.servicebus.aio.management import ServiceBusAdministrationClient
from azure.servicebus.management import TopicProperties, AccessRights, AuthorizationRule
from azure.servicebus.aio._base_handler_async import ServiceBusSharedKeyCredential
from azure.servicebus.management import ApiVersion
from utilities import get_logger
from azure.core.exceptions import HttpResponseError, ResourceExistsError
from devtools_testutils import AzureMgmtRecordedTestCase, CachedResourceGroupPreparer, get_credential
from devtools_testutils.aio import recorded_by_proxy_async
from sb_env_loader import ServiceBusPreparer
from mgmt_test_utilities_async import async_pageable_to_list, clear_topics
_logger = get_logger(logging.DEBUG)
class TestServiceBusAdministrationClientTopicAsync(AzureMgmtRecordedTestCase):
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_create_by_name(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
topic_name = "topic_testaddf"
try:
await mgmt_service.create_topic(topic_name)
topic = await mgmt_service.get_topic(topic_name)
assert topic.name == topic_name
assert topic.availability_status == "Available"
assert topic.status == "Active"
finally:
await mgmt_service.delete_topic(topic_name)
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_create_with_topic_description(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
topic_name = "iweidk"
topic_name_2 = "dkozq"
topic_name_3 = "famviq"
def generate_random_key():
key256 = secrets.token_bytes(32)
return base64.b64encode(key256).decode('utf-8')
auth_rule = AuthorizationRule(
type="SharedAccessAuthorizationRule",
key_name="test_key",
claim_type="SharedAccessKey",
claim_value="None",
rights=[AccessRights.MANAGE, AccessRights.LISTEN, AccessRights.SEND],
primary_key=generate_random_key(),
secondary_key=generate_random_key(),
)
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,
authorization_rules=[auth_rule],
)
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
assert topic.authorization_rules[0].key_name == "test_key"
assert len(topic.authorization_rules[0].rights) == 3
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)
@pytest.mark.skip("unblock after resolving Cannot upgrade to premium namespace.")
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_premium_create_with_topic_description(
self, servicebus_fully_qualified_namespace, **kwargs
):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
topic_name = "iweidk"
topic_name_2 = "dkozq"
topic_name_3 = "rekocd"
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,
max_size_in_megabytes=3072,
max_message_size_in_kilobytes=12345,
)
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.max_size_in_megabytes % 3072 == 0
assert topic.max_message_size_in_kilobytes == 12345
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,
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.max_size_in_megabytes % 3072 == 0
assert topic_2.max_message_size_in_kilobytes == 1024
with pytest.raises(HttpResponseError):
await mgmt_service.create_topic(topic_name=topic_name_3, max_message_size_in_kilobytes=1023)
with pytest.raises(HttpResponseError):
await mgmt_service.create_topic(topic_name=topic_name_3, max_message_size_in_kilobytes=102401)
topic_2.max_message_size_in_kilobytes = 54321
await mgmt_service.update_topic(topic_2)
topic_2_new = await mgmt_service.get_topic(topic_name_2)
assert topic_2_new.max_message_size_in_kilobytes == 54321
finally:
await mgmt_service.delete_topic(topic_name)
await mgmt_service.delete_topic(topic_name_2)
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_create_duplicate(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
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)
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_update_success(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
topic_name = "fjrui"
def generate_random_key():
key256 = secrets.token_bytes(32)
return base64.b64encode(key256).decode('utf-8')
auth_rule = AuthorizationRule(
type="SharedAccessAuthorizationRule",
key_name="test_key_listen",
claim_type="SharedAccessKey",
claim_value="None",
rights=[AccessRights.LISTEN],
primary_key=generate_random_key(),
secondary_key=generate_random_key(),
)
try:
topic_description = await mgmt_service.create_topic(topic_name)
# Try updating one setting.
topic_description.default_message_time_to_live = datetime.timedelta(minutes=2)
topic_description.authorization_rules = [auth_rule]
await mgmt_service.update_topic(topic_description)
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.auto_delete_on_idle = datetime.timedelta(minutes=10)
topic_description.default_message_time_to_live = datetime.timedelta(minutes=11)
topic_description.duplicate_detection_history_time_window = datetime.timedelta(minutes=12)
topic_description.enable_batched_operations = True
topic_description.enable_express = True
# topic_description.enable_partitioning = True # Cannot be changed after creation
topic_description.max_size_in_megabytes = 3072
# topic_description.requires_duplicate_detection = True # Read only
# topic_description.requires_session = True # Cannot be changed after creation
topic_description.support_ordering = True
assert topic_description.authorization_rules[0].key_name == "test_key_listen"
assert len(topic_description.authorization_rules[0].rights) == 1
await mgmt_service.update_topic(topic_description)
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
topic_description.auto_delete_on_idle = "PT10M1S"
topic_description.default_message_time_to_live = "PT11M2S"
topic_description.duplicate_detection_history_time_window = "PT12M3S"
await mgmt_service.update_topic(topic_description)
topic_description = await mgmt_service.get_topic(topic_name)
assert topic_description.auto_delete_on_idle == datetime.timedelta(minutes=10, seconds=1)
assert topic_description.default_message_time_to_live == datetime.timedelta(minutes=11, seconds=2)
assert topic_description.duplicate_detection_history_time_window == datetime.timedelta(
minutes=12, seconds=3
)
# updating all settings with keyword arguments.
await mgmt_service.update_topic(
topic_description,
auto_delete_on_idle=datetime.timedelta(minutes=14),
default_message_time_to_live=datetime.timedelta(minutes=15),
duplicate_detection_history_time_window=datetime.timedelta(minutes=16),
enable_batched_operations=False,
enable_express=False,
max_size_in_megabytes=2048,
support_ordering=False,
)
topic_description = await mgmt_service.get_topic(topic_name)
assert topic_description.auto_delete_on_idle == datetime.timedelta(minutes=14)
assert topic_description.default_message_time_to_live == datetime.timedelta(minutes=15)
assert topic_description.duplicate_detection_history_time_window == datetime.timedelta(minutes=16)
assert topic_description.enable_batched_operations == False
assert topic_description.enable_express == False
# assert topic_description.enable_partitioning == True
assert topic_description.max_size_in_megabytes == 2048
# assert topic_description.requires_duplicate_detection == True
# assert topic_description.requires_session == True
assert topic_description.support_ordering == False
finally:
await mgmt_service.delete_topic(topic_name)
await mgmt_service.close()
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_update_invalid(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
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(HttpResponseError):
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)
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_delete(self, servicebus_fully_qualified_namespace):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
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
await mgmt_service.create_topic("txt/.-_123")
topics = await async_pageable_to_list(mgmt_service.list_topics())
assert len(topics) == 2
description = await mgmt_service.get_topic("test_topic")
await mgmt_service.delete_topic(description.name)
topics = await async_pageable_to_list(mgmt_service.list_topics())
assert len(topics) == 1 and topics[0].name == "txt/.-_123"
description = await mgmt_service.get_topic("txt/.-_123")
await mgmt_service.delete_topic(description.name)
topics = await async_pageable_to_list(mgmt_service.list_topics())
assert len(topics) == 0
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_list(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
topics = await async_pageable_to_list(mgmt_service.list_topics())
assert len(topics) == 0
await mgmt_service.create_topic("test_topic_1")
await mgmt_service.create_topic("test_topic_2")
topics = await async_pageable_to_list(mgmt_service.list_topics())
assert len(topics) == 2
assert topics[0].name == "test_topic_1"
assert topics[1].name == "test_topic_2"
await mgmt_service.delete_topic("test_topic_1")
await mgmt_service.delete_topic("test_topic_2")
topics = await async_pageable_to_list(mgmt_service.list_topics())
assert len(topics) == 0
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_list_runtime_properties(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
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
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_get_runtime_properties_basic(self, servicebus_fully_qualified_namespace):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
await mgmt_service.create_topic("test_topic")
try:
topic_runtime_properties = await 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.subscription_count is 0
assert topic_runtime_properties.size_in_bytes == 0
assert topic_runtime_properties.scheduled_message_count == 0
finally:
await mgmt_service.delete_topic("test_topic")
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_mgmt_topic_async_update_dict_success(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
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
# updating all settings with keyword arguments.
await mgmt_service.update_topic(
dict(topic_description),
auto_delete_on_idle=datetime.timedelta(minutes=14),
default_message_time_to_live=datetime.timedelta(minutes=15),
duplicate_detection_history_time_window=datetime.timedelta(minutes=16),
enable_batched_operations=False,
enable_express=False,
max_size_in_megabytes=2048,
support_ordering=False,
)
topic_description = await mgmt_service.get_topic(topic_name)
assert topic_description.auto_delete_on_idle == datetime.timedelta(minutes=14)
assert topic_description.default_message_time_to_live == datetime.timedelta(minutes=15)
assert topic_description.duplicate_detection_history_time_window == datetime.timedelta(minutes=16)
assert topic_description.enable_batched_operations == False
assert topic_description.enable_express == False
# assert topic_description.enable_partitioning == True
assert topic_description.max_size_in_megabytes == 2048
# assert topic_description.requires_duplicate_detection == True
# assert topic_description.requires_session == True
assert topic_description.support_ordering == False
finally:
await mgmt_service.delete_topic(topic_name)
await mgmt_service.close()
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_mgmt_topic_async_update_dict_error(self, servicebus_fully_qualified_namespace, **kwargs):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace, credential=credential
)
await clear_topics(mgmt_service)
topic_name = "fjruid"
try:
topic_description = await 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):
await mgmt_service.update_topic(topic_description_only_name)
finally:
await mgmt_service.delete_topic(topic_name)
@ServiceBusPreparer()
@recorded_by_proxy_async
async def test_async_mgmt_topic_basic_v2017_04(
self, servicebus_connection_str, servicebus_fully_qualified_namespace, servicebus_sas_key, servicebus_sas_policy
):
credential = get_credential(is_async=True)
mgmt_service = ServiceBusAdministrationClient(
fully_qualified_namespace=servicebus_fully_qualified_namespace,
credential=credential,
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_fully_qualified_namespace
# mgmt_service = ServiceBusAdministrationClient(
# fully_qualified_namespace,
# credential=ServiceBusSharedKeyCredential(servicebus_sas_key, servicebus_sas_policy),
# 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)
|