|
4 | 4 | from copy import copy, deepcopy
|
5 | 5 | from unittest.mock import Mock
|
6 | 6 | import unittest
|
| 7 | +import uuid |
7 | 8 | import aiounittest
|
8 | 9 |
|
9 | 10 | from botbuilder.core import (
|
|
16 | 17 | ActivityTypes,
|
17 | 18 | ConversationAccount,
|
18 | 19 | ConversationReference,
|
| 20 | + ConversationResourceResponse, |
19 | 21 | ChannelAccount,
|
20 | 22 | )
|
21 | 23 | from botframework.connector.aio import ConnectorClient
|
@@ -124,7 +126,12 @@ async def mock_create_conversation(parameters):
|
124 | 126 | self.tester.assertIsNotNone(
|
125 | 127 | parameters, "create_conversation not passed parameters"
|
126 | 128 | )
|
127 |
| - return not self.fail_auth |
| 129 | + response = ConversationResourceResponse( |
| 130 | + activity_id=REFERENCE.activity_id, |
| 131 | + service_url=REFERENCE.service_url, |
| 132 | + id=uuid.uuid4(), |
| 133 | + ) |
| 134 | + return response |
128 | 135 |
|
129 | 136 | connector_client_mock.conversations.reply_to_activity.side_effect = (
|
130 | 137 | mock_reply_to_activity
|
@@ -247,3 +254,36 @@ async def aux_func_assert_tenant_id_copied(context):
|
247 | 254 | )
|
248 | 255 |
|
249 | 256 | await adapter.process_activity(incoming, "", aux_func_assert_tenant_id_copied)
|
| 257 | + |
| 258 | + async def test_should_create_valid_conversation_for_msteams(self): |
| 259 | + |
| 260 | + tenant_id = "testTenant" |
| 261 | + |
| 262 | + reference = deepcopy(REFERENCE) |
| 263 | + reference.conversation.tenant_id = tenant_id |
| 264 | + reference.channel_data = {"tenant": {"id": tenant_id}} |
| 265 | + adapter = AdapterUnderTest() |
| 266 | + |
| 267 | + called = False |
| 268 | + |
| 269 | + async def aux_func_assert_valid_conversation(context): |
| 270 | + self.assertIsNotNone(context, "context not passed") |
| 271 | + self.assertIsNotNone(context.activity, "context has no request") |
| 272 | + self.assertIsNotNone( |
| 273 | + context.activity.conversation, "request has invalid conversation" |
| 274 | + ) |
| 275 | + self.assertEqual( |
| 276 | + context.activity.conversation.tenant_id, |
| 277 | + tenant_id, |
| 278 | + "request has invalid tenant_id on conversation", |
| 279 | + ) |
| 280 | + self.assertEqual( |
| 281 | + context.activity.channel_data["tenant"]["id"], |
| 282 | + tenant_id, |
| 283 | + "request has invalid tenant_id in channel_data", |
| 284 | + ) |
| 285 | + nonlocal called |
| 286 | + called = True |
| 287 | + |
| 288 | + await adapter.create_conversation(reference, aux_func_assert_valid_conversation) |
| 289 | + self.assertTrue(called, "bot logic not called.") |
0 commit comments