DEV Community

William Rodriguez
William Rodriguez

Posted on

Testing bots without spamming chats: Mocking & enterprise test patterns.

Your CI/CD pipeline shouldn't fail because the Telegram API returned a 429 Too Many Requests during unit testing. wconnect's clean WMessage abstraction lets you test bot business logic entirely offline.

Here is how you implement Mocking & Enterprise Testing in production with wconnect:

from wconnect import WMessage

def my_business_logic(msg: WMessage) -> str:
    if msg.user_id != "6586101740":
        return "DENIED"
    return f"Processed: {msg.text.upper()}"

# Unit test without mock server or internet connection
def test_handler_authorization():
    # Synthetic message
    unauthorized = WMessage(chat_id=101, user_id=999, text="hello")
    assert my_business_logic(unauthorized) == "DENIED"

    authorized = WMessage(chat_id=101, user_id=6586101740, text="hello")
    assert my_business_logic(authorized) == "Processed: HELLO"
Enter fullscreen mode Exit fullscreen mode

Why This Matters:

  • Zero boilerplate decorators (@bot.on_command, @bot.on_message, @bot.consumer).
  • Stream binary files directly from RAM using WFile.
  • Non-blocking daemon poller with run_consumers(block=False).

Check out the repo on GitHub!

Top comments (0)