diff --git a/history.txt b/history.txt index f7b3d60..d204c90 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,7 @@ ++ Add properties: `tele_message`, `group_message`. + ++ Add methods: `send2chat`, `send_command`, `tg_button`. + 14.05.2023 ver.1.1 ------------------ diff --git a/tester_vbot3/__init__.py b/tester_vbot3/__init__.py index f250952..59a4a48 100644 --- a/tester_vbot3/__init__.py +++ b/tester_vbot3/__init__.py @@ -1,5 +1,6 @@ """Vbot3 tester.""" from telemulator3 import Telemulator, private_command, private_text +from telemulator3.update.message import Text, Command from tester_flask import TestFlask from test_helper_gae3 import TestGae3 @@ -34,6 +35,8 @@ class Vbot3Tester(TestFlask, TestGae3, Telemulator): teleuser = None private = None group = None + tele_message = None + group_message = None def init(self, flask_app, vbot3, bot_name, bot_username, queue_yaml_dir): """Init tests stuff.""" @@ -44,12 +47,30 @@ def init(self, flask_app, vbot3, bot_name, bot_username, queue_yaml_dir): self.teleuser = self.api.create_user('Test', 'User', language_code='en') self.private = self.teleuser.private() self.group = self.teleuser.create_group("Test group") + self.tele_message = Text(self.private, self.teleuser, "Hello private!") + self.group_message = Text(self.group, self.teleuser, "Hello group!") def tearDown(self): """Clear tests.""" TestGae3.tear_down(self) super().tearDown() + def send2chat(self, chat, message): + """Send message to given chat.""" + with self.app.test_request_context(): + return chat.send(message) + + def send_command(self, chat, command, from_user=None, **kwargs): + """Send command to given chat.""" + from_user = from_user or self.teleuser + return self.send2chat(chat, Command(chat, from_user, command, **kwargs)) + + def tg_button(self, row, index=0, chat=None, user=None): + """Send custom keyboard item to chat.""" + chat = chat or self.private + user = user or self.teleuser + chat.keyboard.menu_item(user, index, row=row) + def private_command(self, cmd, from_user=None): """Call private command.""" from_user = from_user or self.teleuser