Exemplo n.º 1
0
def test_webhooks_integration():
    bot = MockBot()
    called_with = None

    @bot.command(r"/echo (.+)")
    def echo(chat, match):
        nonlocal called_with
        called_with = match.group(1)
        # Let's check sender repr as well
        assert repr(chat.sender) == "John"

    bot.set_webhook(webhook_url)
    assert "setWebhook" in bot.calls

    thread = Thread(target=bot_loop, args=[bot], daemon=True)
    thread.start()
    server_started.wait()

    update = {
        "update_id": 0,
        "message": {
            "message_id": 0,
            "from": {
                "first_name": "John"
            },
            "chat": {
                "id": 0,
                "type": "private"
            },
            "text": "/echo foo",
        },
    }

    import requests

    requests.post(webhook_url, json=update)
    assert called_with == "foo"
Exemplo n.º 2
0
def test_set_webhook():
    bot = MockBot()
    bot.set_webhook(webhook_url)
    assert "setWebhook" in bot.calls