summaryrefslogtreecommitdiff
path: root/tests/unit/test_webapp.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/test_webapp.py')
-rw-r--r--tests/unit/test_webapp.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 7dd465898..75a968ad8 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -75,8 +75,36 @@ class ViewsTestCase(SearxTestCase):
self.assertEqual(result.status_code, 200)
self.assertIn(b'<div class="title"><h1>searx</h1></div>', result.data)
- def test_index_html(self):
+ def test_index_html_post(self):
result = self.app.post('/', data={'q': 'test'})
+ self.assertEqual(result.status_code, 308)
+ self.assertEqual(result.location, 'http://localhost/search')
+
+ def test_index_html_get(self):
+ result = self.app.post('/?q=test')
+ self.assertEqual(result.status_code, 308)
+ self.assertEqual(result.location, 'http://localhost/search?q=test')
+
+ def test_search_empty_html(self):
+ result = self.app.post('/search', data={'q': ''})
+ self.assertEqual(result.status_code, 200)
+ self.assertIn(b'<div class="title"><h1>searx</h1></div>', result.data)
+
+ def test_search_empty_json(self):
+ result = self.app.post('/search', data={'q': '', 'format': 'json'})
+ self.assertEqual(result.status_code, 400)
+
+ def test_search_empty_csv(self):
+ result = self.app.post('/search', data={'q': '', 'format': 'csv'})
+ self.assertEqual(result.status_code, 400)
+
+ def test_search_empty_rss(self):
+ result = self.app.post('/search', data={'q': '', 'format': 'rss'})
+ self.assertEqual(result.status_code, 400)
+
+ def test_search_html(self):
+ result = self.app.post('/search', data={'q': 'test'})
+
self.assertIn(
b'<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/legacy/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz" rel="noreferrer">Second <span class="highlight">Test</span></a></h3>', # noqa
result.data
@@ -88,7 +116,10 @@ class ViewsTestCase(SearxTestCase):
def test_index_json(self):
result = self.app.post('/', data={'q': 'test', 'format': 'json'})
+ self.assertEqual(result.status_code, 308)
+ def test_search_json(self):
+ result = self.app.post('/search', data={'q': 'test', 'format': 'json'})
result_dict = json.loads(result.data.decode())
self.assertEqual('test', result_dict['query'])
@@ -98,6 +129,10 @@ class ViewsTestCase(SearxTestCase):
def test_index_csv(self):
result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
+ self.assertEqual(result.status_code, 308)
+
+ def test_search_csv(self):
+ result = self.app.post('/search', data={'q': 'test', 'format': 'csv'})
self.assertEqual(
b'title,url,content,host,engine,score,type\r\n'
@@ -108,6 +143,10 @@ class ViewsTestCase(SearxTestCase):
def test_index_rss(self):
result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
+ self.assertEqual(result.status_code, 308)
+
+ def test_index_rss(self):
+ result = self.app.post('/search', data={'q': 'test', 'format': 'rss'})
self.assertIn(
b'<description>Search results for "test" - searx</description>',