Exemple #1
0
def test_build_module_payload(module: Module) -> None:
    command_name = 'command'
    description = 'description'
    action_name = 'action'
    view_name = 'view'

    @module.command(command_name,
                    description=description,
                    arg_descriptions={'req': description})
    def command(req: str, opt: str = '') -> None:
        pass

    @module.action(action_name)
    def action() -> None:
        pass

    @module.view(view_name)
    def view() -> None:
        pass

    payload = jsonable_encoder(module._build_module_payload())  # noqa
    assert payload == {
        'name':
        module.name,
        'description':
        module.description,
        'url':
        module.module_url,
        'commands': {
            command_name: {
                'name':
                command_name,
                'description':
                description,
                'arguments': [
                    {
                        'name': 'req',
                        'is_optional': False,
                        'description': description
                    },
                    {
                        'name': 'opt',
                        'is_optional': True,
                        'description': None
                    },
                ]
            }
        },
        'actions': [
            f'block_actions:{action_name}',
            f'view_submission:{view_name}',
        ]
    }
Exemple #2
0
async def test_hearbeat(module: Module, monkeypatch) -> None:
    payload = module._build_module_payload()  # noqa
    mock_api = AsyncMock(name='register_module_api_modules_post')

    monkeypatch.setattr(AsyncMetabotApi, 'register_module_api_modules_post',
                        mock_api)

    module._start_heartbeat()  # noqa
    assert isinstance(module._heartbeat, Task)  # noqa
    await sleep(0)
    mock_api.assert_awaited_with(payload)

    module._stop_heartbeat()  # noqa
    assert module._heartbeat is None  # noqa