tests and robot tests framework, build overhaul

This commit is contained in:
Matej Cotman 2014-01-12 12:40:27 +01:00
parent 348187cff9
commit e740c8a8ea
17 changed files with 732 additions and 5 deletions

16
searx/settings_robot.py Normal file
View file

@ -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)

59
searx/testing.py Normal file
View file

@ -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

0
searx/tests/__init__.py Normal file
View file

View file

View file

@ -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

24
searx/tests/test_robot.py Normal file
View file

@ -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

10
searx/tests/test_unit.py Normal file
View file

@ -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))

View file

@ -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()