|
1 | 1 | from typing import Dict |
2 | 2 | from telegram import User, Chat |
3 | 3 |
|
4 | | -CHAT_ID = 1 |
5 | 4 | BOT_ID = 5000000000 |
| 5 | + |
6 | 6 | BOT_TOKEN = f'5000000000:BBFJVn-zqLnqQGv_Vrg75aJ5rqppy410rm0' |
7 | 7 |
|
| 8 | +CHAT_ID = 1 |
| 9 | + |
| 10 | + |
| 11 | +class UserBase(User): |
| 12 | + |
| 13 | + def __init__(self, id: int = CHAT_ID): |
| 14 | + super().__init__( |
| 15 | + id, # id |
| 16 | + 'FN', # first_name |
| 17 | + False, # is_bot |
| 18 | + 'LN', # last_name |
| 19 | + 'user1', # username |
| 20 | + 'ru' # language_code |
| 21 | + ) |
| 22 | + |
| 23 | + |
| 24 | +class ChatBase(Chat): |
| 25 | + |
| 26 | + def __init__(self, id: int = CHAT_ID): |
| 27 | + super().__init__( |
| 28 | + id, |
| 29 | + 'private', # type |
| 30 | + None, # title |
| 31 | + 'user1', # username |
| 32 | + 'FN', # first_name |
| 33 | + 'LN', # last_name |
| 34 | + ) |
8 | 35 |
|
9 | | -user = User( |
10 | | - CHAT_ID, # id |
11 | | - 'FN', # first_name |
12 | | - False, # is_bot |
13 | | - 'LN', # last_name |
14 | | - 'user1', # username |
15 | | - 'ru') # language_code |
16 | 36 |
|
17 | 37 | virtual_bot = User( |
18 | 38 | BOT_ID, |
|
26 | 46 | False # supports_inline_queries |
27 | 47 | ) |
28 | 48 |
|
29 | | -chat = Chat( |
30 | | - CHAT_ID, |
31 | | - 'private', # type |
32 | | - None, # title |
33 | | - 'user1', # username |
34 | | - 'FN', # first_name |
35 | | - 'LN', # last_name |
36 | | -) |
37 | | - |
38 | 49 |
|
39 | | -class Client: |
| 50 | +class Tester: |
40 | 51 |
|
41 | | - def __init__(self, core): |
42 | | - self.chat_id = CHAT_ID |
| 52 | + def __init__(self, core, user, chat): |
43 | 53 | self.core = core |
44 | | - self.core.init_queue(self.chat_id) |
| 54 | + self.user = user |
| 55 | + self.chat = chat |
45 | 56 |
|
46 | 57 | def send_message(self, text: str) -> None: |
47 | 58 |
|
48 | 59 | self.core.user_send(virtual_bot.id, |
49 | | - user_from=user.to_dict(), |
50 | | - chat=chat.to_dict(), |
| 60 | + user_from=self.user.to_dict(), |
| 61 | + chat=self.chat.to_dict(), |
51 | 62 | text=text |
52 | 63 | ) |
53 | 64 |
|
54 | 65 | def send_command(self, command: str) -> None: |
55 | 66 |
|
56 | 67 | self.core.user_send_command(virtual_bot.id, |
57 | | - user_from=user.to_dict(), |
58 | | - chat=chat.to_dict(), |
| 68 | + user_from=self.user.to_dict(), |
| 69 | + chat=self.chat.to_dict(), |
59 | 70 | command=command |
60 | 71 | ) |
61 | 72 |
|
62 | 73 | def get_message(self, timeout=2.0) -> Dict: |
63 | | - messages = self.core.get_updates(self.chat_id, timeout) |
| 74 | + messages = self.core.get_updates(self.user.id, timeout) |
64 | 75 | if messages: |
65 | 76 | return messages[0]['message'] |
0 commit comments