From 52e615dede8538c36f569d2cf07835427a9a0db6 Mon Sep 17 00:00:00 2001
From: Adam Tauber
Date: Wed, 30 Nov 2016 18:43:03 +0100
Subject: [enh] py3 compatibility
---
tests/robot/__init__.py | 75 ++++++++++++++
tests/robot/test_basic.robot | 153 ----------------------------
tests/unit/engines/test_archlinux.py | 4 +-
tests/unit/engines/test_bing.py | 6 +-
tests/unit/engines/test_bing_news.py | 12 +--
tests/unit/engines/test_btdigg.py | 12 +--
tests/unit/engines/test_currency_convert.py | 4 +-
tests/unit/engines/test_digbt.py | 4 +-
tests/unit/engines/test_duckduckgo.py | 3 +-
tests/unit/engines/test_frinkiac.py | 5 +-
tests/unit/engines/test_gigablast.py | 1 +
tests/unit/engines/test_soundcloud.py | 2 +-
tests/unit/engines/test_startpage.py | 6 +-
tests/unit/engines/test_swisscows.py | 8 +-
tests/unit/engines/test_tokyotoshokan.py | 2 +-
tests/unit/engines/test_wikidata.py | 3 +-
tests/unit/engines/test_wikipedia.py | 18 ++--
tests/unit/engines/test_wolframalpha_api.py | 10 +-
tests/unit/test_plugins.py | 16 +--
tests/unit/test_utils.py | 8 +-
tests/unit/test_webapp.py | 46 ++++-----
21 files changed, 161 insertions(+), 237 deletions(-)
delete mode 100644 tests/robot/test_basic.robot
(limited to 'tests')
diff --git a/tests/robot/__init__.py b/tests/robot/__init__.py
index e69de29bb..038a3196f 100644
--- a/tests/robot/__init__.py
+++ b/tests/robot/__init__.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+
+from time import sleep
+
+url = "http://localhost:11111/"
+
+
+def test_index(browser):
+ # Visit URL
+ browser.visit(url)
+ assert browser.is_text_present('about')
+
+
+def test_404(browser):
+ # Visit URL
+ browser.visit(url + 'missing_link')
+ assert browser.is_text_present('Page not found')
+
+
+def test_about(browser):
+ browser.visit(url)
+ browser.click_link_by_text('about')
+ assert browser.is_text_present('Why use searx?')
+
+
+def test_preferences(browser):
+ browser.visit(url)
+ browser.click_link_by_text('preferences')
+ assert browser.is_text_present('Preferences')
+ assert browser.is_text_present('Cookies')
+
+ assert browser.is_element_present_by_xpath('//label[@for="checkbox_dummy"]')
+
+
+def test_preferences_engine_select(browser):
+ browser.visit(url)
+ browser.click_link_by_text('preferences')
+
+ assert browser.is_element_present_by_xpath('//a[@href="#tab_engine"]')
+ browser.find_by_xpath('//a[@href="#tab_engine"]').first.click()
+
+ assert not browser.find_by_xpath('//input[@id="engine_general_dummy__general"]').first.checked
+ browser.find_by_xpath('//label[@for="engine_general_dummy__general"]').first.check()
+ browser.find_by_xpath('//input[@value="save"]').first.click()
+
+ # waiting for the redirect - without this the test is flaky..
+ sleep(1)
+
+ browser.visit(url)
+ browser.click_link_by_text('preferences')
+ browser.find_by_xpath('//a[@href="#tab_engine"]').first.click()
+
+ assert browser.find_by_xpath('//input[@id="engine_general_dummy__general"]').first.checked
+
+
+def test_preferences_locale(browser):
+ browser.visit(url)
+ browser.click_link_by_text('preferences')
+
+ browser.select('locale', 'hu')
+ browser.find_by_xpath('//input[@value="save"]').first.click()
+
+ # waiting for the redirect - without this the test is flaky..
+ sleep(1)
+
+ browser.visit(url)
+ browser.click_link_by_text('beállítások')
+ browser.is_text_present('Beállítások')
+
+
+def test_search(browser):
+ browser.visit(url)
+ browser.fill('q', 'test search query')
+ browser.find_by_xpath('//button[@type="submit"]').first.click()
+ assert browser.is_text_present('didn\'t find any results')
diff --git a/tests/robot/test_basic.robot b/tests/robot/test_basic.robot
deleted file mode 100644
index d0074cd00..000000000
--- a/tests/robot/test_basic.robot
+++ /dev/null
@@ -1,153 +0,0 @@
-*** Settings ***
-Library Selenium2Library timeout=10 implicit_wait=0.5
-Test Setup Open Browser http://localhost:11111/
-Test Teardown Close All Browsers
-
-
-*** Keywords ***
-Submit Preferences
- Set Selenium Speed 2 seconds
- Submit Form id=search_form
- Location Should Be http://localhost:11111/
- Set Selenium Speed 0 seconds
-
-
-*** Test Cases ***
-Front page
- Page Should Contain about
- Page Should Contain preferences
-
-404 page
- Go To http://localhost:11111/no-such-page
- Page Should Contain Page not found
- Page Should Contain Go to search page
-
-About page
- Click Element link=about
- Page Should Contain Why use searx?
- Page Should Contain Element link=search engines
-
-Preferences page
- Click Element link=preferences
- Page Should Contain Preferences
- Page Should Contain Default categories
- Page Should Contain Currently used search engines
- Page Should Contain dummy dummy
- Page Should Contain general dummy
-
-Switch category
- Go To http://localhost:11111/preferences
- Page Should Contain Checkbox category_general
- Page Should Contain Checkbox category_dummy
- Click Element xpath=//*[.="general"]
- Click Element xpath=//*[.="dummy"]
- Submit Preferences
- Checkbox Should Not Be Selected category_general
- Checkbox Should Be Selected category_dummy
-
-Change language
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- Select From List locale hu
- Submit Preferences
- Page Should Contain rólunk
- Page Should Contain beállítások
-
-Change method
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- Select From List method GET
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be method GET
- Select From List method POST
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be method POST
-
-Change theme
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be theme legacy
- Select From List theme oscar
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be theme oscar
-
-Change safesearch
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be safesearch None
- Select From List safesearch Strict
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be safesearch Strict
-
-Change image proxy
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be image_proxy Disabled
- Select From List image_proxy Enabled
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be image_proxy Enabled
-
-Change search language
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be language Default language
- Select From List language Türkçe - tr-TR
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be language Türkçe - tr-TR
-
-Change autocomplete
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be autocomplete -
- Select From List autocomplete google
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be autocomplete google
-
-Change allowed/disabled engines
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- Page Should Contain Engine name
- Element Should Contain xpath=//label[@class="deny"][@for='engine_dummy_dummy_dummy'] Block
- Element Should Contain xpath=//label[@class="deny"][@for='engine_general_general_dummy'] Block
- Click Element xpath=//label[@class="deny"][@for='engine_general_general_dummy']
- Submit Preferences
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- Page Should Contain Engine name
- Element Should Contain xpath=//label[@class="deny"][@for='engine_dummy_dummy_dummy'] Block
- Element Should Contain xpath=//label[@class="deny"][@for='engine_general_general_dummy'] \
-
-Block a plugin
- Page Should Contain about
- Page Should Contain preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be theme legacy
- Select From List theme oscar
- Submit Preferences
- Go To http://localhost:11111/preferences
- List Selection Should Be theme oscar
- Page Should Contain Plugins
- Click Link Plugins
- Checkbox Should Not Be Selected id=plugin_HTTPS_rewrite
- Click Element xpath=//label[@for='plugin_HTTPS_rewrite']
- Submit Preferences
- Go To http://localhost:11111/preferences
- Page Should Contain Plugins
- Click Link Plugins
- Checkbox Should Be Selected id=plugin_HTTPS_rewrite
diff --git a/tests/unit/engines/test_archlinux.py b/tests/unit/engines/test_archlinux.py
index d0009d63a..e4ee0339c 100644
--- a/tests/unit/engines/test_archlinux.py
+++ b/tests/unit/engines/test_archlinux.py
@@ -25,7 +25,7 @@ class TestArchLinuxEngine(SearxTestCase):
self.assertTrue(query in params['url'])
self.assertTrue('wiki.archlinux.org' in params['url'])
- for lang, domain in domains.iteritems():
+ for lang, domain in domains.items():
dic['language'] = lang
params = archlinux.request(query, dic)
self.assertTrue(domain in params['url'])
@@ -102,5 +102,5 @@ class TestArchLinuxEngine(SearxTestCase):
for exp in expected:
res = results[i]
i += 1
- for key, value in exp.iteritems():
+ for key, value in exp.items():
self.assertEqual(res[key], value)
diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py
index a63b2e333..523ec57b8 100644
--- a/tests/unit/engines/test_bing.py
+++ b/tests/unit/engines/test_bing.py
@@ -7,18 +7,18 @@ from searx.testing import SearxTestCase
class TestBingEngine(SearxTestCase):
def test_request(self):
- query = 'test_query'
+ query = u'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 0
dicto['language'] = 'fr_FR'
- params = bing.request(query, dicto)
+ params = bing.request(query.encode('utf-8'), dicto)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
self.assertTrue('language%3AFR' in params['url'])
self.assertTrue('bing.com' in params['url'])
dicto['language'] = 'all'
- params = bing.request(query, dicto)
+ params = bing.request(query.encode('utf-8'), dicto)
self.assertTrue('language' in params['url'])
def test_response(self):
diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py
index b6793f7be..e571adcee 100644
--- a/tests/unit/engines/test_bing_news.py
+++ b/tests/unit/engines/test_bing_news.py
@@ -36,10 +36,10 @@ class TestBingNewsEngine(SearxTestCase):
self.assertRaises(AttributeError, bing_news.response, '')
self.assertRaises(AttributeError, bing_news.response, '[]')
- response = mock.Mock(content='')
+ response = mock.Mock(text='')
self.assertEqual(bing_news.response(response), [])
- response = mock.Mock(content='')
+ response = mock.Mock(text='')
self.assertEqual(bing_news.response(response), [])
html = """
@@ -74,7 +74,7 @@ class TestBingNewsEngine(SearxTestCase):
""" # noqa
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html.encode('utf-8'))
results = bing_news.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 2)
@@ -113,7 +113,7 @@ class TestBingNewsEngine(SearxTestCase):
""" # noqa
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html.encode('utf-8'))
results = bing_news.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
@@ -136,11 +136,11 @@ class TestBingNewsEngine(SearxTestCase):
""" # noqa
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html.encode('utf-8'))
results = bing_news.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 0)
html = """gabarge"""
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html.encode('utf-8'))
self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)
diff --git a/tests/unit/engines/test_btdigg.py b/tests/unit/engines/test_btdigg.py
index 2721f4e7c..6a88e3f75 100644
--- a/tests/unit/engines/test_btdigg.py
+++ b/tests/unit/engines/test_btdigg.py
@@ -22,10 +22,10 @@ class TestBtdiggEngine(SearxTestCase):
self.assertRaises(AttributeError, btdigg.response, '')
self.assertRaises(AttributeError, btdigg.response, '[]')
- response = mock.Mock(content='')
+ response = mock.Mock(text='')
self.assertEqual(btdigg.response(response), [])
- html = """
+ html = u"""
@@ -82,7 +82,7 @@ class TestBtdiggEngine(SearxTestCase):