diff options
Diffstat (limited to 'searx')
-rw-r--r-- | searx/settings_robot.py | 16 | ||||
-rw-r--r-- | searx/testing.py | 59 | ||||
-rw-r--r-- | searx/tests/__init__.py | 0 | ||||
-rw-r--r-- | searx/tests/robot/__init__.py | 0 | ||||
-rw-r--r-- | searx/tests/robot/test_basic.robot | 11 | ||||
-rw-r--r-- | searx/tests/test_robot.py | 24 | ||||
-rw-r--r-- | searx/tests/test_unit.py | 10 | ||||
-rw-r--r-- | searx/webapp.py | 19 |
8 files changed, 135 insertions, 4 deletions
diff --git a/searx/settings_robot.py b/searx/settings_robot.py new file mode 100644 index 000000000..004add2a1 --- /dev/null +++ b/searx/settings_robot.py @@ -0,0 +1,16 @@ + +port = 11111 + +secret_key = "ultrasecretkey" # change this! + +debug = False + +request_timeout = 5.0 # seconds + +weights = {} # 'search_engine_name': float(weight) | default is 1.0 + +blacklist = [] # search engine blacklist + +categories = {} # custom search engine categories + +base_url = None # "https://your.domain.tld/" or None (to use request parameters) diff --git a/searx/testing.py b/searx/testing.py new file mode 100644 index 000000000..4b1810d6a --- /dev/null +++ b/searx/testing.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +"""Shared testing code.""" + +from plone.testing import Layer +from unittest2 import TestCase + + +import os +import subprocess +import sys + + +class SearxTestLayer: + + __name__ = u'SearxTestLayer' + + def setUp(cls): + pass + setUp = classmethod(setUp) + + def tearDown(cls): + pass + tearDown = classmethod(tearDown) + + def testSetUp(cls): + pass + testSetUp = classmethod(testSetUp) + + def testTearDown(cls): + pass + testTearDown = classmethod(testTearDown) + + +class SearxRobotLayer(Layer): + """Searx Robot Test Layer""" + + def setUp(self): + os.setpgrp() # create new process group, become its leader + webapp = os.path.join( + os.path.abspath(os.path.dirname(os.path.realpath(__file__))), + 'webapp.py' + ) + exe = os.path.abspath(os.path.dirname(__file__) + '/../bin/py') + self.server = subprocess.Popen( + [exe, webapp, 'settings_robot'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + + def tearDown(self): + # TERM all processes in my group + os.killpg(os.getpgid(self.server.pid), 15) + + +SEARXROBOTLAYER = SearxRobotLayer() + + +class SearxTestCase(TestCase): + layer = SearxTestLayer diff --git a/searx/tests/__init__.py b/searx/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/searx/tests/__init__.py diff --git a/searx/tests/robot/__init__.py b/searx/tests/robot/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/searx/tests/robot/__init__.py diff --git a/searx/tests/robot/test_basic.robot b/searx/tests/robot/test_basic.robot new file mode 100644 index 000000000..9f68d6693 --- /dev/null +++ b/searx/tests/robot/test_basic.robot @@ -0,0 +1,11 @@ +*** Settings *** +Library Selenium2Library timeout=10 implicit_wait=0.5 +Test Setup Open Browser http://localhost:11111/ +Test Teardown Close All Browsers + + +*** Test Cases *** +Front page + Page Should Contain about + Page Should Contain preferences + diff --git a/searx/tests/test_robot.py b/searx/tests/test_robot.py new file mode 100644 index 000000000..1480ae8ef --- /dev/null +++ b/searx/tests/test_robot.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from plone.testing import layered +from robotsuite import RobotTestSuite +from searx.testing import SEARXROBOTLAYER + +import os +import unittest2 as unittest + + +def test_suite(): + suite = unittest.TestSuite() + current_dir = os.path.abspath(os.path.dirname(__file__)) + robot_dir = os.path.join(current_dir, 'robot') + tests = [ + os.path.join('robot', f) for f in + os.listdir(robot_dir) if f.endswith('.robot') and + f.startswith('test_') + ] + for test in tests: + suite.addTests([ + layered(RobotTestSuite(test), layer=SEARXROBOTLAYER), + ]) + return suite diff --git a/searx/tests/test_unit.py b/searx/tests/test_unit.py new file mode 100644 index 000000000..8d57d0a46 --- /dev/null +++ b/searx/tests/test_unit.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +from searx.testing import SearxTestCase + + +class UnitTestCase(SearxTestCase): + + def test_flask(self): + import flask + self.assertIn('Flask', dir(flask)) diff --git a/searx/webapp.py b/searx/webapp.py index 6c27369db..48448eb25 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -18,13 +18,20 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >. ''' import os +import sys if __name__ == "__main__": - from sys import path - path.append(os.path.realpath(os.path.dirname(os.path.realpath(__file__))+'/../')) + sys.path.append(os.path.realpath(os.path.dirname(os.path.realpath(__file__))+'/../')) + +# first argument is for specifying settings module, used mostly by robot tests +from sys import argv +if len(argv) == 2: + from importlib import import_module + settings = import_module('searx.' + argv[1]) +else: + from searx import settings from flask import Flask, request, render_template, url_for, Response, make_response, redirect from searx.engines import search, categories, engines, get_engines_stats -from searx import settings import json import cStringIO from searx.utils import UnicodeWriter @@ -226,7 +233,7 @@ def favicon(): 'favicon.png', mimetype='image/vnd.microsoft.icon') -if __name__ == "__main__": +def run(): from gevent import monkey monkey.patch_all() @@ -234,3 +241,7 @@ if __name__ == "__main__": ,use_debugger = settings.debug ,port = settings.port ) + + +if __name__ == "__main__": + run() |