4
4
from app .app import handle_message
5
5
from app .core .models import UserState , URLQR , WifiQR , ContactQR
6
6
from app .qrcodegen import generate_wifi_qr , generate_contact_qr , generate_url_qr
7
- from pydantic import ValidationError
7
+
8
8
9
9
@pytest .mark .asyncio
10
10
async def test_handle_message_awaiting_url ():
@@ -32,6 +32,7 @@ async def test_handle_message_awaiting_url():
32
32
photo = actual_call , caption = "Here is your QR code!"
33
33
)
34
34
35
+
35
36
@pytest .mark .asyncio
36
37
async def test_handle_message_awaiting_url_invalid ():
37
38
@@ -41,13 +42,15 @@ async def test_handle_message_awaiting_url_invalid():
41
42
context .user_data = {"state" : UserState .AWAITING_URL }
42
43
test_url = "invalid-url.com"
43
44
update .message .text = test_url
44
-
45
+
45
46
await handle_message (update , context )
46
- assert ( context .user_data ["state" ]== UserState .AWAITING_URL )
47
- # Assert that the bot sends an error message
47
+ assert context .user_data ["state" ] == UserState .AWAITING_URL
48
+ # Assert that the bot sends an error message
48
49
update .message .reply_text .assert_called_once_with (
49
50
"❌ Invalid URL. Please send a valid URL starting with 'http://' or 'https://'."
50
51
)
52
+
53
+
51
54
@pytest .mark .asyncio
52
55
async def test_handle_message_awaiting_ssid ():
53
56
# Mock Update and Context
@@ -66,6 +69,8 @@ async def test_handle_message_awaiting_ssid():
66
69
67
70
# Assert that the state is updated
68
71
assert context .user_data ["state" ] == UserState .AWAITING_PASSWORD
72
+
73
+
69
74
@pytest .mark .asyncio
70
75
async def test_handle_message_awaiting_ssid_invalid ():
71
76
@@ -75,14 +80,15 @@ async def test_handle_message_awaiting_ssid_invalid():
75
80
context .user_data = {"state" : UserState .AWAITING_SSID }
76
81
test_ssid = "TestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSIDTestSSID"
77
82
update .message .text = test_ssid
78
-
83
+
79
84
await handle_message (update , context )
80
- assert ( context .user_data ["state" ]== UserState .AWAITING_SSID )
81
- # Assert that the bot sends an error message
85
+ assert context .user_data ["state" ] == UserState .AWAITING_SSID
86
+ # Assert that the bot sends an error message
82
87
update .message .reply_text .assert_called_once_with (
83
88
"❌ Invalid SSID. Please send a valid SSID (1-32 characters)."
84
89
)
85
90
91
+
86
92
@pytest .mark .asyncio
87
93
async def test_handle_message_awaiting_password ():
88
94
# Mock Update and Context
@@ -110,6 +116,8 @@ async def test_handle_message_awaiting_password():
110
116
assert context .user_data == {}
111
117
# Assert by content
112
118
assert update .message .reply_photo .call_count == 1
119
+
120
+
113
121
@pytest .mark .asyncio
114
122
async def test_handle_message_awaiting_password_invalid ():
115
123
@@ -119,14 +127,15 @@ async def test_handle_message_awaiting_password_invalid():
119
127
context .user_data = {"state" : UserState .AWAITING_PASSWORD , "ssid" : "TestSSID" }
120
128
test_password = "T"
121
129
update .message .text = test_password
122
-
130
+
123
131
await handle_message (update , context )
124
- assert ( context .user_data ["state" ]== UserState .AWAITING_PASSWORD )
125
- # Assert that the bot sends an error message
132
+ assert context .user_data ["state" ] == UserState .AWAITING_PASSWORD
133
+ # Assert that the bot sends an error message
126
134
update .message .reply_text .assert_called_once_with (
127
135
"❌ Invalid SSID or Password. Please send a valid SSID (1-32 characters) and a Valid Password between 8 and 63 characters."
128
136
)
129
137
138
+
130
139
@pytest .mark .asyncio
131
140
async def test_handle_message_awaiting_name ():
132
141
# Mock Update and Context
@@ -221,6 +230,7 @@ async def test_handle_message_awaiting_email():
221
230
assert context .user_data ["state" ] == UserState .AWAITING_COMPANY
222
231
assert context .user_data ["email" ] == test_email
223
232
233
+
224
234
@pytest .mark .asyncio
225
235
async def test_handle_message_awaiting_email_invalid ():
226
236
@@ -235,13 +245,15 @@ async def test_handle_message_awaiting_email_invalid():
235
245
}
236
246
test_email = "joelperez91.gmail.com"
237
247
update .message .text = test_email
238
-
248
+
239
249
await handle_message (update , context )
240
- assert ( context .user_data ["state" ]== UserState .AWAITING_EMAIL )
241
- # Assert that the bot sends an error message
250
+ assert context .user_data ["state" ] == UserState .AWAITING_EMAIL
251
+ # Assert that the bot sends an error message
242
252
update .message .reply_text .assert_called_once_with (
243
253
"❌ Invalid email. Please send a valid email address."
244
254
)
255
+
256
+
245
257
@pytest .mark .asyncio
246
258
async def test_handle_message_awaiting_company ():
247
259
# Mock Update and Context
@@ -290,7 +302,7 @@ async def test_handle_message_awaiting_title():
290
302
await handle_message (update , context )
291
303
292
304
# Assert that the bot asks for the website URL
293
- update .message .reply_text .assert_called_once_with ("Please send the URL 🔗:" )
305
+ update .message .reply_text .assert_called_once_with ("Please send the Website URL 🔗:" )
294
306
295
307
# Assert that the state is updated
296
308
assert context .user_data ["state" ] == UserState .AWAITING_WEBSITE
@@ -343,4 +355,3 @@ async def test_handle_message_awaiting_website():
343
355
)
344
356
# Assert that user data is cleared
345
357
assert context .user_data == {}
346
-
0 commit comments