Skip to content

Commit

Permalink
Add properties and methods. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
vb64 authored May 16, 2023
1 parent 9ced9c8 commit 348b143
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
+ Add properties: `tele_message`, `group_message`.

+ Add methods: `send2chat`, `send_command`, `tg_button`.

14.05.2023 ver.1.1
------------------

Expand Down
21 changes: 21 additions & 0 deletions tester_vbot3/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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."""
Expand All @@ -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
Expand Down

0 comments on commit 348b143

Please sign in to comment.