Skip to content

Commit ce9bea7

Browse files
authored
CPM Python Package Release failure fix (#34893)
* release fix * release fix * review comments
1 parent 5e42039 commit ce9bea7

File tree

9 files changed

+277
-5
lines changed

9 files changed

+277
-5
lines changed

sdk/communication/azure-communication-messages/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 1.0.0 (2024-02-01)
3+
## 1.0.0 (2024-03-25)
44

55
This is the GA release of Azure Communication Messages Python SDK. For more information, please see the [README][read_me].
66

sdk/communication/azure-communication-messages/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/communication/azure-communication-messages",
5-
"Tag": "python/communication/azure-communication-messages_1c6b0f13ac"
5+
"Tag": "python/communication/azure-communication-messages_22ab5a97f3"
66
}

sdk/communication/azure-communication-messages/dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-e ../../../tools/azure-sdk-tools
33
../../core/azure-core
44
../../identity/azure-identity
5-
aiohttp
5+
aiohttp>=3.0
66
aiounittest>=1.4
77
pytest-tornasync==0.6.0.post2
88
retry>=0.9.2
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
import os
8+
from typing import Callable, Any
9+
10+
from devtools_testutils import is_live, is_live_and_not_recording, trim_kwargs_from_test_function
11+
from azure.communication.messages._shared.utils import parse_connection_str
12+
13+
class MessagesPreparers(object):
14+
15+
@staticmethod
16+
def messages_test_decorator(func: Callable[[], object], **kwargs: Any):
17+
def wrapper(self, *args, **kwargs):
18+
if is_live() or is_live_and_not_recording():
19+
self.connection_string = os.getenv("COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING")
20+
endpoint, _ = parse_connection_str(self.connection_string)
21+
self.resource_name = endpoint.split(".")[0]
22+
23+
else:
24+
self.connection_string = "endpoint=https://sanitized.unitedstates.communication.azure.com/;accesskey=fake==="
25+
self.resource_name = "sanitized"
26+
27+
func(self, *args, **kwargs)
28+
29+
return wrapper
30+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
# ------------------------------------
4+
5+
from abc import abstractmethod
6+
from retry import retry
7+
import warnings
8+
from _shared.utils import get_http_logging_policy
9+
from azure.communication.messages import (
10+
NotificationMessagesClient,
11+
MessageTemplateClient,
12+
)
13+
from devtools_testutils import AzureRecordedTestCase
14+
15+
class MessagesRecordedTestCase(AzureRecordedTestCase):
16+
17+
def create_notification_message_client(self) -> NotificationMessagesClient:
18+
return NotificationMessagesClient.from_connection_string(
19+
conn_str=self.connection_string, http_logging_policy=get_http_logging_policy()
20+
)
21+
22+
def create_notification_message_client_from_token(self) -> NotificationMessagesClient:
23+
return NotificationMessagesClient.from_token_credentials(
24+
endpoint=self.endpoint_str, http_logging_policy=get_http_logging_policy()
25+
)
26+
27+
def create_message_template_client(self) -> MessageTemplateClient:
28+
return MessageTemplateClient.from_connection_string(
29+
conn_str=self.connection_string, http_logging_policy=get_http_logging_policy()
30+
)
31+
32+
def create_message_template_client_from_token(self) -> MessageTemplateClient:
33+
return MessageTemplateClient.from_token_credentials(
34+
endpoint=self.endpoint_str, http_logging_policy=get_http_logging_policy()
35+
)

sdk/communication/azure-communication-messages/tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def start_proxy(test_proxy):
5252
add_general_string_sanitizer(target=resource_name, value="sanitized")
5353
add_general_regex_sanitizer(regex=connection_str, value=FAKE_CONNECTION_STRING)
5454
add_general_regex_sanitizer(regex=endpoint, value=FAKE_ENDPOINT)
55-
55+
56+
add_general_string_sanitizer(target="8f8c29b2-c2e4-4340-bb28-3009c8a57283", value="sanitized")
5657
add_body_key_sanitizer(json_path="channel_registration_id", value="sanitized")
5758
add_body_key_sanitizer(json_path="*.channel_registration_id", value="sanitized")
5859
add_body_key_sanitizer(json_path="*..channel_registration_id", value="sanitized")
@@ -65,6 +66,9 @@ def start_proxy(test_proxy):
6566
add_body_key_sanitizer(json_path="media_uri", value="sanitized")
6667
add_body_key_sanitizer(json_path="*.media_uri", value="sanitized")
6768
add_body_key_sanitizer(json_path="*..media_uri", value="sanitized")
69+
add_body_key_sanitizer(json_path="id", value="sanitized")
70+
add_body_key_sanitizer(json_path="*.id", value="sanitized")
71+
add_body_key_sanitizer(json_path="*..id", value="sanitized")
6872
add_body_key_sanitizer(json_path="repeatability-request-id", value="sanitized")
6973
add_body_key_sanitizer(json_path="*.repeatability-request-id", value="sanitized")
7074
add_body_key_sanitizer(json_path="*..repeatability-request-id", value="sanitized")
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
import os
8+
from typing import List
9+
from devtools_testutils import recorded_by_proxy
10+
from _decorators import MessagesPreparers
11+
from azure.core.credentials import AccessToken
12+
from azure.communication.messages import NotificationMessagesClient
13+
from azure.communication.messages.models import (
14+
TextNotificationContent,
15+
ImageNotificationContent,
16+
TemplateNotificationContent,
17+
MessageReceipt,
18+
MessageTemplate,
19+
MessageTemplateText,
20+
MessageTemplateBindings,
21+
MessageTemplateValue,
22+
WhatsAppMessageTemplateBindings,
23+
WhatsAppMessageTemplateBindingsComponent
24+
)
25+
from _shared.utils import get_http_logging_policy
26+
from _messages_test_case import MessagesRecordedTestCase
27+
from azure.communication.messages._shared.utils import parse_connection_str
28+
29+
class TestNotificationMessageClientForText(MessagesRecordedTestCase):
30+
31+
@MessagesPreparers.messages_test_decorator
32+
@recorded_by_proxy
33+
def test_text_send_message(self):
34+
phone_number: str = "+14254360097"
35+
raised = False
36+
37+
text_options = TextNotificationContent(
38+
channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959",
39+
to= [phone_number],
40+
content="Thanks for your feedback Hello.")
41+
42+
message_response : MessageReceipt = None
43+
message_client: NotificationMessagesClient = self.create_notification_message_client()
44+
45+
try:
46+
with message_client:
47+
message_responses = message_client.send(text_options)
48+
message_response = message_responses.receipts[0]
49+
except:
50+
raised = True
51+
raise
52+
assert raised is False
53+
assert message_response.message_id is not None
54+
assert message_response.to is not None
55+
56+
57+
@MessagesPreparers.messages_test_decorator
58+
@recorded_by_proxy
59+
def test_template_send_message(self):
60+
phone_number: str = "+14254360097"
61+
input_template: MessageTemplate = MessageTemplate(
62+
name="gathering_invitation",
63+
language="ca")
64+
raised = False
65+
66+
message_client: NotificationMessagesClient = self.create_notification_message_client()
67+
68+
template_options = TemplateNotificationContent(
69+
channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959",
70+
to=[phone_number],
71+
template=input_template)
72+
73+
message_response : MessageReceipt = None
74+
75+
try:
76+
with message_client:
77+
message_responses = message_client.send(template_options)
78+
message_response = message_responses.receipts[0]
79+
except:
80+
raised = True
81+
raise
82+
assert raised is False
83+
assert message_response.message_id is not None
84+
assert message_response.to is not None
85+
86+
87+
@MessagesPreparers.messages_test_decorator
88+
@recorded_by_proxy
89+
def test_template_with_parameters_send_message(self):
90+
91+
phone_number: str = "+14254360097"
92+
parammeter1 = MessageTemplateText (
93+
name="first",
94+
text="11-18-2024"
95+
)
96+
97+
input_template: MessageTemplate = MessageTemplate(
98+
name="gathering_invitation",
99+
language="en_US",
100+
template_values= [parammeter1],
101+
bindings=WhatsAppMessageTemplateBindings
102+
(
103+
body= [ WhatsAppMessageTemplateBindingsComponent(ref_value="first")]
104+
)
105+
)
106+
raised = False
107+
108+
template_options = TemplateNotificationContent(
109+
channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959",
110+
to=[phone_number],
111+
template=input_template)
112+
113+
message_response : MessageReceipt = None
114+
message_client: NotificationMessagesClient = self.create_notification_message_client()
115+
116+
try:
117+
with message_client:
118+
message_responses = message_client.send(template_options)
119+
message_response = message_responses.receipts[0]
120+
except:
121+
raised = True
122+
raise
123+
assert raised is False
124+
assert message_response.message_id is not None
125+
assert message_response.to is not None
126+
127+
@MessagesPreparers.messages_test_decorator
128+
@recorded_by_proxy
129+
def test_image_send_message(self):
130+
phone_number: str = "+14254360097"
131+
input_media_uri: str = "https://aka.ms/acsicon1"
132+
raised = False
133+
134+
template_options = ImageNotificationContent(
135+
channel_registration_id="b045be8c-45cd-492a-b2a2-47bae7c36959",
136+
to=[phone_number],
137+
media_uri=input_media_uri)
138+
139+
message_response : MessageReceipt = None
140+
message_client: NotificationMessagesClient = self.create_notification_message_client()
141+
142+
try:
143+
with message_client:
144+
message_responses = message_client.send(template_options)
145+
message_response = message_responses.receipts[0]
146+
except:
147+
raised = True
148+
raise
149+
assert raised is False
150+
assert message_response.message_id is not None
151+
assert message_response.to is not None
152+
153+
154+
@MessagesPreparers.messages_test_decorator
155+
@recorded_by_proxy
156+
def test_download_media(self):
157+
phone_number: str = "+14254360097"
158+
input_media_id: str = "8f8c29b2-c2e4-4340-bb28-3009c8a57283"
159+
raised = False
160+
message_client: NotificationMessagesClient = self.create_notification_message_client()
161+
try:
162+
with message_client:
163+
media_stream = message_client.download_media(input_media_id)
164+
except:
165+
raised = True
166+
raise
167+
assert raised is False
168+
assert media_stream is not None

sdk/communication/azure-communication-messages/tests/test_messages_client_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def test_image_send_message_async(self):
156156
@recorded_by_proxy_async
157157
async def test_download_media_async(self):
158158
phone_number: str = "+14254360097"
159-
input_media_id: str = "315a0b04-d80d-4573-bcf1-1ce33d3f19f0"
159+
input_media_id: str = "8f8c29b2-c2e4-4340-bb28-3009c8a57283"
160160
raised = False
161161
message_client: NotificationMessagesClient = self.create_notification_message_client()
162162
try:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
from devtools_testutils import recorded_by_proxy
8+
from _decorators import MessagesPreparers
9+
from azure.communication.messages.models import (
10+
MessageTemplateItem,
11+
MessageTemplate
12+
)
13+
from _shared.utils import get_http_logging_policy
14+
from _messages_test_case import MessagesRecordedTestCase
15+
from azure.communication.messages._shared.utils import parse_connection_str
16+
17+
class TestMessageTemplateClientToGetTemplates(MessagesRecordedTestCase):
18+
19+
@MessagesPreparers.messages_test_decorator
20+
@recorded_by_proxy
21+
def test_get_templates(self):
22+
channel_id = "b045be8c-45cd-492a-b2a2-47bae7c36959"
23+
raised = False
24+
25+
message_template_client = self.create_message_template_client()
26+
27+
try:
28+
with message_template_client:
29+
message_template_item_list = message_template_client.list_templates(channel_id)
30+
except:
31+
raised = True
32+
raise
33+
34+
assert raised is False
35+
assert message_template_item_list is not None

0 commit comments

Comments
 (0)