示例#1
0
async def test_get_compat_path(mocker: MockFixture, platform_paths):
    platform, in_path, expect_path = platform_paths
    mock_proc = mocker.AsyncMock()
    mock_proc.return_value.communicate.return_value = expect_path.encode(), ""
    mocker.patch.object(compat.asyncio, "create_subprocess_exec", mock_proc)
    ret_path = await compat.get_compat_path(in_path)
    assert ret_path == expect_path
    if platform == "Linux":
        mock_proc.assert_called_once()
    else:
        mock_proc.assert_not_called()
示例#2
0
async def test_get_redis_uses_os_variable(mocker: MockFixture):
    # GIVEN: Redis database URL
    FAKE_URL = "redis://*****:*****@hosthost.com:9870/"
    ENV_KEY = "REDISTOGO_URL"
    mocker.patch.dict(os.environ, {ENV_KEY: FAKE_URL})
    mock = mocker.AsyncMock()
    mocker.patch.object(aioredis, 'create_redis_pool', mock)
    # WHEN: get_redis() is called
    await get_redis()
    # THEN: it reads from os.environ.get('REDISTOGO_URL')
    mock.assert_called_with(FAKE_URL)
示例#3
0
async def test_goes_to_fallback_on_unknown_message(
        text, mocker: MockFixture, fake_vk_api_message_builder):
    # GIVEN: prepared bot
    from src.bot import bot
    # WHEN: bot receives a message with unknown command
    bot.api = fake_vk_api_message_builder(text=text)
    mock = mocker.AsyncMock()

    # THEN: bot calls fallback handler
    for handler in bot.labeler.message_view.handlers:
        if 'hello_admin' in str(handler):
            handler.handle = mock

    async for event in bot.polling.listen():
        # Придут ивенты из fake_vk_api_message_builder
        assert 'updates' in event
        for update in event['updates']:
            await bot.router.route(update, bot.api)
        # Но в конце бот будет бесконечно ждать новых сообщений
        # Это фиксится одним break
        break
    mock.assert_called_once()
示例#4
0
async def close_redis_mock(mocker: MockFixture):
    quit_mock = mocker.AsyncMock()
    # fakeredis does not support 'QUIT', so need to mock it
    mocker.patch.object(aioredis.Redis, 'quit', quit_mock)
    return quit_mock