Skip to content

Commit

Permalink
update servicebus endpoint suffix in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swathipil committed Mar 10, 2023
1 parent cd3cb9b commit 7007e5f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
CachedServiceBusQueuePreparer,
CachedServiceBusTopicPreparer,
CachedServiceBusSubscriptionPreparer,
CachedServiceBusResourceGroupPreparer
CachedServiceBusResourceGroupPreparer,
SERVICEBUS_ENDPOINT_SUFFIX
)
from utilities import get_logger

Expand All @@ -45,7 +46,7 @@ class ServiceBusClientAsyncTests(AzureMgmtTestCase):
@CachedServiceBusQueuePreparer(name_prefix='servicebustest', dead_lettering_on_message_expiration=True)
async def test_sb_client_bad_credentials_async(self, servicebus_namespace, servicebus_queue, **kwargs):
client = ServiceBusClient(
fully_qualified_namespace=servicebus_namespace.name + '.servicebus.windows.net',
fully_qualified_namespace=f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}",
credential=ServiceBusSharedKeyCredential('invalid', 'invalid'),
logging_enable=False)
async with client:
Expand All @@ -59,7 +60,7 @@ async def test_sb_client_bad_credentials_async(self, servicebus_namespace, servi
async def test_sb_client_bad_namespace_async(self, **kwargs):

client = ServiceBusClient(
fully_qualified_namespace='invalid.servicebus.windows.net',
fully_qualified_namespace=f'invalid.{SERVICEBUS_ENDPOINT_SUFFIX}',
credential=ServiceBusSharedKeyCredential('invalid', 'invalid'),
logging_enable=False)
async with client:
Expand All @@ -73,8 +74,8 @@ async def test_sb_client_bad_namespace_async(self, **kwargs):
@CachedServiceBusResourceGroupPreparer(name_prefix='servicebustest')
@CachedServiceBusNamespacePreparer(name_prefix='servicebustest')
async def test_sb_client_bad_entity_async(self):
fake_str = "Endpoint=sb://mock.servicebus.windows.net/;" \
"SharedAccessKeyName=mock;SharedAccessKey=mock;EntityPath=mockentity"
fake_str = f"Endpoint=sb://mock.{SERVICEBUS_ENDPOINT_SUFFIX}/;" \
f"SharedAccessKeyName=mock;SharedAccessKey=mock;EntityPath=mockentity"
fake_client = ServiceBusClient.from_connection_string(fake_str)

with pytest.raises(ValueError):
Expand All @@ -94,8 +95,8 @@ async def test_sb_client_bad_entity_async(self):
fake_client.get_topic_sender('mockentity')
fake_client.get_subscription_receiver('mockentity', 'subscription')

fake_str = "Endpoint=sb://mock.servicebus.windows.net/;" \
"SharedAccessKeyName=mock;SharedAccessKey=mock"
fake_str = f"Endpoint=sb://mock.{SERVICEBUS_ENDPOINT_SUFFIX}/;" \
f"SharedAccessKeyName=mock;SharedAccessKey=mock"
fake_client = ServiceBusClient.from_connection_string(fake_str)
fake_client.get_queue_sender('queue')
fake_client.get_queue_receiver('queue')
Expand Down Expand Up @@ -302,7 +303,7 @@ async def test_client_sas_credential_async(self,
**kwargs):
# This should "just work" to validate known-good.
credential = ServiceBusSharedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key)
hostname = "{}.servicebus.windows.net".format(servicebus_namespace.name)
hostname = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"
auth_uri = "sb://{}/{}".format(hostname, servicebus_queue.name)
token = (await credential.get_token(auth_uri)).token

Expand Down Expand Up @@ -330,24 +331,23 @@ async def test_client_credential_async(self,
**kwargs):
# This should "just work" to validate known-good.
credential = ServiceBusSharedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key)
hostname = "{}.servicebus.windows.net".format(servicebus_namespace.name)
hostname = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"

client = ServiceBusClient(hostname, credential)
async with client:
assert len(client._handlers) == 0
async with client.get_queue_sender(servicebus_queue.name) as sender:
await sender.send_messages(ServiceBusMessage("foo"))

hostname = "sb://{}.servicebus.windows.net".format(servicebus_namespace.name)
hostname = f"sb://{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"

client = ServiceBusClient(hostname, credential)
async with client:
assert len(client._handlers) == 0
async with client.get_queue_sender(servicebus_queue.name) as sender:
await sender.send_messages(ServiceBusMessage("foo"))

hostname = "https://{}.servicebus.windows.net \
".format(servicebus_namespace.name)
hostname = f"https://{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"

client = ServiceBusClient(hostname, credential)
async with client:
Expand All @@ -370,7 +370,7 @@ async def test_client_azure_sas_credential_async(self,
**kwargs):
# This should "just work" to validate known-good.
credential = ServiceBusSharedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key)
hostname = "{}.servicebus.windows.net".format(servicebus_namespace.name)
hostname = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"
auth_uri = "sb://{}/{}".format(hostname, servicebus_queue.name)
token = (await credential.get_token(auth_uri)).token.decode()

Expand All @@ -395,7 +395,7 @@ async def test_client_named_key_credential_async(self,
servicebus_namespace_primary_key,
servicebus_namespace_connection_string,
**kwargs):
hostname = "{}.servicebus.windows.net".format(servicebus_namespace.name)
hostname = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"
credential = AzureNamedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key)

client = ServiceBusClient(hostname, credential)
Expand Down Expand Up @@ -457,7 +457,7 @@ async def test_backoff_fixed_retry(self):
assert sleep_time_fixed < backoff * (2 ** 1)

async def test_custom_client_id_queue_sender_async(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
queue_name = "queue_name"
custom_id = "my_custom_id"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
Expand All @@ -467,7 +467,7 @@ async def test_custom_client_id_queue_sender_async(self, **kwargs):
assert queue_sender.client_identifier == custom_id

async def test_default_client_id_queue_sender(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
queue_name = "queue_name"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
async with servicebus_client:
Expand All @@ -476,7 +476,7 @@ async def test_default_client_id_queue_sender(self, **kwargs):
assert "SBSender" in queue_sender.client_identifier

async def test_custom_client_id_queue_receiver(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
queue_name = "queue_name"
custom_id = "my_custom_id"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
Expand All @@ -486,7 +486,7 @@ async def test_custom_client_id_queue_receiver(self, **kwargs):
assert queue_receiver.client_identifier == custom_id

async def test_default_client_id_queue_receiver(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
queue_name = "queue_name"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
async with servicebus_client:
Expand All @@ -495,7 +495,7 @@ async def test_default_client_id_queue_receiver(self, **kwargs):
assert "SBReceiver" in queue_receiver.client_identifier

async def test_custom_client_id_topic_sender(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
custom_id = "my_custom_id"
topic_name = "topic_name"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
Expand All @@ -505,7 +505,7 @@ async def test_custom_client_id_topic_sender(self, **kwargs):
assert topic_sender.client_identifier == custom_id

async def test_default_client_id_topic_sender(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
topic_name = "topic_name"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
async with servicebus_client:
Expand All @@ -514,7 +514,7 @@ async def test_default_client_id_topic_sender(self, **kwargs):
assert "SBSender" in topic_sender.client_identifier

async def test_default_client_id_subscription_receiver(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
topic_name = "topic_name"
sub_name = "sub_name"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=servicebus_connection_str)
Expand All @@ -524,7 +524,7 @@ async def test_default_client_id_subscription_receiver(self, **kwargs):
assert "SBReceiver" in subscription_receiver.client_identifier

async def test_custom_client_id_subscription_receiver(self, **kwargs):
servicebus_connection_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
servicebus_connection_str = f'Endpoint=sb://resourcename.{SERVICEBUS_ENDPOINT_SUFFIX}/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;'
custom_id = "my_custom_id"
topic_name = "topic_name"
sub_name = "sub_name"
Expand All @@ -546,7 +546,7 @@ async def test_connection_verify_exception_async(self,
servicebus_namespace_primary_key,
servicebus_namespace_connection_string,
**kwargs):
hostname = "{}.servicebus.windows.net".format(servicebus_namespace.name)
hostname = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"
credential = AzureNamedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key)

client = ServiceBusClient(hostname, credential, connection_verify="cacert.pem")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
CachedServiceBusSubscriptionPreparer,
ServiceBusTopicPreparer,
ServiceBusSubscriptionPreparer,
CachedServiceBusResourceGroupPreparer
CachedServiceBusResourceGroupPreparer,
SERVICEBUS_ENDPOINT_SUFFIX
)
from utilities import get_logger, print_message

Expand Down Expand Up @@ -82,7 +83,7 @@ async def test_subscription_by_subscription_client_conn_str_receive_basic(self,
@ServiceBusTopicPreparer(name_prefix='servicebustest')
@ServiceBusSubscriptionPreparer(name_prefix='servicebustest')
async def test_subscription_by_sas_token_credential_conn_str_send_basic(self, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key, servicebus_topic, servicebus_subscription, **kwargs):
fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
fully_qualified_namespace = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"
async with ServiceBusClient(
fully_qualified_namespace=fully_qualified_namespace,
credential=ServiceBusSharedKeyCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
ServiceBusTopicPreparer,
CachedServiceBusNamespacePreparer,
CachedServiceBusTopicPreparer,
CachedServiceBusResourceGroupPreparer
CachedServiceBusResourceGroupPreparer,
SERVICEBUS_ENDPOINT_SUFFIX
)
from utilities import get_logger, print_message

Expand Down Expand Up @@ -53,7 +54,7 @@ async def test_topic_by_servicebus_client_conn_str_send_basic(self, servicebus_n
@CachedServiceBusNamespacePreparer(name_prefix='servicebustest')
@CachedServiceBusTopicPreparer(name_prefix='servicebustest')
async def test_topic_by_sas_token_credential_conn_str_send_basic(self, servicebus_namespace, servicebus_namespace_key_name, servicebus_namespace_primary_key, servicebus_topic, **kwargs):
fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
fully_qualified_namespace = f"{servicebus_namespace.name}.{SERVICEBUS_ENDPOINT_SUFFIX}"
async with ServiceBusClient(
fully_qualified_namespace=fully_qualified_namespace,
credential=ServiceBusSharedKeyCredential(
Expand Down
Loading

0 comments on commit 7007e5f

Please sign in to comment.