forked from zaclys/searxng
		
	[fix] webapp tests
This commit is contained in:
		
							parent
							
								
									37c58fd9ca
								
							
						
					
					
						commit
						80ba6f22fa
					
				
					 1 changed files with 9 additions and 33 deletions
				
			
		| 
						 | 
					@ -2,7 +2,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
from urlparse import ParseResult
 | 
					from urlparse import ParseResult
 | 
				
			||||||
from mock import patch
 | 
					 | 
				
			||||||
from searx import webapp
 | 
					from searx import webapp
 | 
				
			||||||
from searx.testing import SearxTestCase
 | 
					from searx.testing import SearxTestCase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +32,11 @@ class ViewsTestCase(SearxTestCase):
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def search_mock(search_self, *args):
 | 
				
			||||||
 | 
					            search_self.results = self.test_results
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        webapp.Search.search = search_mock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.maxDiff = None  # to see full diffs
 | 
					        self.maxDiff = None  # to see full diffs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_index_empty(self):
 | 
					    def test_index_empty(self):
 | 
				
			||||||
| 
						 | 
					@ -40,14 +44,7 @@ class ViewsTestCase(SearxTestCase):
 | 
				
			||||||
        self.assertEqual(result.status_code, 200)
 | 
					        self.assertEqual(result.status_code, 200)
 | 
				
			||||||
        self.assertIn('<div class="title"><h1>searx</h1></div>', result.data)
 | 
					        self.assertIn('<div class="title"><h1>searx</h1></div>', result.data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @patch('searx.search.Search.search')
 | 
					    def test_index_html(self):
 | 
				
			||||||
    def test_index_html(self, search):
 | 
					 | 
				
			||||||
        search.return_value = (
 | 
					 | 
				
			||||||
            self.test_results,
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set()
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        result = self.app.post('/', data={'q': 'test'})
 | 
					        result = self.app.post('/', data={'q': 'test'})
 | 
				
			||||||
        self.assertIn(
 | 
					        self.assertIn(
 | 
				
			||||||
            '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz">Second <span class="highlight">Test</span></a></h3>',  # noqa
 | 
					            '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz">Second <span class="highlight">Test</span></a></h3>',  # noqa
 | 
				
			||||||
| 
						 | 
					@ -58,14 +55,7 @@ class ViewsTestCase(SearxTestCase):
 | 
				
			||||||
            result.data
 | 
					            result.data
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @patch('searx.search.Search.search')
 | 
					    def test_index_json(self):
 | 
				
			||||||
    def test_index_json(self, search):
 | 
					 | 
				
			||||||
        search.return_value = (
 | 
					 | 
				
			||||||
            self.test_results,
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set()
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        result = self.app.post('/', data={'q': 'test', 'format': 'json'})
 | 
					        result = self.app.post('/', data={'q': 'test', 'format': 'json'})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        result_dict = json.loads(result.data)
 | 
					        result_dict = json.loads(result.data)
 | 
				
			||||||
| 
						 | 
					@ -76,14 +66,7 @@ class ViewsTestCase(SearxTestCase):
 | 
				
			||||||
        self.assertEqual(
 | 
					        self.assertEqual(
 | 
				
			||||||
            result_dict['results'][0]['url'], 'http://first.test.xyz')
 | 
					            result_dict['results'][0]['url'], 'http://first.test.xyz')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @patch('searx.search.Search.search')
 | 
					    def test_index_csv(self):
 | 
				
			||||||
    def test_index_csv(self, search):
 | 
					 | 
				
			||||||
        search.return_value = (
 | 
					 | 
				
			||||||
            self.test_results,
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set()
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
 | 
					        result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(
 | 
					        self.assertEqual(
 | 
				
			||||||
| 
						 | 
					@ -93,14 +76,7 @@ class ViewsTestCase(SearxTestCase):
 | 
				
			||||||
            result.data
 | 
					            result.data
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @patch('searx.search.Search.search')
 | 
					    def test_index_rss(self):
 | 
				
			||||||
    def test_index_rss(self, search):
 | 
					 | 
				
			||||||
        search.return_value = (
 | 
					 | 
				
			||||||
            self.test_results,
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set(),
 | 
					 | 
				
			||||||
            set()
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
 | 
					        result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertIn(
 | 
					        self.assertIn(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue