async def test__on_process_message(self): mid_unique_id = UniqueIdMiddleware() data = dict() await mid_unique_id.on_process_message( message, data ) assert data[DATA_UNIQUE_ID_KEY] == TEMPLATE_UNIQUE_ID
from app.middlewares.unique_id import UniqueIdMiddleware from app.views import Cmds from app.views import ECmds import argparse parser = argparse.ArgumentParser() parser.add_argument("--cfg") args = parser.parse_args() setup = Setup(path=args.cfg) bot = Bot(token=setup.bot["token"], parse_mode=ParseMode.HTML) dp = Dispatcher(bot) dp.middleware.setup(GinoMiddleware(setup.database)) dp.middleware.setup(UniqueIdMiddleware()) logger = getLogger(__name__) # ----- cmd: start ----- # @dp.message_handler(commands=Cmds.START.get()) async def cmd_start(message: t.Message, unique_id): data = { "is_bot": message.from_user.is_bot, "unique_id": unique_id, "id": message.chat.id, "language": message.from_user.language_code, "datetime": message.date, "referral_id": message.get_args() or False }
async def test__on_process_message(message): data = {} unique_id_mdw = UniqueIdMiddleware() await unique_id_mdw.on_process_message(message, data) assert data.get("unique_id")
def test__make(message): UNIQUE_ID = f"{message.chat.id}-{message.message_id}" unique_id_mdw = UniqueIdMiddleware() unique_id = unique_id_mdw.make(message) assert unique_id == UNIQUE_ID
def test__make_unique_id(self): mid_unique_id = UniqueIdMiddleware() unique_id = mid_unique_id._make(message) assert unique_id == TEMPLATE_UNIQUE_ID
def test__unique_id_cls_is_sub_base_middleware(self): mid_unique_id = UniqueIdMiddleware() assert isinstance(mid_unique_id, BaseMiddleware)