|
| 1 | +from unittest.mock import MagicMock, patch |
| 2 | + |
| 3 | +import pytest |
| 4 | +from csp import ts |
| 5 | +from csp.impl.wiring import Edge |
| 6 | +from csp_adapter_discord import DiscordAdapterConfig |
| 7 | +from csp_adapter_slack import SlackAdapterConfig |
| 8 | + |
| 9 | +from csp_bot import Bot, BotCommand, BotConfig, Channels, DiscordConfig, Message, SlackConfig |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture(scope="session") |
| 13 | +def bot_config(): |
| 14 | + return BotConfig( |
| 15 | + discord_config=DiscordConfig( |
| 16 | + bot_name="test_bot", |
| 17 | + adapter_config=DiscordAdapterConfig( |
| 18 | + token="1" * 72, |
| 19 | + ), |
| 20 | + ), |
| 21 | + slack_config=SlackConfig( |
| 22 | + bot_name="test_bot", |
| 23 | + adapter_config=SlackAdapterConfig( |
| 24 | + app_token="xapp-blerg", |
| 25 | + bot_token="xoxb-blerg", |
| 26 | + ), |
| 27 | + ), |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +@pytest.fixture(scope="session") |
| 32 | +def bot(bot_config): |
| 33 | + bot = Bot(config=bot_config) |
| 34 | + channels_mock = MagicMock(spec=Channels) |
| 35 | + |
| 36 | + def side_effect(name): |
| 37 | + if name == "commands": |
| 38 | + return Edge(ts[BotCommand], None, 0) |
| 39 | + raise Exception(name) |
| 40 | + |
| 41 | + channels_mock.get_channel.side_effect = side_effect |
| 42 | + with ( |
| 43 | + patch("csp.unroll", return_value=Edge(ts[Message], None, 0)), |
| 44 | + patch("csp.flatten", return_value=Edge(ts[Message], None, 0)), |
| 45 | + patch("csp.timer", return_value=Edge(ts[Message], None, 0)), |
| 46 | + patch("csp_adapter_discord.adapter.DiscordAdapterManager.publish"), |
| 47 | + patch("csp_adapter_slack.adapter.SlackAdapterManager.publish"), |
| 48 | + ): |
| 49 | + bot.connect(channels=channels_mock) |
| 50 | + yield bot |
0 commit comments