|
6 | 6 |
|
7 | 7 | from botbuilder.core import TurnContext, MessageFactory
|
8 | 8 | from botbuilder.core.teams import TeamsInfo, TeamsActivityHandler
|
9 |
| -from botbuilder.schema import Activity |
10 |
| -from botbuilder.schema.teams import TeamsChannelData, TeamInfo |
11 |
| -from botframework.connector import Channels |
| 9 | +from botbuilder.schema import ( |
| 10 | + Activity, |
| 11 | + ChannelAccount, |
| 12 | + ConversationAccount, |
| 13 | +) |
12 | 14 | from simple_adapter_with_create_conversation import SimpleAdapterWithCreateConversation
|
13 | 15 |
|
| 16 | +ACTIVITY = Activity( |
| 17 | + id="1234", |
| 18 | + type="message", |
| 19 | + text="test", |
| 20 | + from_property=ChannelAccount(id="user", name="User Name"), |
| 21 | + recipient=ChannelAccount(id="bot", name="Bot Name"), |
| 22 | + conversation=ConversationAccount(id="convo", name="Convo Name"), |
| 23 | + channel_data={"channelData": {}}, |
| 24 | + channel_id="UnitTest", |
| 25 | + locale="en-us", |
| 26 | + service_url="https://example.org", |
| 27 | +) |
| 28 | + |
14 | 29 |
|
15 | 30 | class TestTeamsInfo(aiounittest.AsyncTestCase):
|
16 | 31 | async def test_send_message_to_teams_channels_without_activity(self):
|
@@ -41,17 +56,149 @@ def create_conversation():
|
41 | 56 | call_create_conversation=create_conversation
|
42 | 57 | )
|
43 | 58 |
|
44 |
| - activity = Activity( |
45 |
| - type="message", |
46 |
| - text="test_send_message_to_teams_channel", |
47 |
| - channel_id=Channels.ms_teams, |
48 |
| - service_url="https://example.org", |
49 |
| - channel_data=TeamsChannelData(team=TeamInfo(id="team-id")), |
50 |
| - ) |
51 |
| - turn_context = TurnContext(adapter, activity) |
| 59 | + turn_context = TurnContext(adapter, ACTIVITY) |
52 | 60 | handler = TestTeamsActivityHandler()
|
53 | 61 | await handler.on_turn(turn_context)
|
54 | 62 |
|
| 63 | + async def test_send_message_to_teams_channels_without_turn_context(self): |
| 64 | + try: |
| 65 | + await TeamsInfo.send_message_to_teams_channel( |
| 66 | + None, ACTIVITY, "channelId123" |
| 67 | + ) |
| 68 | + except ValueError: |
| 69 | + pass |
| 70 | + else: |
| 71 | + assert False, "should have raise ValueError" |
| 72 | + |
| 73 | + async def test_send_message_to_teams_channels_without_teams_channel_id(self): |
| 74 | + def create_conversation(): |
| 75 | + pass |
| 76 | + |
| 77 | + adapter = SimpleAdapterWithCreateConversation( |
| 78 | + call_create_conversation=create_conversation |
| 79 | + ) |
| 80 | + |
| 81 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 82 | + |
| 83 | + try: |
| 84 | + await TeamsInfo.send_message_to_teams_channel(turn_context, ACTIVITY, "") |
| 85 | + except ValueError: |
| 86 | + pass |
| 87 | + else: |
| 88 | + assert False, "should have raise ValueError" |
| 89 | + |
| 90 | + async def test_send_message_to_teams_channel_works(self): |
| 91 | + adapter = SimpleAdapterWithCreateConversation() |
| 92 | + |
| 93 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 94 | + result = await TeamsInfo.send_message_to_teams_channel( |
| 95 | + turn_context, ACTIVITY, "teamId123" |
| 96 | + ) |
| 97 | + assert result[0].activity_id == "new_conversation_id" |
| 98 | + assert result[1] == "reference123" |
| 99 | + |
| 100 | + async def test_get_team_details_works_without_team_id(self): |
| 101 | + adapter = SimpleAdapterWithCreateConversation() |
| 102 | + ACTIVITY.channel_data = {} |
| 103 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 104 | + result = TeamsInfo.get_team_id(turn_context) |
| 105 | + |
| 106 | + assert result == "" |
| 107 | + |
| 108 | + async def test_get_team_details_works_with_team_id(self): |
| 109 | + adapter = SimpleAdapterWithCreateConversation() |
| 110 | + team_id = "teamId123" |
| 111 | + ACTIVITY.channel_data = {"team": {"id": team_id}} |
| 112 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 113 | + result = TeamsInfo.get_team_id(turn_context) |
| 114 | + |
| 115 | + assert result == team_id |
| 116 | + |
| 117 | + async def test_get_team_details_without_team_id(self): |
| 118 | + def create_conversation(): |
| 119 | + pass |
| 120 | + |
| 121 | + adapter = SimpleAdapterWithCreateConversation( |
| 122 | + call_create_conversation=create_conversation |
| 123 | + ) |
| 124 | + |
| 125 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 126 | + |
| 127 | + try: |
| 128 | + await TeamsInfo.get_team_details(turn_context) |
| 129 | + except TypeError: |
| 130 | + pass |
| 131 | + else: |
| 132 | + assert False, "should have raise TypeError" |
| 133 | + |
| 134 | + async def test_get_team_channels_without_team_id(self): |
| 135 | + def create_conversation(): |
| 136 | + pass |
| 137 | + |
| 138 | + adapter = SimpleAdapterWit
8000
hCreateConversation( |
| 139 | + call_create_conversation=create_conversation |
| 140 | + ) |
| 141 | + |
| 142 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 143 | + |
| 144 | + try: |
| 145 | + await TeamsInfo.get_team_channels(turn_context) |
| 146 | + except TypeError: |
| 147 | + pass |
| 148 | + else: |
| 149 | + assert False, "should have raise TypeError" |
| 150 | + |
| 151 | + async def test_get_paged_team_members_without_team_id(self): |
| 152 | + def create_conversation(): |
| 153 | + pass |
| 154 | + |
| 155 | + adapter = SimpleAdapterWithCreateConversation( |
| 156 | + call_create_conversation=create_conversation |
| 157 | + ) |
| 158 | + |
| 159 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 160 | + |
| 161 | + try: |
| 162 | + await TeamsInfo.get_paged_team_members(turn_context) |
| 163 | + except TypeError: |
| 164 | + pass |
| 165 | + else: |
| 166 | + assert False, "should have raise TypeError" |
| 167 | + |
| 168 | + async def test_get_team_members_without_team_id(self): |
| 169 | + def create_conversation(): |
| 170 | + pass |
| 171 | + |
| 172 | + adapter = SimpleAdapterWithCreateConversation( |
| 173 | + call_create_conversation=create_conversation |
| 174 | + ) |
| 175 | + |
| 176 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 177 | + |
| 178 | + try: |
| 179 | + await TeamsInfo.get_team_member(turn_context) |
| 180 | + except TypeError: |
| 181 | + pass |
| 182 | + else: |
| 183 | + assert False, "should have raise TypeError" |
| 184 | + |
| 185 | + async def test_get_team_members_without_member_id(self): |
| 186 | + def create_conversation(): |
| 187 | + pass |
| 188 | + |
| 189 | + adapter = SimpleAdapterWithCreateConversation( |
| 190 | + call_create_conversation=create_conversation |
| 191 | + ) |
| 192 | + |
| 193 | + turn_context = TurnContext(adapter, ACTIVITY) |
| 194 | + |
| 195 | + try: |
| 196 | + await TeamsInfo.get_team_member(turn_context, "teamId123") |
| 197 | + except TypeError: |
| 198 | + pass |
| 199 | + else: |
| 200 | + assert False, "should have raise TypeError" |
| 201 | + |
55 | 202 |
|
56 | 203 | class TestTeamsActivityHandler(TeamsActivityHandler):
|
57 | 204 | async def on_turn(self, turn_context: TurnContext):
|
|
0 commit comments