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