-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_run_handlers.py
More file actions
136 lines (104 loc) · 3.38 KB
/
test_run_handlers.py
File metadata and controls
136 lines (104 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import asyncio
import os
import json
from KrisBot import (
start,
handle_text,
handle_email,
handle_phone,
add_social_media,
scrape_tiktok,
scrape_instagram,
scrape_facebook,
help_command,
USER_DATA_FILE,
load_user_data,
save_user_data,
)
class MockMessage:
def __init__(self, text=""):
self.text = text
async def reply_text(self, txt):
print("BOT reply_text:", txt)
async def reply_html(self, txt):
print("BOT reply_html:", txt)
class MockUser:
def __init__(self, user_id, name="TestUser"):
self.id = user_id
self._name = name
def mention_html(self):
return f"<a href=\"tg://user?id={self.id}\">{self._name}</a>"
class MockUpdate:
def __init__(self, user_id, text=""):
self.effective_user = MockUser(user_id)
self.message = MockMessage(text)
class MockContext:
pass
async def run_comprehensive_tests():
print("=== Comprehensive Testing of KrisBot Functionality ===\n")
# Test 1: Single User Full Flow
print("--- Test 1: Single User Full Flow ---")
user_id = 12345
ctx = MockContext()
print("1.1 Sending /start")
import asyncio
from KrisBot import (
start,
handle_text,
add_social_media,
scrape_tiktok,
scrape_instagram,
scrape_facebook,
)
class MockMessage:
def __init__(self, text=""):
self.text = text
async def reply_text(self, txt):
print("BOT reply_text:", txt)
async def reply_html(self, txt):
print("BOT reply_html:", txt)
class MockUser:
def __init__(self, user_id, name="TestUser"):
self.id = user_id
self._name = name
def mention_html(self):
return f"<a href=\"tg://user?id={self.id}\">{self._name}</a>"
class MockUpdate:
def __init__(self, user_id, text=""):
self.effective_user = MockUser(user_id)
self.message = MockMessage(text)
class MockContext:
pass
async def run_sequence():
user_id = 12345
ctx = MockContext()
print("--- Sending /start ---")
upd = MockUpdate(user_id)
await start(upd, ctx)
print("--- Sending email text ---")
upd = MockUpdate(user_id, text="user@example.com")
await handle_text(upd, ctx)
print("--- Sending phone text ---")
upd = MockUpdate(user_id, text="+11234567890")
await handle_text(upd, ctx)
print("--- Sending /tiktok command ---")
upd = MockUpdate(user_id, text="/tiktok")
await scrape_tiktok(upd, ctx)
print("--- Adding new platform via /add then name ---")
upd = MockUpdate(user_id, text="/add")
await add_social_media(upd, ctx)
upd = MockUpdate(user_id, text="LinkedIn")
await handle_text(upd, ctx)
print("--- List of other commands behavior ---")
await scrape_instagram(upd, ctx)
await scrape_facebook(upd, ctx)
if __name__ == '__main__':
asyncio.run(run_sequence())
await add_social_media(upd, ctx)
upd = MockUpdate(user_id, text="LinkedIn")
await handle_text(upd, ctx)
print("--- List of other commands behavior ---")
await scrape_instagram(upd, ctx)
await scrape_facebook(upd, ctx)
if __name__ == '__main__':
asyncio.run(run_sequence())