| 
									
										
										
										
											2022-11-21 23:55:04 +01:00
										 |  |  | # SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							| 
									
										
										
										
											2024-03-11 14:06:26 +01:00
										 |  |  | # pylint: disable=missing-module-docstring | 
					
						
							| 
									
										
										
										
											2022-11-21 23:55:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-24 05:37:30 +02:00
										 |  |  | from parameterized import parameterized | 
					
						
							| 
									
										
										
										
											2022-11-21 23:55:04 +01:00
										 |  |  | from tests import SearxTestCase | 
					
						
							|  |  |  | import searx.exceptions | 
					
						
							|  |  |  | from searx import get_setting | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 14:06:26 +01:00
										 |  |  | class TestExceptions(SearxTestCase):  # pylint: disable=missing-class-docstring | 
					
						
							| 
									
										
										
										
											2024-09-24 05:37:30 +02:00
										 |  |  |     @parameterized.expand( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             searx.exceptions.SearxEngineAccessDeniedException, | 
					
						
							|  |  |  |             searx.exceptions.SearxEngineCaptchaException, | 
					
						
							|  |  |  |             searx.exceptions.SearxEngineTooManyRequestsException, | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     def test_default_suspend_time(self, exception): | 
					
						
							|  |  |  |         with self.assertRaises(exception) as e: | 
					
						
							|  |  |  |             raise exception() | 
					
						
							| 
									
										
										
										
											2022-11-21 23:55:04 +01:00
										 |  |  |         self.assertEqual( | 
					
						
							|  |  |  |             e.exception.suspended_time, | 
					
						
							| 
									
										
										
										
											2024-09-24 05:37:30 +02:00
										 |  |  |             get_setting(exception.SUSPEND_TIME_SETTING), | 
					
						
							| 
									
										
										
										
											2022-11-21 23:55:04 +01:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-24 05:37:30 +02:00
										 |  |  |     @parameterized.expand( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             searx.exceptions.SearxEngineAccessDeniedException, | 
					
						
							|  |  |  |             searx.exceptions.SearxEngineCaptchaException, | 
					
						
							|  |  |  |             searx.exceptions.SearxEngineTooManyRequestsException, | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     def test_custom_suspend_time(self, exception): | 
					
						
							|  |  |  |         with self.assertRaises(exception) as e: | 
					
						
							|  |  |  |             raise exception(suspended_time=1337) | 
					
						
							| 
									
										
										
										
											2022-11-21 23:55:04 +01:00
										 |  |  |         self.assertEqual(e.exception.suspended_time, 1337) |