import pytest
from aiotg import TgBot
from aiotg import MESSAGE_TYPES

API_TOKEN = "test_token"

def text_msg(text):
    return {
        "message_id": 0,
        "from": {},
        "chat": { "id": 0, "type": "private" },
        "text": text
    }

def test_command():
    bot = TgBot(API_TOKEN)
    called_with = None

    @bot.command(r"/echo (.+)")
    def echo(chat, match):
        nonlocal called_with
        called_with = match.group(1)

    bot._process_message(text_msg("/echo foo"))

    assert called_with == "foo"

def test_default():
    bot = TgBot(API_TOKEN)
    called_with = None

    @bot.default
    def default(chat, message):
        nonlocal called_with
        called_with = message["text"]

    bot._process_message(text_msg("foo bar"))

    assert called_with == "foo bar"

@@ -7,16 +7,31 @@
  pytest%0A
+import random%0A%0A
 from aio
@@ -108,39 +108,67 @@
 en%22%0A
-%0Adef text
+bot = TgBot(API_TOKEN)%0A%0Adef custom
 _msg(
-text
+msg
 ):%0A    
-return
+template =
  %7B%0A 
@@ -261,44 +261,68 @@
 e%22 %7D
-,
 %0A    
+%7D%0A
     
-%22
 te
-xt%22: text%0A    %7D
+mplate.update(msg)%0A    return template%0A
 %0A%0Adef te
 st_c
@@ -321,48 +321,83 @@
 f te
-st_command():%0A    bot = TgBot(API_TOKEN)
+xt_msg(text):%0A    return custom_msg(%7B %22text%22: text %7D)%0A%0A%0Adef test_command():
 %0A   
@@ -587,25 +587,24 @@
 echo foo%22))%0A
-%0A
     assert c
@@ -624,16 +624,17 @@
  %22foo%22%0A%0A
+%0A
 def test
@@ -649,35 +649,8 @@
 ():%0A
-    bot = TgBot(API_TOKEN)%0A
     
@@ -832,17 +832,16 @@
  bar%22))%0A
-%0A
     asse
@@ -868,8 +868,320 @@
 oo bar%22%0A
+%0A%0A@pytest.mark.parametrize(%22mt%22, MESSAGE_TYPES)%0Adef test_handle(mt):%0A    called_with = None%0A%0A    @bot.handle(mt)%0A    def handle(chat, media):%0A        nonlocal called_with%0A        called_with = media%0A%0A    value = random.random()%0A    bot._process_message(custom_msg(%7B mt: value %7D))%0A    assert called_with == value%0A

Add test for media handlers