Skip to content

Commit cc753e2

Browse files
committed
added test case
1 parent 9d09d2e commit cc753e2

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

release_notes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Release Notes
2-
## Version 2.4 - Date 5 May 2024
2+
## Version 2.4 - Date 6 May 2024
33
### Enhancement 🔥
44
- Clearer error messages for users
55

6+
### For Developer 🧑‍💻
7+
- Added more test case
8+
69
## Version 2.3.7 - Date 3 May 2024
710
### For Developer 🧑‍💻
811
- Add number of error users for /notifyall command

test/test_database.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from bot.database_service import firestore_service
2-
32
from unittest import TestCase
4-
3+
from bot.error_handler import DatabaseError
54

65
class TestFirestoreService(TestCase):
76
@classmethod
87
def setUpClass(cls):
98
super().setUpClass()
109
cls.db = firestore_service.FirestoreService()
1110
cls.telegram_id = "123456"
11+
cls.fake_telegram_id = "123"
1212
cls.sheet_id = "sheet123"
1313
cls.telegram_username = "test_user"
1414

@@ -19,9 +19,26 @@ def test_check_if_user_exists(self):
1919
# Assert
2020
self.assertTrue(user_exists)
2121

22+
23+
def test_check_if_user_dont_exists(self):
24+
# Act
25+
user_exists = self.db.check_if_user_exists(self.fake_telegram_id)
26+
27+
# Assert
28+
self.assertFalse(user_exists)
29+
2230
def test_get_user_sheet_id(self):
2331
# Act
2432
sheet_id = self.db.get_user_sheet_id(self.telegram_id, self.telegram_username)
2533

2634
# Assert
2735
self.assertEqual(sheet_id, self.sheet_id)
36+
37+
38+
def test_get_dont_exist_user_sheet_id(self):
39+
# Act & Assert
40+
with self.assertRaises(DatabaseError) as context:
41+
self.db.get_user_sheet_id(self.fake_telegram_id, self.telegram_username)
42+
43+
# Check if the error message is as expected
44+
self.assertIn("User does not exist", context.exception.extra_info)

test/test_errorhandler.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import unittest
2+
from unittest.mock import patch
3+
from bot.error_handler import GoogleSheetError, TelegramBotError, DatabaseError
4+
5+
class TestErrorHandling(unittest.TestCase):
6+
7+
def test_google_sheet_error_raises_correctly(self):
8+
# Define the message and extra_info
9+
message = "Test failure in Google Sheets"
10+
extra_info = "Invalid Range"
11+
12+
# Check if the exception is raised with the correct message
13+
with self.assertRaises(GoogleSheetError) as context:
14+
raise GoogleSheetError(message, extra_info)
15+
16+
# Verify that the message in the exception is as expected
17+
self.assertEqual(str(context.exception), f"GoogleSheetError: {message}")
18+
19+
def test_telegram_bot_error_raises_correctly(self):
20+
message = "Failed to send message"
21+
extra_info = "User not found"
22+
23+
with self.assertRaises(TelegramBotError) as context:
24+
raise TelegramBotError(message, extra_info)
25+
26+
self.assertEqual(str(context.exception), f"TelegramBotError: {message}")
27+
28+
def test_database_error_raises_correctly(self):
29+
message = "Database connection failed"
30+
extra_info = "Timeout occurred"
31+
32+
with self.assertRaises(DatabaseError) as context:
33+
raise DatabaseError(message, extra_info)
34+
35+
self.assertEqual(str(context.exception), f"DatabaseError: {message}")

0 commit comments

Comments
 (0)