66
77from botbuilder .core import TurnContext , MessageFactory
88from botbuilder .core .teams import TeamsInfo , TeamsActivityHandler
9- from botbuilder .schema import Activity
9+ from botbuilder .schema import Activity , ChannelAccount , ConversationAccount , ConversationReference
1010from botbuilder .schema .teams import TeamsChannelData , TeamInfo
1111from botframework .connector import Channels
1212from simple_adapter_with_create_conversation import SimpleAdapterWithCreateConversation
13-
13+ from typing import Tuple
14+
15+ ACTIVITY = Activity (
16+ id = "1234" ,
17+ type = "message" ,
18+ text = "test" ,
19+ from_property = ChannelAccount (id = "user" , name = "User Name" ),
20+ recipient = ChannelAccount (id = "bot" , name = "Bot Name" ),
21+ conversation = ConversationAccount (id = "convo" , name = "Convo Name" ),
22+ channel_data = {"channelData" : {}},
23+ channel_id = "UnitTest" ,
24+ locale = "en-us" ,
25+ service_url = "https://example.org" ,
26+ )
1427
1528class TestTeamsInfo (aiounittest .AsyncTestCase ):
1629 async def test_send_message_to_teams_channels_without_activity (self ):
@@ -41,28 +54,13 @@ def create_conversation():
4154 call_create_conversation = create_conversation
4255 )
4356
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 )
57+ turn_context = TurnContext (adapter , ACTIVITY )
5258 handler = TestTeamsActivityHandler ()
5359 await handler .on_turn (turn_context )
5460
5561 async def test_send_message_to_teams_channels_without_turn_context (self ):
56- activity = Activity (
57- type = "message" ,
58- text = "test_send_message_to_teams_channel" ,
59- channel_id = Channels .ms_teams ,
60- service_url = "https://example.org" ,
61- channel_data = TeamsChannelData (team = TeamInfo (id = "team-id" )),
62- )
63-
6462 try :
65- await TeamsInfo .send_message_to_teams_channel (None , activity , "channelId123" )
63+ await TeamsInfo .send_message_to_teams_channel (None , ACTIVITY , "channelId123" )
6664 except ValueError :
6765 pass
6866 else :
@@ -76,17 +74,10 @@ def create_conversation():
7674 call_create_conversation = create_conversation
7775 )
7876
79- activity = Activity (
80- type = "message" ,
81- text = "test_send_message_to_teams_channel" ,
82- channel_id = Channels .ms_teams ,
83- service_url = "https://example.org" ,
84- channel_data = TeamsChannelData (team = TeamInfo (id = "team-id" )),
85- )
86- turn_context = TurnContext (adapter , activity )
77+ turn_context = TurnContext (adapter , ACTIVITY )
8778
8879 try :
89- await TeamsInfo .send_message_to_teams_channel (turn_context , activity , "" )
80+ await TeamsInfo .send_message_to_teams_channel (turn_context , ACTIVITY , "" )
9081 except ValueError :
9182 pass
9283 else :
@@ -100,17 +91,127 @@ def create_conversation():
10091 call_create_conversation = create_conversation
10192 )
10293
103- activity = Activity ()
104- turn_context = TurnContext (adapter , activity )
94+ turn_context = TurnContext (adapter , ACTIVITY )
10595
10696 try :
107- await TeamsInfo .send_message_to_teams_channel (turn_context , activity , "" )
97+ await TeamsInfo .send_message_to_teams_channel (turn_context , ACTIVITY , "" )
10898 except ValueError :
10999 pass
110100 else :
111101 assert False , "should have raise ValueError"
112102
103+ async def test_send_message_to_teams_channel_works (self ):
104+ adapter = SimpleAdapterWithCreateConversation ()
105+
106+ turn_context = TurnContext (adapter , ACTIVITY )
107+ result = await TeamsInfo .send_message_to_teams_channel (turn_context , ACTIVITY , "teamId123" )
108+ assert result [0 ].activity_id == "new_conversation_id"
109+ assert result [1 ] == "reference123"
110+
111+ async def test_get_team_details_works_without_team_id (self ):
112+ adapter = SimpleAdapterWithCreateConversation ()
113+ ACTIVITY .channel_data = {}
114+ turn_context = TurnContext (adapter , ACTIVITY )
115+ result = TeamsInfo .get_team_id (turn_context )
116+
117+ assert result == ""
118+
119+ async def test_get_team_details_works_with_team_id (self ):
120+ adapter = SimpleAdapterWithCreateConversation ()
121+ team_id = "teamId123"
122+ ACTIVITY .channel_data = {"team" :{"id" : team_id }}
123+ turn_context = TurnContext (adapter , ACTIVITY )
124+ result = TeamsInfo .get_team_id (turn_context )
125+
126+ assert result == team_id
127+
128+
129+ async def test_get_team_details_without_team_id (self ):
130+ def create_conversation ():
131+ pass
132+
133+ adapter = SimpleAdapterWithCreateConversation (
134+ call_create_conversation = create_conversation
135+ )
136+
137+ turn_context = TurnContext (adapter , ACTIVITY )
138+
139+ try :
140+ await TeamsInfo .get_team_details (turn_context )
141+ except TypeError :
142+ pass
143+ else :
144+ assert False , "should have raise TypeError"
145+
146+ async def test_get_team_channels_without_team_id (self ):
147+ def create_conversation ():
148+ pass
149+
150+ adapter = SimpleAdapterWithCreateConversation (
151+ call_create_conversation = create_conversation
152+ )
153+
154+ turn_context = TurnContext (adapter , ACTIVITY )
155+
156+ try :
157+ await TeamsInfo .get_team_channels (turn_context )
158+ except TypeError :
159+ pass
160+ else :
161+ assert False , "should have raise TypeError"
162+
163+ async def test_get_paged_team_members_without_team_id (self ):
164+ def create_conversation ():
165+ pass
166+
167+ adapter = SimpleAdapterWithCreateConversation (
168+ call_create_conversation = create_conversation
169+ )
170+
171+ turn_context = TurnContext (adapter , ACTIVITY )
172+
173+ try :
174+ await TeamsInfo .get_paged_team_members (turn_context )
175+ except TypeError :
176+ pass
177+ else :
178+ assert False , "should have raise TypeError"
179+
180+ async def test_get_team_members_without_team_id (self ):
181+ def create_conversation ():
182+ pass
183+
184+ adapter = SimpleAdapterWithCreateConversation (
185+ call_create_conversation = create_conversation
186+ )
187+
188+ turn_context = TurnContext (adapter , ACTIVITY )
189+
190+ try :
191+ await TeamsInfo .get_team_member (turn_context )
192+ except TypeError :
193+ pass
194+ else :
195+ assert False , "should have raise TypeError"
196+
197+ async def test_get_team_members_without_member_id (self ):
198+ def create_conversation ():
199+ pass
113200
201+ adapter = SimpleAdapterWithCreateConversation (
202+ call_create_conversation = create_conversation
203+ )
204+
205+ turn_context = TurnContext (adapter , ACTIVITY )
206+
207+ try :
208+ await TeamsInfo .get_team_member (turn_context , "teamId123" )
209+ except TypeError :
210+ pass
211+ else :
212+ assert False , "should have raise TypeError"
213+
214+
114215class TestTeamsActivityHandler (TeamsActivityHandler ):
115216 async def on_turn (self , turn_context : TurnContext ):
116217 await super ().on_turn (turn_context )
0 commit comments