예제 #1
0
async def test_connect_clients():
    bot = MockBot()
    conn = MockConn()
    bot.connections = {"foo": conn}
    future = bot.loop.create_future()
    future.set_result(True)
    conn.try_connect.return_value = future
    bot.plugin_manager.load_all = load_mock = MagicMock()
    load_mock.return_value = future
    await CloudBot._init_routine(bot)
    assert load_mock.mock_calls == [call(str(bot.base_dir / "plugins"))]
    conn.try_connect.assert_called()
예제 #2
0
    async def test_conn_not_ready(self, mock_db, setup_db, refresh_mods, freeze_time):
        bot = MockBot({})
        mock_conn = MagicMock()
        mock_conn.name = "test"
        mock_conn.ready = False
        bot.connections = {mock_conn.name: mock_conn}

        await self.check_reminders(mock_db, bot)

        assert mock_conn.message.mock_calls == []

        assert mock_db.get_data(remind.table) == [
            ('test', 'user', self.set_time, '#chan', 'a reminder', self.remind_time)
        ]
예제 #3
0
    async def test_normal(self, mock_db, setup_db, refresh_mods, freeze_time):
        bot = MockBot({})
        mock_conn = MagicMock()
        mock_conn.name = "test"
        mock_conn.ready = True
        bot.connections = {mock_conn.name: mock_conn}

        await self.check_reminders(mock_db, bot)

        assert mock_conn.message.mock_calls == [
            call('user', 'user, you have a reminder from \x0260 minutes\x0f ago!'),
            call('user', '"a reminder"'),
        ]

        assert mock_db.get_data(remind.table) == []
예제 #4
0
    async def test_late(self, mock_db, setup_db, refresh_mods, freeze_time):
        bot = MockBot({})
        mock_conn = MagicMock()
        mock_conn.name = "test"
        mock_conn.ready = True
        bot.connections = {mock_conn.name: mock_conn}

        with self.set_delay(40 * minute):
            await self.check_reminders(mock_db, bot)

        assert mock_conn.message.mock_calls == [
            call('user', 'user, you have a reminder from \x0260 minutes\x0f ago!'),
            call('user', '"a reminder"'),
            call(
                'user',
                "(I'm sorry for delivering this message \x0245 minutes\x0f late, "
                "it seems I was unable to deliver it on time)",
            ),
        ]

        assert mock_db.get_data(remind.table) == []
예제 #5
0
async def test_reload_config():
    bot = MockBot()
    conn = MockConn()
    bot.connections = {"foo": conn}
    bot.config.load_config = MagicMock()
    runs = []

    @hook.config()
    @hook.config()
    async def coro(hook):
        runs.append(hook)

    plugin = MagicMock()
    config_hook = ConfigHook(plugin, hook._get_hook(coro, "config"))

    bot.plugin_manager.config_hooks.append(config_hook)

    bot.config.load_config.assert_not_called()
    await CloudBot.reload_config(bot)
    conn.reload.assert_called()
    bot.config.load_config.assert_called()
    assert runs == [config_hook]