Add tests for searx.engines.(dummy|github)
This commit is contained in:
		
							parent
							
								
									233599ae5a
								
							
						
					
					
						commit
						f705800612
					
				
							
								
								
									
										0
									
								
								searx/tests/engines/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								searx/tests/engines/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										26
									
								
								searx/tests/engines/test_dummy.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								searx/tests/engines/test_dummy.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| from searx.engines import dummy | ||||
| from searx.testing import SearxTestCase | ||||
| 
 | ||||
| 
 | ||||
| class TestDummyEngine(SearxTestCase): | ||||
| 
 | ||||
|     def test_request(self): | ||||
|         test_params = [ | ||||
|             [1, 2, 3], | ||||
|             ['a'], | ||||
|             [], | ||||
|             1 | ||||
|         ] | ||||
|         for params in test_params: | ||||
|             self.assertEqual(dummy.request(None, params), params) | ||||
| 
 | ||||
|     def test_response(self): | ||||
|         responses = [ | ||||
|             None, | ||||
|             [], | ||||
|             True, | ||||
|             dict(), | ||||
|             tuple() | ||||
|         ] | ||||
|         for response in responses: | ||||
|             self.assertEqual(dummy.response(response), []) | ||||
							
								
								
									
										61
									
								
								searx/tests/engines/test_github.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								searx/tests/engines/test_github.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,61 @@ | ||||
| from collections import defaultdict | ||||
| import mock | ||||
| from searx.engines import github | ||||
| from searx.testing import SearxTestCase | ||||
| 
 | ||||
| 
 | ||||
| class TestGitHubEngine(SearxTestCase): | ||||
| 
 | ||||
|     def test_request(self): | ||||
|         query = 'test_query' | ||||
|         params = github.request(query, defaultdict(dict)) | ||||
|         self.assertTrue('url' in params) | ||||
|         self.assertTrue(query in params['url']) | ||||
|         self.assertTrue('github.com' in params['url']) | ||||
|         self.assertEqual(params['headers']['Accept'], github.accept_header) | ||||
| 
 | ||||
|     def test_response(self): | ||||
|         self.assertRaises(AttributeError, github.response, None) | ||||
|         self.assertRaises(AttributeError, github.response, []) | ||||
|         self.assertRaises(AttributeError, github.response, '') | ||||
|         self.assertRaises(AttributeError, github.response, '[]') | ||||
| 
 | ||||
|         response = mock.Mock(text='{}') | ||||
|         self.assertEqual(github.response(response), []) | ||||
| 
 | ||||
|         response = mock.Mock(text='{"items": []}') | ||||
|         self.assertEqual(github.response(response), []) | ||||
| 
 | ||||
|         json = """ | ||||
|         { | ||||
|             "items": [ | ||||
|                 { | ||||
|                     "name": "title", | ||||
|                     "html_url": "url", | ||||
|                     "description": "" | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|         """ | ||||
|         response = mock.Mock(text=json) | ||||
|         results = github.response(response) | ||||
|         self.assertEqual(type(results), list) | ||||
|         self.assertEqual(len(results), 1) | ||||
|         self.assertEqual(results[0]['title'], 'title') | ||||
|         self.assertEqual(results[0]['url'], 'url') | ||||
|         self.assertEqual(results[0]['content'], '') | ||||
| 
 | ||||
|         json = """ | ||||
|         { | ||||
|             "items": [ | ||||
|                 { | ||||
|                     "name": "title", | ||||
|                     "html_url": "url", | ||||
|                     "description": "desc" | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|         """ | ||||
|         response = mock.Mock(text=json) | ||||
|         results = github.response(response) | ||||
|         self.assertEqual(results[0]['content'], "desc") | ||||
							
								
								
									
										2
									
								
								searx/tests/test_engines.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								searx/tests/test_engines.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| from searx.tests.engines.test_dummy import *  # noqa | ||||
| from searx.tests.engines.test_github import *  # noqa | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user