Skip to content

Commit 23cc975

Browse files
committed
Added unit tests for notification and tooling
1 parent 4a69e4a commit 23cc975

File tree

25 files changed

+3871
-122
lines changed

25 files changed

+3871
-122
lines changed

.coverage

68 KB
Binary file not shown.

tests/notifications/__init__.py renamed to tests/microsoft-agents-a365-notification/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
"""
44
Unit tests for Microsoft Agents A365 Notifications module.
5-
"""
5+
"""

tests/notifications/models/__init__.py renamed to tests/microsoft-agents-a365-notification/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
"""
44
Unit tests for Microsoft Agents A365 Notifications models.
5-
"""
5+
"""

tests/notifications/models/test_agent_notification.py renamed to tests/microsoft-agents-a365-notification/models/test_agent_notification.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ class ChannelId:
1919
MSTeams = "msteams"
2020
Directline = "directline"
2121
Webchat = "webchat"
22-
22+
2323
class Activity:
2424
def __init__(self, **kwargs):
2525
for k, v in kwargs.items():
2626
setattr(self, k, v)
27-
27+
2828
class TurnContext:
2929
def __init__(self, **kwargs):
3030
for k, v in kwargs.items():
3131
setattr(self, k, v)
32-
32+
3333
class TurnState:
3434
def __init__(self, **kwargs):
3535
for k, v in kwargs.items():
3636
setattr(self, k, v)
37+
38+
3739
from microsoft_agents_a365.notifications.agent_notification import AgentNotification
3840
from microsoft_agents_a365.notifications.models.agent_notification_activity import (
3941
AgentNotificationActivity,
@@ -409,4 +411,4 @@ async def test_route_selector_unknown_subchannel(self):
409411
result = route_selector(mock_context)
410412

411413
# Assert
412-
assert result is False
414+
assert result is False

tests/notifications/models/test_agent_notification_activity.py renamed to tests/microsoft-agents-a365-notification/models/test_agent_notification_activity.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
class TestAgentNotificationActivity:
2222
"""Test cases for AgentNotificationActivity class"""
23-
24-
def _create_mock_activity(self, entities=None, name="agentLifecycle", channel_id=None, value=None, type="message"):
23+
24+
def _create_mock_activity(
25+
self, entities=None, name="agentLifecycle", channel_id=None, value=None, type="message"
26+
):
2527
"""Helper to create properly configured mock activity"""
2628
mock_activity = Mock(spec=Activity)
2729
# Directly set attributes to ensure they're accessible
@@ -108,7 +110,7 @@ def test_init_with_multiple_entities(self):
108110
mock_email_entity.properties = {"type": "emailNotification"}
109111

110112
mock_wpx_entity = Mock()
111-
mock_wpx_entity.type = "WPXCOMMENT"
113+
mock_wpx_entity.type = "WPXCOMMENT"
112114
mock_wpx_entity.properties = {"type": "wpxComment"}
113115

114116
mock_activity = self._create_mock_activity(entities=[mock_email_entity, mock_wpx_entity])
@@ -172,7 +174,7 @@ def test_sub_channel_property_with_channel_id(self):
172174
# Arrange
173175
mock_channel_id = Mock()
174176
mock_channel_id.sub_channel = "testSubChannel"
175-
177+
176178
mock_activity = self._create_mock_activity(entities=None, channel_id=mock_channel_id)
177179

178180
ana = AgentNotificationActivity(mock_activity)
@@ -229,10 +231,7 @@ def test_email_property_returns_parsed_email(self):
229231
# Arrange
230232
mock_email_entity = Mock()
231233
mock_email_entity.type = "EMAILNOTIFICATION"
232-
mock_email_entity.properties = {
233-
"type": "emailNotification",
234-
"id": "test-email-id"
235-
}
234+
mock_email_entity.properties = {"type": "emailNotification", "id": "test-email-id"}
236235

237236
mock_activity = self._create_mock_activity(entities=[mock_email_entity])
238237

@@ -250,10 +249,7 @@ def test_wpx_comment_property_returns_parsed_comment(self):
250249
# Arrange
251250
mock_wpx_entity = Mock()
252251
mock_wpx_entity.type = "WPXCOMMENT"
253-
mock_wpx_entity.properties = {
254-
"type": "wpxComment",
255-
"odataId": "test-comment-id"
256-
}
252+
mock_wpx_entity.properties = {"type": "wpxComment", "odataId": "test-comment-id"}
257253

258254
mock_activity = self._create_mock_activity(entities=[mock_wpx_entity])
259255

@@ -329,7 +325,9 @@ def test_duplicate_entity_type_handling(self):
329325
mock_email_entity2.type = "EMAILNOTIFICATION"
330326
mock_email_entity2.properties = {"type": "emailNotification", "id": "second"}
331327

332-
mock_activity = self._create_mock_activity(entities=[mock_email_entity1, mock_email_entity2])
328+
mock_activity = self._create_mock_activity(
329+
entities=[mock_email_entity1, mock_email_entity2]
330+
)
333331

334332
# Act
335333
ana = AgentNotificationActivity(mock_activity)
@@ -363,7 +361,7 @@ def test_entity_parsing_only_first_entity_of_each_type(self):
363361
email_entity1.properties = {"type": "emailNotification", "id": "email1"}
364362

365363
email_entity2 = Mock()
366-
email_entity2.type = "EMAILNOTIFICATION"
364+
email_entity2.type = "EMAILNOTIFICATION"
367365
email_entity2.properties = {"type": "emailNotification", "id": "email2"}
368366

369367
mock_activity = self._create_mock_activity(entities=[email_entity1, email_entity2])
@@ -377,7 +375,7 @@ def test_entity_parsing_only_first_entity_of_each_type(self):
377375

378376
def test_as_model_with_none_value(self):
379377
"""Test as_model method with None value"""
380-
# Arrange
378+
# Arrange
381379
mock_activity = self._create_mock_activity(entities=None, value=None)
382380

383381
mock_model_class = Mock()
@@ -388,4 +386,4 @@ def test_as_model_with_none_value(self):
388386
result = ana.as_model(mock_model_class)
389387

390388
# Assert
391-
mock_model_class.model_validate.assert_called_once_with({})
389+
mock_model_class.model_validate.assert_called_once_with({})

tests/notifications/models/test_email_reference.py renamed to tests/microsoft-agents-a365-notification/models/test_email_reference.py

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def test_init_with_all_values(self):
2727
"""Test EmailReference initialization with all values provided"""
2828
# Arrange & Act
2929
email_ref = EmailReference(
30-
id="email-123",
31-
conversation_id="conv-456",
32-
html_body="<p>Test email content</p>"
30+
id="email-123", conversation_id="conv-456", html_body="<p>Test email content</p>"
3331
)
3432

3533
# Assert
@@ -41,10 +39,7 @@ def test_init_with_all_values(self):
4139
def test_init_with_partial_values(self):
4240
"""Test EmailReference initialization with only some values"""
4341
# Arrange & Act
44-
email_ref = EmailReference(
45-
id="email-789",
46-
conversation_id="conv-101112"
47-
)
42+
email_ref = EmailReference(id="email-789", conversation_id="conv-101112")
4843

4944
# Assert
5045
assert email_ref.type == NotificationTypes.EMAIL_NOTIFICATION
@@ -67,7 +62,7 @@ def test_model_validate_from_dict_with_all_fields(self):
6762
data = {
6863
"id": "test-email-id",
6964
"conversation_id": "test-conv-id",
70-
"html_body": "<html><body>Test content</body></html>"
65+
"html_body": "<html><body>Test content</body></html>",
7166
}
7267

7368
# Act
@@ -82,9 +77,7 @@ def test_model_validate_from_dict_with_all_fields(self):
8277
def test_model_validate_from_dict_with_partial_fields(self):
8378
"""Test creating EmailReference from dictionary with partial fields"""
8479
# Arrange
85-
data = {
86-
"id": "partial-email-id"
87-
}
80+
data = {"id": "partial-email-id"}
8881

8982
# Act
9083
email_ref = EmailReference.model_validate(data)
@@ -116,7 +109,7 @@ def test_model_validate_with_extra_fields(self):
116109
"id": "test-id",
117110
"conversation_id": "test-conv",
118111
"extra_field": "should_be_ignored_or_handled",
119-
"another_extra": 123
112+
"another_extra": 123,
120113
}
121114

122115
# Act
@@ -131,11 +124,7 @@ def test_model_validate_with_extra_fields(self):
131124
def test_model_validate_with_none_values(self):
132125
"""Test model validation with explicit None values"""
133126
# Arrange
134-
data = {
135-
"id": None,
136-
"conversation_id": None,
137-
"html_body": None
138-
}
127+
data = {"id": None, "conversation_id": None, "html_body": None}
139128

140129
# Act
141130
email_ref = EmailReference.model_validate(data)
@@ -152,15 +141,15 @@ def test_properties_are_accessible(self):
152141
email_ref = EmailReference(
153142
id="prop-test-id",
154143
conversation_id="prop-test-conv",
155-
html_body="<div>Property test content</div>"
144+
html_body="<div>Property test content</div>",
156145
)
157146

158147
# Act & Assert
159-
assert hasattr(email_ref, 'id')
160-
assert hasattr(email_ref, 'conversation_id')
161-
assert hasattr(email_ref, 'html_body')
162-
assert hasattr(email_ref, 'type')
163-
148+
assert hasattr(email_ref, "id")
149+
assert hasattr(email_ref, "conversation_id")
150+
assert hasattr(email_ref, "html_body")
151+
assert hasattr(email_ref, "type")
152+
164153
assert email_ref.id == "prop-test-id"
165154
assert email_ref.conversation_id == "prop-test-conv"
166155
assert email_ref.html_body == "<div>Property test content</div>"
@@ -199,13 +188,13 @@ def test_id_with_various_formats(self):
199188
"email_123456",
200189
"msg-abcd-efgh-1234",
201190
202-
"12345"
191+
"12345",
203192
]
204193

205194
for test_id in test_ids:
206195
# Act
207196
email_ref = EmailReference(id=test_id)
208-
197+
209198
# Assert
210199
assert email_ref.id == test_id
211200
assert email_ref.type == NotificationTypes.EMAIL_NOTIFICATION
@@ -217,13 +206,13 @@ def test_conversation_id_formats(self):
217206
"conv-123",
218207
"conversation_abcd1234",
219208
"thread-xyz-789",
220-
209+
221210
]
222211

223212
for conv_id in test_conv_ids:
224213
# Act
225214
email_ref = EmailReference(conversation_id=conv_id)
226-
215+
227216
# Assert
228217
assert email_ref.conversation_id == conv_id
229218
assert email_ref.type == NotificationTypes.EMAIL_NOTIFICATION
@@ -232,21 +221,15 @@ def test_model_equality_comparison(self):
232221
"""Test equality comparison between EmailReference instances"""
233222
# Arrange
234223
email_ref1 = EmailReference(
235-
id="test-id",
236-
conversation_id="test-conv",
237-
html_body="<p>Test</p>"
224+
id="test-id", conversation_id="test-conv", html_body="<p>Test</p>"
238225
)
239-
226+
240227
email_ref2 = EmailReference(
241-
id="test-id",
242-
conversation_id="test-conv",
243-
html_body="<p>Test</p>"
228+
id="test-id", conversation_id="test-conv", html_body="<p>Test</p>"
244229
)
245-
230+
246231
email_ref3 = EmailReference(
247-
id="different-id",
248-
conversation_id="test-conv",
249-
html_body="<p>Test</p>"
232+
id="different-id", conversation_id="test-conv", html_body="<p>Test</p>"
250233
)
251234

252235
# Act & Assert
@@ -257,9 +240,7 @@ def test_model_dict_representation(self):
257240
"""Test dictionary representation of EmailReference"""
258241
# Arrange
259242
email_ref = EmailReference(
260-
id="dict-test-id",
261-
conversation_id="dict-test-conv",
262-
html_body="<p>Dict test</p>"
243+
id="dict-test-id", conversation_id="dict-test-conv", html_body="<p>Dict test</p>"
263244
)
264245

265246
# Act
@@ -270,6 +251,6 @@ def test_model_dict_representation(self):
270251
"type": "emailNotification",
271252
"id": "dict-test-id",
272253
"conversation_id": "dict-test-conv",
273-
"html_body": "<p>Dict test</p>"
254+
"html_body": "<p>Dict test</p>",
274255
}
275-
assert email_dict == expected_dict
256+
assert email_dict == expected_dict

tests/notifications/models/test_notification_types.py renamed to tests/microsoft-agents-a365-notification/models/test_notification_types.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class TestNotificationTypes:
1414
def test_enum_values_exist(self):
1515
"""Test that all expected enum values exist"""
1616
# Assert
17-
assert hasattr(NotificationTypes, 'EMAIL_NOTIFICATION')
18-
assert hasattr(NotificationTypes, 'WPX_COMMENT')
19-
assert hasattr(NotificationTypes, 'AGENT_LIFECYCLE')
17+
assert hasattr(NotificationTypes, "EMAIL_NOTIFICATION")
18+
assert hasattr(NotificationTypes, "WPX_COMMENT")
19+
assert hasattr(NotificationTypes, "AGENT_LIFECYCLE")
2020

2121
def test_enum_string_values(self):
2222
"""Test that enum values have correct string representations"""
@@ -38,7 +38,7 @@ def test_enum_string_equality(self):
3838
assert NotificationTypes.EMAIL_NOTIFICATION == "emailNotification"
3939
assert NotificationTypes.WPX_COMMENT == "wpxComment"
4040
assert NotificationTypes.AGENT_LIFECYCLE == "agentLifecycle"
41-
41+
4242
# Test inequality
4343
assert NotificationTypes.EMAIL_NOTIFICATION != "wpxComment"
4444
assert NotificationTypes.WPX_COMMENT != "agentLifecycle"
@@ -72,7 +72,7 @@ def test_enum_membership_check(self):
7272
"""Test checking membership in enum"""
7373
# Act & Assert
7474
all_values = [nt.value for nt in NotificationTypes]
75-
75+
7676
assert "emailNotification" in all_values
7777
assert "wpxComment" in all_values
7878
assert "agentLifecycle" in all_values
@@ -160,19 +160,19 @@ def test_enum_in_collections(self):
160160
notification_list = [
161161
NotificationTypes.EMAIL_NOTIFICATION,
162162
NotificationTypes.WPX_COMMENT,
163-
NotificationTypes.AGENT_LIFECYCLE
163+
NotificationTypes.AGENT_LIFECYCLE,
164164
]
165-
165+
166166
notification_set = {
167167
NotificationTypes.EMAIL_NOTIFICATION,
168168
NotificationTypes.WPX_COMMENT,
169-
NotificationTypes.AGENT_LIFECYCLE
169+
NotificationTypes.AGENT_LIFECYCLE,
170170
}
171-
171+
172172
notification_dict = {
173173
NotificationTypes.EMAIL_NOTIFICATION: "handle_email",
174174
NotificationTypes.WPX_COMMENT: "handle_wpx",
175-
NotificationTypes.AGENT_LIFECYCLE: "handle_lifecycle"
175+
NotificationTypes.AGENT_LIFECYCLE: "handle_lifecycle",
176176
}
177177

178178
# Act & Assert
@@ -186,7 +186,7 @@ def test_enum_as_dictionary_keys(self):
186186
handlers = {
187187
NotificationTypes.EMAIL_NOTIFICATION: lambda: "email_handler",
188188
NotificationTypes.WPX_COMMENT: lambda: "wpx_handler",
189-
NotificationTypes.AGENT_LIFECYCLE: lambda: "lifecycle_handler"
189+
NotificationTypes.AGENT_LIFECYCLE: lambda: "lifecycle_handler",
190190
}
191191

192192
# Act & Assert
@@ -199,7 +199,7 @@ def test_enum_hash_consistency(self):
199199
# Act
200200
email_hash1 = hash(NotificationTypes.EMAIL_NOTIFICATION)
201201
email_hash2 = hash(NotificationTypes.EMAIL_NOTIFICATION)
202-
202+
203203
wpx_hash = hash(NotificationTypes.WPX_COMMENT)
204204
lifecycle_hash = hash(NotificationTypes.AGENT_LIFECYCLE)
205205

@@ -227,4 +227,4 @@ def test_enum_comparison_with_none(self):
227227
# Act & Assert
228228
assert NotificationTypes.EMAIL_NOTIFICATION is not None
229229
assert NotificationTypes.EMAIL_NOTIFICATION != None
230-
assert not (NotificationTypes.EMAIL_NOTIFICATION == None)
230+
assert not (NotificationTypes.EMAIL_NOTIFICATION == None)

0 commit comments

Comments
 (0)