Skip to content

Fixes #655 #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions libraries/botbuilder-core/tests/simple_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
# Licensed under the MIT License.

import unittest
from typing import List
from typing import List, Tuple, Awaitable, Callable
from botbuilder.core import BotAdapter, TurnContext
from botbuilder.schema import Activity, ConversationReference, ResourceResponse
from botbuilder.schema import (
Activity,
ConversationReference,
ResourceResponse,
ConversationParameters,
)


class SimpleAdapter(BotAdapter):
# pylint: disable=unused-argument

def __init__(self, call_on_send=None, call_on_update=None, call_on_delete=None):
def __init__(
self,
call_on_send=None,
call_on_update=None,
call_on_delete=None,
call_create_conversation=None,
):
super(SimpleAdapter, self).__init__()
self.test_aux = unittest.TestCase("__init__")
self._call_on_send = call_on_send
self._call_on_update = call_on_update
self._call_on_delete = call_on_delete
self._call_create_conversation = call_create_conversation

async def delete_activity(
self, context: TurnContext, reference: ConversationReference
Expand Down Expand Up @@ -46,6 +58,15 @@ async def send_activities(

return responses

async def create_conversation(
self,
reference: ConversationReference,
logic: Callable[[TurnContext], Awaitable] = None,
conversation_parameters: ConversationParameters = None,
) -> Tuple[ConversationReference, str]:
if self._call_create_conversation is not None:
self._call_create_conversation()

async def update_activity(self, context: TurnContext, activity: Activity):
self.test_aux.assertIsNotNone(
activity, "SimpleAdapter.update_activity: missing activity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
# Licensed under the MIT License.

import unittest
from typing import List
from typing import List, Tuple, Awaitable, Callable
from botbuilder.core import BotAdapter, TurnContext
from botbuilder.schema import Activity, ConversationReference, ResourceResponse
from botbuilder.schema import (
Activity,
ConversationReference,
ResourceResponse,
ConversationParameters,
)


class SimpleAdapter(BotAdapter):
class SimpleAdapterWithCreateConversation(BotAdapter):
# pylint: disable=unused-argument

def __init__(self, call_on_send=None, call_on_update=None, call_on_delete=None):
super(SimpleAdapter, self).__init__()
def __init__(
self,
call_on_send=None,
call_on_update=None,
call_on_delete=None,
call_create_conversation=None,
):
super(SimpleAdapterWithCreateConversation, self).__init__()
self.test_aux = unittest.TestCase("__init__")
self._call_on_send = call_on_send
self._call_on_update = call_on_update
self._call_on_delete = call_on_delete
self._call_create_conversation = call_create_conversation

async def delete_activity(
self, context: TurnContext, reference: ConversationReference
Expand Down Expand Up @@ -46,6 +58,17 @@ async def send_activities(

return responses

async def create_conversation(
self,
reference: ConversationReference,
logic: Callable[[TurnContext], Awaitable] = None,
conversation_parameters: ConversationParameters = None,
) -> Tuple[ConversationReference, str]:
if self._call_create_conversation is not None:
self._call_create_conversation()
ref = ConversationReference(activity_id="new_conversation_id")
return (ref, "reference123")

async def update_activity(self, context: TurnContext, activity: Activity):
self.test_aux.assertIsNotNone(
activity, "SimpleAdapter.update_activity: missing activity"
Expand All @@ -57,4 +80,4 @@ async def update_activity(self, context: TurnContext, activity: Activity):

async def process_request(self, activity, handler):
context = TurnContext(self, activity)
return self.run_pipeline(context, handler)
return await self.run_pipeline(context, handler)
51 changes: 51 additions & 0 deletions libraries/botbuilder-core/tests/teams/test_teams_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import aiounittest


from botbuilder.core import TurnContext, MessageFactory
from botbuilder.core.teams import TeamsInfo, TeamsActivityHandler
from botbuilder.schema import Activity
from botbuilder.schema.teams import TeamsChannelData, TeamInfo
from botframework.connector import Channels
from simple_adapter_with_create_conversation import SimpleAdapterWithCreateConversation


class TestTeamsInfo(aiounittest.AsyncTestCase):
async def test_send_message_to_teams(self):
def create_conversation():
pass

adapter = SimpleAdapterWithCreateConversation(
call_create_conversation=create_conversation
)

activity = Activity(
type="message",
text="test_send_message_to_teams_channel",
channel_id=Channels.ms_teams,
service_url="https://example.org",
channel_data=TeamsChannelData(team=TeamInfo(id="team-id")),
)
turn_context = TurnContext(adapter, activity)
handler = TestTeamsActivityHandler()
await handler.on_turn(turn_context)


class TestTeamsActivityHandler(TeamsActivityHandler):
async def on_turn(self, turn_context: TurnContext):
super().on_turn(turn_context)

if turn_context.activity.text == "test_send_message_to_teams_channel":
await self.call_send_message_to_teams(turn_context)

async def call_send_message_to_teams(self, turn_context: TurnContext):
msg = MessageFactory.text("call_send_message_to_teams")
channel_id = "teams_channel_123"
reference = await TeamsInfo.send_message_to_teams_channel(
turn_context, msg, channel_id
)

assert reference[0].activity_id == "new_conversation_id"
assert reference[1] == "reference123"