-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
volta_cabral
committed
Mar 20, 2024
1 parent
80f2332
commit 6af246e
Showing
10 changed files
with
661 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pytest | ||
from unittest.mock import AsyncMock, Mock | ||
from botgen.adapters import WebAdapter | ||
from botbuilder.schema import Activity, ConversationReference, ResourceResponse | ||
from botbuilder.core import TurnContext | ||
|
||
@pytest.fixture | ||
def web_adapter(): | ||
return WebAdapter() | ||
|
||
def test_activity_to_message(web_adapter): | ||
activity = Activity(type="message", text="Test message") | ||
message = web_adapter.activity_to_message(activity) | ||
assert message.type == activity.type | ||
assert message.text == activity.text | ||
|
||
@pytest.mark.asyncio | ||
async def test_send_activities_webhook(web_adapter): | ||
context = Mock() | ||
context.activity.channel_id = "websocket" | ||
context.turn_state.get.return_value = None | ||
activities = [Activity(type="message", text="Test message")] | ||
|
||
with pytest.raises(NotImplementedError): | ||
await web_adapter.send_activities(context, activities) | ||
|
||
@pytest.mark.asyncio | ||
async def test_update_activity(web_adapter): | ||
context = Mock() | ||
activity = Mock() | ||
with pytest.raises(NotImplementedError): | ||
await web_adapter.update_activity(context, activity) | ||
|
||
@pytest.mark.asyncio | ||
async def test_delete_activity(web_adapter): | ||
context = Mock() | ||
reference = Mock() | ||
with pytest.raises(NotImplementedError): | ||
await web_adapter.delete_activity(context, reference) | ||
|
||
@pytest.mark.asyncio | ||
async def test_process_activity(web_adapter): | ||
request = Mock() | ||
request.json = AsyncMock(return_value={"type": "message", "text": "Test message", "user": "user_id"}) | ||
logic_callback = AsyncMock() | ||
response = await web_adapter.process_activity(request, logic_callback) | ||
assert response == None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
from unittest.mock import Mock, AsyncMock | ||
from botgen.bot_worker import BotWorker | ||
from botbuilder.schema import Activity | ||
from botbuilder.core import TurnContext | ||
|
||
@pytest.fixture | ||
def bot_worker(): | ||
# Mock Bot and config | ||
bot_mock = Mock() | ||
config = {"context": Mock()} | ||
return BotWorker(bot_mock, config) | ||
|
||
def test_get_controller(bot_worker): | ||
controller = bot_worker.get_controller() | ||
assert controller == bot_worker._controller | ||
|
||
def test_get_config(bot_worker): | ||
config = bot_worker.get_config() | ||
assert config == bot_worker._config | ||
|
||
@pytest.mark.asyncio | ||
async def test_say(bot_worker): | ||
# Mock the context's send_activity method | ||
bot_worker._config["context"].send_activity = AsyncMock() | ||
|
||
message = "Test message" | ||
await bot_worker.say(message) | ||
|
||
bot_worker._config["context"].send_activity.assert_called_once() | ||
|
||
@pytest.mark.asyncio | ||
async def test_reply(bot_worker): | ||
# Mock methods and objects needed for reply | ||
activity = Activity(type="message", text="Reply message", channel_data={}) | ||
bot_worker.ensure_message_format = AsyncMock(return_value=activity) | ||
TurnContext.get_conversation_reference = Mock(return_value={"conversation": {"id": "123"}}) | ||
TurnContext.apply_conversation_reference = Mock(return_value=activity) | ||
bot_worker.say = AsyncMock() | ||
|
||
message_src = Mock() | ||
message_src.incoming_message = Mock() | ||
message_resp = "Replying to the message" | ||
|
||
await bot_worker.reply(message_src, message_resp) | ||
|
||
bot_worker.ensure_message_format.assert_called_once_with(message=message_resp) | ||
TurnContext.get_conversation_reference.assert_called_once_with(message_src.incoming_message) | ||
TurnContext.apply_conversation_reference.assert_called_once_with(activity, {"conversation": {"id": "123"}}) | ||
bot_worker.say.assert_called_once_with(activity) | ||
|
||
@pytest.mark.asyncio | ||
async def test_ensure_message_format_string(bot_worker): | ||
message = "Test message" | ||
activity = await bot_worker.ensure_message_format(message) | ||
assert isinstance(activity, Activity) | ||
assert activity.type == "message" | ||
assert activity.text == message | ||
|
||
@pytest.mark.asyncio | ||
async def test_ensure_message_format_message_object(bot_worker): | ||
message = Mock() | ||
message.__dict__ = {"type": "test", "text": "Test message"} | ||
activity = await bot_worker.ensure_message_format(message) | ||
assert isinstance(activity, Activity) | ||
assert activity.type == message.type | ||
assert activity.text == message.text | ||
|
||
if __name__ == '__main__': | ||
pytest.main() |
Oops, something went wrong.