Commit e740c8a8 authored by Matej Cotman's avatar Matej Cotman

tests and robot tests framework, build overhaul

parent 348187cf
env
engines.cfg
.installed.cfg
setup.cfg
*.pyc
*/*.pyc
\ No newline at end of file
*/*.pyc
bin/
include/
lib/
build/
develop-eggs/
parts/
# convenience makefile to boostrap & run buildout
# use `make options=-v` to run buildout with extra options
version = 2.7
python = bin/python
options =
all: .installed.cfg
.installed.cfg: bin/buildout buildout.cfg setup.py
bin/buildout $(options)
bin/buildout: $(python) buildout.cfg bootstrap.py
$(python) bootstrap.py
@touch $@
$(python):
virtualenv -p python$(version) --no-site-packages .
@touch $@
tests: .installed.cfg
@bin/test
enginescfg:
@test -f ./engines.cfg || echo "Copying engines.cfg ..."
@cp --no-clobber engines.cfg_sample engines.cfg
robot: .installed.cfg enginescfg
@bin/robot
flake8: .installed.cfg
@bin/flake8 setup.py
@bin/flake8 ./searx/
coverage: .installed.cfg
@bin/coverage run --source=./searx/ --branch bin/test
@bin/coverage report --show-missing
@bin/coverage html --directory ./coverage
minimal: bin/buildout production.cfg setup.py enginescfg
bin/buildout -c production.cfg $(options)
@echo "* Please modify `readlink --canonicalize-missing ./searx/settings.py`"
@echo "* Hint 1: on production, disable debug mode and change secret_key"
@echo "* Hint 2: to run server execute 'bin/searx-run'"
clean:
@rm -rf .installed.cfg .mr.developer.cfg bin parts develop-eggs \
searx.egg-info lib include .coverage coverage
.PHONY: all tests enginescfg robot flake8 coverage minimal clean
......@@ -29,6 +29,48 @@ List of [running instances](https://github.com/asciimoo/searx/wiki/Searx-instanc
For all the details, follow this [step by step installation](https://github.com/asciimoo/searx/wiki/Installation)
### Alternative (Recommended) Installation
* clone source: `git clone git@github.com:asciimoo/searx.git && cd searx`
* build in current folder: `make minimal`
* run `bin/searx-run` to start the application
### Development
Just run `make`. Versions of dependencies are pinned down inside `versions.cfg` to produce most stable build.
#### Command make
##### `make`
Builds development environment with testing support.
##### `make tests`
Runs tests. You can write tests [here](https://github.com/asciimoo/searx/tree/master/searx/tests) and remember 'untested code is broken code'.
##### `make robot`
Runs robot (Selenium) tests, you must have `firefox` installed because this functional tests actually run the browser and perform operations on it. Also searx is executed with [settings_robot](https://github.com/asciimoo/searx/blob/master/searx/settings_robot.py).
##### `make flake8`
'pep8 is a tool to check your Python code against some of the style conventions in [PEP 8](http://www.python.org/dev/peps/pep-0008/).'
##### `make coverage`
Checks coverage of tests, after running this, execute this: `firefox ./coverage/index.html`
##### `make minimal`
Used to make co-called production environment - without tests (you should ran tests before deploying searx on the server).
##### `make clean`
Deletes several folders and files (see `Makefile` for more), so that next time you run any other `make` command it will rebuild everithing.
### TODO
* Moar engines
......@@ -36,7 +78,9 @@ For all the details, follow this [step by step installation](https://github.com/
* Language support
* Documentation
* Pagination
* Fix `flake8` errors, `make flake8` will be merged into `make tests` when it does not fail anymore
* Tests
* When we have more tests, we can integrate Travis-CI
### Bugs
......
[buildout]
extends = versions.cfg
versions = versions
unzip = true
newest = false
extends = versions.cfg
versions = versions
prefer-final = true
develop = .
extensions =
buildout_versions
eggs =
searx
parts =
omelette
[omelette]
recipe = collective.recipe.omelette
eggs = ${buildout:eggs}
This diff is collapsed.
[buildout]
extends = base.cfg
develop = .
eggs =
searx [test]
parts +=
pyscripts
robot
test
[pyscripts]
recipe = zc.recipe.egg:script
eggs = ${buildout:eggs}
interpreter = py
dependent-scripts = true
entry-points =
searx-run=searx.webapp:run
[robot]
recipe = zc.recipe.testrunner
eggs = ${buildout:eggs}
defaults = ['--color', '--auto-progress', '--layer', 'SearxRobotLayer']
[test]
recipe = zc.recipe.testrunner
eggs = ${buildout:eggs}
defaults = ['--color', '--auto-progress', '--layer', 'SearxTestLayer', '--layer', '!SearxRobotLayer']
[buildout]
extends = base.cfg
develop = .
eggs =
searx
parts +=
pyscripts
[pyscripts]
recipe = zc.recipe.egg:script
eggs = ${buildout:eggs}
interpreter = py
entry-points =
searx-run=searx.webapp:run
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)
# -*- 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
*** 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
# -*- 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
# -*- coding: utf-8 -*-
from searx.testing import SearxTestCase
class UnitTestCase(SearxTestCase):
def test_flask(self):
import flask
self.assertIn('Flask', dir(flask))
......@@ -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()
# -*- coding: utf-8 -*-
"""Installer for Searx package."""
from setuptools import setup
from setuptools import find_packages
import os
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description = read('README.md')
setup(
name='searx',
version="0.1",
description="",
long_description=long_description,
classifiers=[
"Programming Language :: Python",
],
keywords='meta search engine',
author='Adam Tauber',
author_email='asciimoo@gmail.com',
url='https://github.com/asciimoo/searx',
license='GNU Affero General Public License',
packages=find_packages('.'),
zip_safe=False,
install_requires=[
'flask',
'grequests',
'lxml',
'setuptools',
],
extras_require={
'test': [
'coverage',
'flake8',
'plone.testing',
'robotframework',
'robotframework-debuglibrary',
'robotframework-httplibrary',
'robotframework-selenium2library',
'robotsuite',
'unittest2',
'zope.testrunner',
]
},
)
[versions]
Flask = 0.10.1
Jinja2 = 2.7.2
MarkupSafe = 0.18
WebOb = 1.3.1
WebTest = 2.0.11
Werkzeug = 0.9.4
buildout-versions = 1.7
collective.recipe.omelette = 0.16
coverage = 3.7.1
decorator = 3.4.0
docutils = 0.11
flake8 = 2.1.0
itsdangerous = 0.23
mccabe = 0.2.1
pep8 = 1.4.6
plone.testing = 4.0.8
pyflakes = 0.7.3
requests = 2.2.0
robotframework-debuglibrary = 0.3
robotframework-httplibrary = 0.4.2
robotframework-selenium2library = 1.5.0
robotsuite = 1.4.2
selenium = 2.39.0
unittest2 = 0.5.1
waitress = 0.8.8
zc.recipe.testrunner = 2.0.0
# Required by:
# WebTest==2.0.11
beautifulsoup4 = 4.3.2
# Required by:
# grequests==0.2.0
gevent = 1.0
# Required by:
# gevent==1.0
greenlet = 0.4.2
# Required by:
# searx==0.1
grequests = 0.2.0
# Required by:
# robotframework-httplibrary==0.4.2
jsonpatch = 1.3
# Required by:
# robotframework-httplibrary==0.4.2
jsonpointer = 1.1
# Required by:
# robotsuite==1.4.2
# searx==0.1
lxml = 3.2.5
# Required by:
# robotframework-httplibrary==0.4.2
robotframework = 2.8.3
# Required by:
# plone.testing==4.0.8
# robotsuite==1.4.2
# searx==0.1
# zope.exceptions==4.0.6
# zope.interface==4.0.5
# zope.testrunner==4.4.1
setuptools = 2.1
# Required by:
# zope.testrunner==4.4.1
six = 1.5.2
# Required by:
# collective.recipe.omelette==0.16
zc.recipe.egg = 2.0.1
# Required by:
# zope.testrunner==4.4.1
zope.exceptions = 4.0.6
# Required by:
# zope.testrunner==4.4.1
zope.interface = 4.0.5
# Required by:
# plone.testing==4.0.8
zope.testing = 4.1.2
# Required by:
# zc.recipe.testrunner==2.0.0
zope.testrunner = 4.4.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment