-
Notifications
You must be signed in to change notification settings - Fork 3.2k
CPM Python Package Release failure fix #34893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sdk/communication/azure-communication-messages/tests/_decorators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| import os | ||
| from typing import Callable, Any | ||
|
|
||
| from devtools_testutils import is_live, is_live_and_not_recording, trim_kwargs_from_test_function | ||
| from azure.communication.messages._shared.utils import parse_connection_str | ||
|
|
||
| class MessagesPreparers(object): | ||
|
|
||
| @staticmethod | ||
| def messages_test_decorator(func: Callable[[], object], **kwargs: Any): | ||
| def wrapper(self, *args, **kwargs): | ||
| if is_live() or is_live_and_not_recording(): | ||
| self.connection_string = os.getenv("COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING") | ||
| endpoint, _ = parse_connection_str(self.connection_string) | ||
| self.resource_name = endpoint.split(".")[0] | ||
|
|
||
| else: | ||
| self.connection_string = "endpoint=https://sanitized.unitedstates.communication.azure.com/;accesskey=fake===" | ||
| self.resource_name = "sanitized" | ||
|
|
||
| func(self, *args, **kwargs) | ||
|
|
||
| return wrapper | ||
|
|
35 changes: 35 additions & 0 deletions
35
sdk/communication/azure-communication-messages/tests/_messages_test_case.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| from abc import abstractmethod | ||
| from retry import retry | ||
| import warnings | ||
| from _shared.utils import get_http_logging_policy | ||
| from azure.communication.messages import ( | ||
| NotificationMessagesClient, | ||
| MessageTemplateClient, | ||
| ) | ||
| from devtools_testutils import AzureRecordedTestCase | ||
|
|
||
| class MessagesRecordedTestCase(AzureRecordedTestCase): | ||
|
|
||
| def create_notification_message_client(self) -> NotificationMessagesClient: | ||
| return NotificationMessagesClient.from_connection_string( | ||
| conn_str=self.connection_string, http_logging_policy=get_http_logging_policy() | ||
| ) | ||
|
|
||
| def create_notification_message_client_from_token(self) -> NotificationMessagesClient: | ||
| return NotificationMessagesClient.from_token_credentials( | ||
| endpoint=self.endpoint_str, http_logging_policy=get_http_logging_policy() | ||
| ) | ||
|
|
||
| def create_message_template_client(self) -> MessageTemplateClient: | ||
| return MessageTemplateClient.from_connection_string( | ||
| conn_str=self.connection_string, http_logging_policy=get_http_logging_policy() | ||
| ) | ||
|
|
||
| def create_message_template_client_from_token(self) -> MessageTemplateClient: | ||
| return MessageTemplateClient.from_token_credentials( | ||
| endpoint=self.endpoint_str, http_logging_policy=get_http_logging_policy() | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
sdk/communication/azure-communication-messages/tests/test_messages_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| import os | ||
| from typing import List | ||
| from devtools_testutils import recorded_by_proxy | ||
| from _decorators import MessagesPreparers | ||
| from azure.core.credentials import AccessToken | ||
| from azure.communication.messages import NotificationMessagesClient | ||
| from azure.communication.messages.models import ( | ||
| TextNotificationContent, | ||
| ImageNotificationContent, | ||
| TemplateNotificationContent, | ||
| MessageReceipt, | ||
| MessageTemplate, | ||
| MessageTemplateText, | ||
| MessageTemplateBindings, | ||
| MessageTemplateValue, | ||
| WhatsAppMessageTemplateBindings, | ||
| WhatsAppMessageTemplateBindingsComponent | ||
| ) | ||
| from _shared.utils import get_http_logging_policy | ||
| from _messages_test_case import MessagesRecordedTestCase | ||
| from azure.communication.messages._shared.utils import parse_connection_str | ||
|
|
||
| class TestNotificationMessageClientForText(MessagesRecordedTestCase): | ||
|
|
||
| @MessagesPreparers.messages_test_decorator | ||
| @recorded_by_proxy | ||
| def test_text_send_message(self): | ||
| phone_number: str = "+14254360097" | ||
| raised = False | ||
|
|
||
| text_options = TextNotificationContent( | ||
| channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959", | ||
| to= [phone_number], | ||
| content="Thanks for your feedback Hello.") | ||
|
|
||
| message_response : MessageReceipt = None | ||
| message_client: NotificationMessagesClient = self.create_notification_message_client() | ||
|
|
||
| try: | ||
| with message_client: | ||
| message_responses = message_client.send(text_options) | ||
| message_response = message_responses.receipts[0] | ||
| except: | ||
| raised = True | ||
| raise | ||
| assert raised is False | ||
| assert message_response.message_id is not None | ||
| assert message_response.to is not None | ||
|
|
||
|
|
||
| @MessagesPreparers.messages_test_decorator | ||
| @recorded_by_proxy | ||
| def test_template_send_message(self): | ||
| phone_number: str = "+14254360097" | ||
| input_template: MessageTemplate = MessageTemplate( | ||
| name="gathering_invitation", | ||
| language="ca") | ||
| raised = False | ||
|
|
||
| message_client: NotificationMessagesClient = self.create_notification_message_client() | ||
|
|
||
| template_options = TemplateNotificationContent( | ||
| channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959", | ||
| to=[phone_number], | ||
| template=input_template) | ||
|
|
||
| message_response : MessageReceipt = None | ||
|
|
||
| try: | ||
| with message_client: | ||
| message_responses = message_client.send(template_options) | ||
| message_response = message_responses.receipts[0] | ||
| except: | ||
| raised = True | ||
| raise | ||
| assert raised is False | ||
| assert message_response.message_id is not None | ||
| assert message_response.to is not None | ||
|
|
||
|
|
||
| @MessagesPreparers.messages_test_decorator | ||
| @recorded_by_proxy | ||
| def test_template_with_parameters_send_message(self): | ||
|
|
||
| phone_number: str = "+14254360097" | ||
| parammeter1 = MessageTemplateText ( | ||
| name="first", | ||
| text="11-18-2024" | ||
| ) | ||
|
|
||
| input_template: MessageTemplate = MessageTemplate( | ||
| name="gathering_invitation", | ||
| language="en_US", | ||
| template_values= [parammeter1], | ||
| bindings=WhatsAppMessageTemplateBindings | ||
| ( | ||
| body= [ WhatsAppMessageTemplateBindingsComponent(ref_value="first")] | ||
| ) | ||
| ) | ||
| raised = False | ||
|
|
||
| template_options = TemplateNotificationContent( | ||
| channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959", | ||
| to=[phone_number], | ||
| template=input_template) | ||
|
|
||
| message_response : MessageReceipt = None | ||
| message_client: NotificationMessagesClient = self.create_notification_message_client() | ||
|
|
||
| try: | ||
| with message_client: | ||
| message_responses = message_client.send(template_options) | ||
| message_response = message_responses.receipts[0] | ||
| except: | ||
| raised = True | ||
| raise | ||
| assert raised is False | ||
| assert message_response.message_id is not None | ||
| assert message_response.to is not None | ||
|
|
||
| @MessagesPreparers.messages_test_decorator | ||
| @recorded_by_proxy | ||
| def test_image_send_message(self): | ||
| phone_number: str = "+14254360097" | ||
| input_media_uri: str = "https://aka.ms/acsicon1" | ||
| raised = False | ||
|
|
||
| template_options = ImageNotificationContent( | ||
| channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959", | ||
| to=[phone_number], | ||
| media_uri=input_media_uri) | ||
|
|
||
| message_response : MessageReceipt = None | ||
| message_client: NotificationMessagesClient = self.create_notification_message_client() | ||
|
|
||
| try: | ||
| with message_client: | ||
| message_responses = message_client.send(template_options) | ||
| message_response = message_responses.receipts[0] | ||
| except: | ||
| raised = True | ||
| raise | ||
| assert raised is False | ||
| assert message_response.message_id is not None | ||
| assert message_response.to is not None | ||
|
|
||
|
|
||
| @MessagesPreparers.messages_test_decorator | ||
| @recorded_by_proxy | ||
| def test_download_media(self): | ||
| phone_number: str = "+14254360097" | ||
| input_media_id: str = "8f8c29b2-c2e4-4340-bb28-3009c8a57283" | ||
| raised = False | ||
| message_client: NotificationMessagesClient = self.create_notification_message_client() | ||
| try: | ||
| with message_client: | ||
| media_stream = message_client.download_media(input_media_id) | ||
| except: | ||
| raised = True | ||
| raise | ||
| assert raised is False | ||
| assert media_stream is not None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
sdk/communication/azure-communication-messages/tests/test_messages_template_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| from devtools_testutils import recorded_by_proxy | ||
| from _decorators import MessagesPreparers | ||
| from azure.communication.messages.models import ( | ||
| MessageTemplateItem, | ||
| MessageTemplate | ||
| ) | ||
| from _shared.utils import get_http_logging_policy | ||
| from _messages_test_case import MessagesRecordedTestCase | ||
| from azure.communication.messages._shared.utils import parse_connection_str | ||
|
|
||
| class TestMessageTemplateClientToGetTemplates(MessagesRecordedTestCase): | ||
|
|
||
| @MessagesPreparers.messages_test_decorator | ||
| @recorded_by_proxy | ||
| def test_get_templates(self): | ||
| channel_id = "b045be8c-45cd-492a-b2a2-47bae7c36959" | ||
| raised = False | ||
|
|
||
| message_template_client = self.create_message_template_client() | ||
|
|
||
| try: | ||
| with message_template_client: | ||
| message_template_item_list = message_template_client.list_templates(channel_id) | ||
| except: | ||
| raised = True | ||
| raise | ||
|
|
||
| assert raised is False | ||
| assert message_template_item_list is not None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.