From 53979a7bf7669c803c2a493fbf136519f6a293e6 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 2 Jan 2016 11:14:49 +0100 Subject: [mod] remove buildout/makefile infrastructure --- .gitignore | 12 - .travis.yml | 15 +- Makefile | 66 --- base.cfg | 17 - bootstrap.py | 210 --------- buildout.cfg | 30 -- manage.sh | 70 +++ minimal.cfg | 15 - production.cfg | 34 -- requirements-dev.txt | 9 + searx/tests/__init__.py | 0 searx/tests/engines/__init__.py | 0 searx/tests/engines/test_bing.py | 90 ---- searx/tests/engines/test_bing_images.py | 269 ----------- searx/tests/engines/test_bing_news.py | 138 ------ searx/tests/engines/test_blekko_images.py | 71 --- searx/tests/engines/test_btdigg.py | 384 ---------------- searx/tests/engines/test_currency_convert.py | 46 -- searx/tests/engines/test_dailymotion.py | 74 --- searx/tests/engines/test_deezer.py | 57 --- searx/tests/engines/test_deviantart.py | 118 ----- searx/tests/engines/test_digg.py | 101 ----- searx/tests/engines/test_duckduckgo.py | 91 ---- searx/tests/engines/test_duckduckgo_definitions.py | 250 ---------- searx/tests/engines/test_dummy.py | 26 -- searx/tests/engines/test_faroo.py | 116 ----- searx/tests/engines/test_flickr.py | 142 ------ searx/tests/engines/test_flickr_noapi.py | 328 -------------- searx/tests/engines/test_gigablast.py | 58 --- searx/tests/engines/test_github.py | 61 --- searx/tests/engines/test_google.py | 178 -------- searx/tests/engines/test_google_images.py | 58 --- searx/tests/engines/test_google_news.py | 136 ------ searx/tests/engines/test_kickass.py | 397 ---------------- searx/tests/engines/test_mediawiki.py | 130 ------ searx/tests/engines/test_mixcloud.py | 67 --- searx/tests/engines/test_openstreetmap.py | 199 -------- searx/tests/engines/test_photon.py | 166 ------- searx/tests/engines/test_piratebay.py | 166 ------- searx/tests/engines/test_qwant.py | 317 ------------- searx/tests/engines/test_searchcode_code.py | 75 --- searx/tests/engines/test_searchcode_doc.py | 73 --- searx/tests/engines/test_soundcloud.py | 192 -------- searx/tests/engines/test_spotify.py | 124 ----- searx/tests/engines/test_stackoverflow.py | 106 ----- searx/tests/engines/test_startpage.py | 140 ------ searx/tests/engines/test_subtitleseeker.py | 169 ------- searx/tests/engines/test_swisscows.py | 128 ------ searx/tests/engines/test_twitter.py | 502 --------------------- searx/tests/engines/test_vimeo.py | 101 ----- searx/tests/engines/test_www1x.py | 57 --- searx/tests/engines/test_www500px.py | 83 ---- searx/tests/engines/test_yacy.py | 96 ---- searx/tests/engines/test_yahoo.py | 141 ------ searx/tests/engines/test_yahoo_news.py | 149 ------ searx/tests/engines/test_youtube_api.py | 111 ----- searx/tests/engines/test_youtube_noapi.py | 154 ------- searx/tests/robot/__init__.py | 0 searx/tests/robot/test_basic.robot | 44 -- searx/tests/test_engines.py | 45 -- searx/tests/test_plugins.py | 74 --- searx/tests/test_results.py | 41 -- searx/tests/test_robot.py | 23 - searx/tests/test_search.py | 10 - searx/tests/test_utils.py | 101 ----- searx/tests/test_webapp.py | 151 ------- tests/__init__.py | 0 tests/robot/__init__.py | 0 tests/robot/test_basic.robot | 44 ++ tests/test_robot.py | 23 + tests/unit/__init__.py | 0 tests/unit/engines/__init__.py | 0 tests/unit/engines/test_bing.py | 90 ++++ tests/unit/engines/test_bing_images.py | 269 +++++++++++ tests/unit/engines/test_bing_news.py | 138 ++++++ tests/unit/engines/test_blekko_images.py | 71 +++ tests/unit/engines/test_btdigg.py | 384 ++++++++++++++++ tests/unit/engines/test_currency_convert.py | 46 ++ tests/unit/engines/test_dailymotion.py | 74 +++ tests/unit/engines/test_deezer.py | 57 +++ tests/unit/engines/test_deviantart.py | 118 +++++ tests/unit/engines/test_digg.py | 101 +++++ tests/unit/engines/test_duckduckgo.py | 91 ++++ tests/unit/engines/test_duckduckgo_definitions.py | 250 ++++++++++ tests/unit/engines/test_dummy.py | 26 ++ tests/unit/engines/test_faroo.py | 116 +++++ tests/unit/engines/test_flickr.py | 142 ++++++ tests/unit/engines/test_flickr_noapi.py | 328 ++++++++++++++ tests/unit/engines/test_gigablast.py | 58 +++ tests/unit/engines/test_github.py | 61 +++ tests/unit/engines/test_google.py | 178 ++++++++ tests/unit/engines/test_google_images.py | 58 +++ tests/unit/engines/test_google_news.py | 136 ++++++ tests/unit/engines/test_kickass.py | 397 ++++++++++++++++ tests/unit/engines/test_mediawiki.py | 130 ++++++ tests/unit/engines/test_mixcloud.py | 67 +++ tests/unit/engines/test_openstreetmap.py | 199 ++++++++ tests/unit/engines/test_photon.py | 166 +++++++ tests/unit/engines/test_piratebay.py | 166 +++++++ tests/unit/engines/test_qwant.py | 317 +++++++++++++ tests/unit/engines/test_searchcode_code.py | 75 +++ tests/unit/engines/test_searchcode_doc.py | 73 +++ tests/unit/engines/test_soundcloud.py | 192 ++++++++ tests/unit/engines/test_spotify.py | 124 +++++ tests/unit/engines/test_stackoverflow.py | 106 +++++ tests/unit/engines/test_startpage.py | 140 ++++++ tests/unit/engines/test_subtitleseeker.py | 169 +++++++ tests/unit/engines/test_swisscows.py | 128 ++++++ tests/unit/engines/test_twitter.py | 502 +++++++++++++++++++++ tests/unit/engines/test_vimeo.py | 101 +++++ tests/unit/engines/test_www1x.py | 57 +++ tests/unit/engines/test_www500px.py | 83 ++++ tests/unit/engines/test_yacy.py | 96 ++++ tests/unit/engines/test_yahoo.py | 141 ++++++ tests/unit/engines/test_yahoo_news.py | 149 ++++++ tests/unit/engines/test_youtube_api.py | 111 +++++ tests/unit/engines/test_youtube_noapi.py | 154 +++++++ tests/unit/test_plugins.py | 74 +++ tests/unit/test_results.py | 41 ++ tests/unit/test_search.py | 10 + tests/unit/test_utils.py | 101 +++++ tests/unit/test_webapp.py | 151 +++++++ versions.cfg | 122 ----- 123 files changed, 7166 insertions(+), 7637 deletions(-) delete mode 100644 Makefile delete mode 100644 base.cfg delete mode 100644 bootstrap.py delete mode 100644 buildout.cfg create mode 100755 manage.sh delete mode 100644 minimal.cfg delete mode 100644 production.cfg create mode 100644 requirements-dev.txt delete mode 100644 searx/tests/__init__.py delete mode 100644 searx/tests/engines/__init__.py delete mode 100644 searx/tests/engines/test_bing.py delete mode 100644 searx/tests/engines/test_bing_images.py delete mode 100644 searx/tests/engines/test_bing_news.py delete mode 100644 searx/tests/engines/test_blekko_images.py delete mode 100644 searx/tests/engines/test_btdigg.py delete mode 100644 searx/tests/engines/test_currency_convert.py delete mode 100644 searx/tests/engines/test_dailymotion.py delete mode 100644 searx/tests/engines/test_deezer.py delete mode 100644 searx/tests/engines/test_deviantart.py delete mode 100644 searx/tests/engines/test_digg.py delete mode 100644 searx/tests/engines/test_duckduckgo.py delete mode 100644 searx/tests/engines/test_duckduckgo_definitions.py delete mode 100644 searx/tests/engines/test_dummy.py delete mode 100644 searx/tests/engines/test_faroo.py delete mode 100644 searx/tests/engines/test_flickr.py delete mode 100644 searx/tests/engines/test_flickr_noapi.py delete mode 100644 searx/tests/engines/test_gigablast.py delete mode 100644 searx/tests/engines/test_github.py delete mode 100644 searx/tests/engines/test_google.py delete mode 100644 searx/tests/engines/test_google_images.py delete mode 100644 searx/tests/engines/test_google_news.py delete mode 100644 searx/tests/engines/test_kickass.py delete mode 100644 searx/tests/engines/test_mediawiki.py delete mode 100644 searx/tests/engines/test_mixcloud.py delete mode 100644 searx/tests/engines/test_openstreetmap.py delete mode 100644 searx/tests/engines/test_photon.py delete mode 100644 searx/tests/engines/test_piratebay.py delete mode 100644 searx/tests/engines/test_qwant.py delete mode 100644 searx/tests/engines/test_searchcode_code.py delete mode 100644 searx/tests/engines/test_searchcode_doc.py delete mode 100644 searx/tests/engines/test_soundcloud.py delete mode 100644 searx/tests/engines/test_spotify.py delete mode 100644 searx/tests/engines/test_stackoverflow.py delete mode 100644 searx/tests/engines/test_startpage.py delete mode 100644 searx/tests/engines/test_subtitleseeker.py delete mode 100644 searx/tests/engines/test_swisscows.py delete mode 100644 searx/tests/engines/test_twitter.py delete mode 100644 searx/tests/engines/test_vimeo.py delete mode 100644 searx/tests/engines/test_www1x.py delete mode 100644 searx/tests/engines/test_www500px.py delete mode 100644 searx/tests/engines/test_yacy.py delete mode 100644 searx/tests/engines/test_yahoo.py delete mode 100644 searx/tests/engines/test_yahoo_news.py delete mode 100644 searx/tests/engines/test_youtube_api.py delete mode 100644 searx/tests/engines/test_youtube_noapi.py delete mode 100644 searx/tests/robot/__init__.py delete mode 100644 searx/tests/robot/test_basic.robot delete mode 100644 searx/tests/test_engines.py delete mode 100644 searx/tests/test_plugins.py delete mode 100644 searx/tests/test_results.py delete mode 100644 searx/tests/test_robot.py delete mode 100644 searx/tests/test_search.py delete mode 100644 searx/tests/test_utils.py delete mode 100644 searx/tests/test_webapp.py create mode 100644 tests/__init__.py create mode 100644 tests/robot/__init__.py create mode 100644 tests/robot/test_basic.robot create mode 100644 tests/test_robot.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/engines/__init__.py create mode 100644 tests/unit/engines/test_bing.py create mode 100644 tests/unit/engines/test_bing_images.py create mode 100644 tests/unit/engines/test_bing_news.py create mode 100644 tests/unit/engines/test_blekko_images.py create mode 100644 tests/unit/engines/test_btdigg.py create mode 100644 tests/unit/engines/test_currency_convert.py create mode 100644 tests/unit/engines/test_dailymotion.py create mode 100644 tests/unit/engines/test_deezer.py create mode 100644 tests/unit/engines/test_deviantart.py create mode 100644 tests/unit/engines/test_digg.py create mode 100644 tests/unit/engines/test_duckduckgo.py create mode 100644 tests/unit/engines/test_duckduckgo_definitions.py create mode 100644 tests/unit/engines/test_dummy.py create mode 100644 tests/unit/engines/test_faroo.py create mode 100644 tests/unit/engines/test_flickr.py create mode 100644 tests/unit/engines/test_flickr_noapi.py create mode 100644 tests/unit/engines/test_gigablast.py create mode 100644 tests/unit/engines/test_github.py create mode 100644 tests/unit/engines/test_google.py create mode 100644 tests/unit/engines/test_google_images.py create mode 100644 tests/unit/engines/test_google_news.py create mode 100644 tests/unit/engines/test_kickass.py create mode 100644 tests/unit/engines/test_mediawiki.py create mode 100644 tests/unit/engines/test_mixcloud.py create mode 100644 tests/unit/engines/test_openstreetmap.py create mode 100644 tests/unit/engines/test_photon.py create mode 100644 tests/unit/engines/test_piratebay.py create mode 100644 tests/unit/engines/test_qwant.py create mode 100644 tests/unit/engines/test_searchcode_code.py create mode 100644 tests/unit/engines/test_searchcode_doc.py create mode 100644 tests/unit/engines/test_soundcloud.py create mode 100644 tests/unit/engines/test_spotify.py create mode 100644 tests/unit/engines/test_stackoverflow.py create mode 100644 tests/unit/engines/test_startpage.py create mode 100644 tests/unit/engines/test_subtitleseeker.py create mode 100644 tests/unit/engines/test_swisscows.py create mode 100644 tests/unit/engines/test_twitter.py create mode 100644 tests/unit/engines/test_vimeo.py create mode 100644 tests/unit/engines/test_www1x.py create mode 100644 tests/unit/engines/test_www500px.py create mode 100644 tests/unit/engines/test_yacy.py create mode 100644 tests/unit/engines/test_yahoo.py create mode 100644 tests/unit/engines/test_yahoo_news.py create mode 100644 tests/unit/engines/test_youtube_api.py create mode 100644 tests/unit/engines/test_youtube_noapi.py create mode 100644 tests/unit/test_plugins.py create mode 100644 tests/unit/test_results.py create mode 100644 tests/unit/test_search.py create mode 100644 tests/unit/test_utils.py create mode 100644 tests/unit/test_webapp.py delete mode 100644 versions.cfg diff --git a/.gitignore b/.gitignore index 760b1a8f3..d29971645 100644 --- a/.gitignore +++ b/.gitignore @@ -11,18 +11,6 @@ setup.cfg */*.pyc *~ -bin/ -build/ -coverage/ -develop-eggs/ -dist/ -eggs/ -include/ -lib/ -local/ -parts/ -searx.egg-info/ -var/ node_modules/ .tx/ diff --git a/.travis.yml b/.travis.yml index be6683510..57d623060 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,16 +11,17 @@ before_install: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - npm install -g less grunt-cli - - ( cd searx/static/themes/oscar;npm install ) + - ( cd searx/static/themes/oscar;npm install; cd - ) install: - - "make" + - ./manage.sh update_packages + - ./manage.sh update_dev_packages - pip install coveralls script: - - "make flake8" - - "make robot" - - "make styles" - - "make grunt" - - make coverage + - ./manage.sh pep8_check + - ./manage.sh styles + - ./manage.sh grunt + - ./manage.sh coverage + - ./manage.sh robot after_success: coveralls notifications: diff --git a/Makefile b/Makefile deleted file mode 100644 index 5573e5447..000000000 --- a/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -# 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 $@ - -robot: .installed.cfg - @bin/robot - -flake8: .installed.cfg - @bin/flake8 setup.py - @bin/flake8 ./searx/ - -tests: .installed.cfg flake8 - @bin/test - @grunt test --gruntfile searx/static/themes/oscar/gruntfile.js - -coverage: .installed.cfg - @bin/coverage run bin/test - @bin/coverage report - @bin/coverage html - -production: bin/buildout production.cfg setup.py - 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: searx will be executed at server startup by crontab" - @echo "* Hint 3: to run immediatley, execute 'bin/supervisord'" - -minimal: bin/buildout minimal.cfg setup.py - bin/buildout -c minimal.cfg $(options) - -styles: - @lessc -x searx/static/themes/default/less/style.less > searx/static/themes/default/css/style.css - @lessc -x searx/static/themes/default/less/style-rtl.less > searx/static/themes/default/css/style-rtl.css - @lessc -x searx/static/themes/courgette/less/style.less > searx/static/themes/courgette/css/style.css - @lessc -x searx/static/themes/courgette/less/style-rtl.less > searx/static/themes/courgette/css/style-rtl.css - @lessc -x searx/static/less/bootstrap/bootstrap.less > searx/static/css/bootstrap.min.css - @lessc -x searx/static/themes/oscar/less/oscar/oscar.less > searx/static/themes/oscar/css/oscar.min.css - @lessc -x searx/static/themes/pix-art/less/style.less > searx/static/themes/pix-art/css/style.css - -grunt: - @grunt --gruntfile searx/static/themes/oscar/gruntfile.js - -locales: - @pybabel compile -d searx/translations - -clean: - @rm -rf .installed.cfg .mr.developer.cfg bin parts develop-eggs eggs \ - searx.egg-info lib include .coverage coverage - -.PHONY: all tests robot flake8 coverage production minimal styles locales clean diff --git a/base.cfg b/base.cfg deleted file mode 100644 index 6e46e9eb7..000000000 --- a/base.cfg +++ /dev/null @@ -1,17 +0,0 @@ -[buildout] -extends = versions.cfg -unzip = true -newest = false -prefer-final = true -develop = . - -eggs = - searx - -parts = - omelette - - -[omelette] -recipe = collective.recipe.omelette -eggs = ${buildout:eggs} diff --git a/bootstrap.py b/bootstrap.py deleted file mode 100644 index a4599211f..000000000 --- a/bootstrap.py +++ /dev/null @@ -1,210 +0,0 @@ -############################################################################## -# -# Copyright (c) 2006 Zope Foundation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -"""Bootstrap a buildout-based project - -Simply run this script in a directory containing a buildout.cfg. -The script accepts buildout command-line options, so you can -use the -c option to specify an alternate configuration file. -""" - -import os -import shutil -import sys -import tempfile - -from optparse import OptionParser - -__version__ = '2015-07-01' -# See zc.buildout's changelog if this version is up to date. - -tmpeggs = tempfile.mkdtemp(prefix='bootstrap-') - -usage = '''\ -[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] - -Bootstraps a buildout-based project. - -Simply run this script in a directory containing a buildout.cfg, using the -Python that you want bin/buildout to use. - -Note that by using --find-links to point to local resources, you can keep -this script from going over the network. -''' - -parser = OptionParser(usage=usage) -parser.add_option("--version", - action="store_true", default=False, - help=("Return bootstrap.py version.")) -parser.add_option("-t", "--accept-buildout-test-releases", - dest='accept_buildout_test_releases', - action="store_true", default=False, - help=("Normally, if you do not specify a --version, the " - "bootstrap script and buildout gets the newest " - "*final* versions of zc.buildout and its recipes and " - "extensions for you. If you use this flag, " - "bootstrap and buildout will get the newest releases " - "even if they are alphas or betas.")) -parser.add_option("-c", "--config-file", - help=("Specify the path to the buildout configuration " - "file to be used.")) -parser.add_option("-f", "--find-links", - help=("Specify a URL to search for buildout releases")) -parser.add_option("--allow-site-packages", - action="store_true", default=False, - help=("Let bootstrap.py use existing site packages")) -parser.add_option("--buildout-version", - help="Use a specific zc.buildout version") -parser.add_option("--setuptools-version", - help="Use a specific setuptools version") -parser.add_option("--setuptools-to-dir", - help=("Allow for re-use of existing directory of " - "setuptools versions")) - -options, args = parser.parse_args() -if options.version: - print("bootstrap.py version %s" % __version__) - sys.exit(0) - - -###################################################################### -# load/install setuptools - -try: - from urllib.request import urlopen -except ImportError: - from urllib2 import urlopen - -ez = {} -if os.path.exists('ez_setup.py'): - exec(open('ez_setup.py').read(), ez) -else: - exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) - -if not options.allow_site_packages: - # ez_setup imports site, which adds site packages - # this will remove them from the path to ensure that incompatible versions - # of setuptools are not in the path - import site - # inside a virtualenv, there is no 'getsitepackages'. - # We can't remove these reliably - if hasattr(site, 'getsitepackages'): - for sitepackage_path in site.getsitepackages(): - # Strip all site-packages directories from sys.path that - # are not sys.prefix; this is because on Windows - # sys.prefix is a site-package directory. - if sitepackage_path != sys.prefix: - sys.path[:] = [x for x in sys.path - if sitepackage_path not in x] - -setup_args = dict(to_dir=tmpeggs, download_delay=0) - -if options.setuptools_version is not None: - setup_args['version'] = options.setuptools_version -if options.setuptools_to_dir is not None: - setup_args['to_dir'] = options.setuptools_to_dir - -ez['use_setuptools'](**setup_args) -import setuptools -import pkg_resources - -# This does not (always?) update the default working set. We will -# do it. -for path in sys.path: - if path not in pkg_resources.working_set.entries: - pkg_resources.working_set.add_entry(path) - -###################################################################### -# Install buildout - -ws = pkg_resources.working_set - -setuptools_path = ws.find( - pkg_resources.Requirement.parse('setuptools')).location - -# Fix sys.path here as easy_install.pth added before PYTHONPATH -cmd = [sys.executable, '-c', - 'import sys; sys.path[0:0] = [%r]; ' % setuptools_path + - 'from setuptools.command.easy_install import main; main()', - '-mZqNxd', tmpeggs] - -find_links = os.environ.get( - 'bootstrap-testing-find-links', - options.find_links or - ('http://downloads.buildout.org/' - if options.accept_buildout_test_releases else None) - ) -if find_links: - cmd.extend(['-f', find_links]) - -requirement = 'zc.buildout' -version = options.buildout_version -if version is None and not options.accept_buildout_test_releases: - # Figure out the most recent final version of zc.buildout. - import setuptools.package_index - _final_parts = '*final-', '*final' - - def _final_version(parsed_version): - try: - return not parsed_version.is_prerelease - except AttributeError: - # Older setuptools - for part in parsed_version: - if (part[:1] == '*') and (part not in _final_parts): - return False - return True - - index = setuptools.package_index.PackageIndex( - search_path=[setuptools_path]) - if find_links: - index.add_find_links((find_links,)) - req = pkg_resources.Requirement.parse(requirement) - if index.obtain(req) is not None: - best = [] - bestv = None - for dist in index[req.project_name]: - distv = dist.parsed_version - if _final_version(distv): - if bestv is None or distv > bestv: - best = [dist] - bestv = distv - elif distv == bestv: - best.append(dist) - if best: - best.sort() - version = best[-1].version -if version: - requirement = '=='.join((requirement, version)) -cmd.append(requirement) - -import subprocess -if subprocess.call(cmd) != 0: - raise Exception( - "Failed to execute command:\n%s" % repr(cmd)[1:-1]) - -###################################################################### -# Import and run buildout - -ws.add_entry(tmpeggs) -ws.require(requirement) -import zc.buildout.buildout - -if not [a for a in args if '=' not in a]: - args.append('bootstrap') - -# if -c was provided, we push it back into args for buildout' main function -if options.config_file is not None: - args[0:0] = ['-c', options.config_file] - -zc.buildout.buildout.main(args) -shutil.rmtree(tmpeggs) diff --git a/buildout.cfg b/buildout.cfg deleted file mode 100644 index b9e6d24ed..000000000 --- a/buildout.cfg +++ /dev/null @@ -1,30 +0,0 @@ -[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 - - -[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'] diff --git a/manage.sh b/manage.sh new file mode 100755 index 000000000..39a8e27d3 --- /dev/null +++ b/manage.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +BASE_DIR=$(dirname `readlink -f $0`) +PYTHONPATH=$BASE_DIR +SEARX_DIR="$BASE_DIR/searx" +ACTION=$1 + +update_packages() { + pip install --upgrade -r "$BASE_DIR/requirements.txt" +} + +update_dev_packages() { + pip install --upgrade -r "$BASE_DIR/requirements-dev.txt" +} + +pep8_check() { + echo '[!] Running pep8 check' + pep8 "$SEARX_DIR" "$BASE_DIR/tests" +} + +unit_tests() { + echo '[!] Running unit tests' + python -m nose2 -s "$BASE_DIR/tests/unit" +} + +py_test_coverage() { + echo '[!] Running python test coverage' + PYTHONPATH=`pwd` python -m nose2 -C --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" + coverage report + coverage html +} + +robot_tests() { + echo '[!] Running robot tests' + python -c "import zope.testrunner; import sys; sys.exit(zope.testrunner.run("\ +"['--color', '--auto-progress', '--layer', 'SearxRobotLayer', '--test-path', '$BASE_DIR']))" +} + +tests() { + set -e + pep8_check + unit_tests + robot_tests + set +e +} + +build_style() { + lessc -x "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2" +} + +styles() { + echo '[!] Building styles' + build_style themes/default/less/style.less themes/default/css/style.css + build_style themes/default/less/style-rtl.less themes/default/css/style-rtl.css + build_style themes/courgette/less/style.less themes/courgette/css/style.css + build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css + build_style less/bootstrap/bootstrap.less css/bootstrap.min.css + build_style themes/oscar/less/oscar/oscar.less themes/oscar/css/oscar.min.css + build_style themes/pix-art/less/style.less themes/pix-art/css/style.css +} + +grunt() { + grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js" +} + +locales() { + pybabel compile -d "$SEARX_DIR/translations" +} + +$ACTION diff --git a/minimal.cfg b/minimal.cfg deleted file mode 100644 index 339a2939f..000000000 --- a/minimal.cfg +++ /dev/null @@ -1,15 +0,0 @@ -[buildout] -extends = base.cfg -develop = . - -eggs = - searx - -parts += - pyscripts - - -[pyscripts] -recipe = zc.recipe.egg:script -eggs = ${buildout:eggs} -interpreter = py diff --git a/production.cfg b/production.cfg deleted file mode 100644 index ea40682d8..000000000 --- a/production.cfg +++ /dev/null @@ -1,34 +0,0 @@ -[buildout] -extends = base.cfg -develop = . - -eggs = - searx - -parts += - pyscripts - supervisor - crontab_reboot - - -[pyscripts] -recipe = zc.recipe.egg:script -eggs = ${buildout:eggs} -interpreter = py - - -[supervisor] -recipe = collective.recipe.supervisor -http-socket = unix -user = searxer -password = ohpleasedochangeme -file = /tmp/supervisor.sock -chmod = 0700 -programs = - 50 searx ${buildout:bin-directory}/searx-run - - -[crontab_reboot] -recipe = z3c.recipe.usercrontab -times = @reboot -command = ${buildout:bin-directory}/supervisord diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 000000000..d8c2395dd --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,9 @@ +flake8==2.5.1 +mock==1.0.1 +nose2==0.4.7 +nose2[coverage-plugin] +plone.testing==4.0.15 +robotframework-selenium2library==1.7.4 +robotsuite==1.7.0 +unittest2==1.1.0 +zope.testrunner==4.4.10 diff --git a/searx/tests/__init__.py b/searx/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/searx/tests/engines/__init__.py b/searx/tests/engines/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/searx/tests/engines/test_bing.py b/searx/tests/engines/test_bing.py deleted file mode 100644 index bce221440..000000000 --- a/searx/tests/engines/test_bing.py +++ /dev/null @@ -1,90 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import bing -from searx.testing import SearxTestCase - - -class TestBingEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['language'] = 'fr_FR' - params = bing.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('bing.com' in params['url']) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) - - dicto['language'] = 'all' - params = bing.request(query, dicto) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('en' in params['cookies']['SRCHHPGUSR']) - - def test_response(self): - self.assertRaises(AttributeError, bing.response, None) - self.assertRaises(AttributeError, bing.response, []) - self.assertRaises(AttributeError, bing.response, '') - self.assertRaises(AttributeError, bing.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(bing.response(response), []) - - response = mock.Mock(text='') - self.assertEqual(bing.response(response), []) - - html = """ -
-
- -
this.meta.com - - - - -
-

This should be the content.

-
-
- """ - response = mock.Mock(text=html) - results = bing.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') - self.assertEqual(results[0]['content'], 'This should be the content.') - - html = """ -
  • -
    - -
    this.meta.com - - - - -
    -

    This should be the content.

    -
    -
  • - """ - response = mock.Mock(text=html) - results = bing.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') - self.assertEqual(results[0]['content'], 'This should be the content.') diff --git a/searx/tests/engines/test_bing_images.py b/searx/tests/engines/test_bing_images.py deleted file mode 100644 index f42dff7e8..000000000 --- a/searx/tests/engines/test_bing_images.py +++ /dev/null @@ -1,269 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import bing_images -from searx.testing import SearxTestCase - - -class TestBingImagesEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - dicto['safesearch'] = 1 - params = bing_images.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('bing.com' in params['url']) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) - - dicto['language'] = 'all' - params = bing_images.request(query, dicto) - self.assertIn('SRCHHPGUSR', params['cookies']) - self.assertIn('en', params['cookies']['SRCHHPGUSR']) - - def test_response(self): - self.assertRaises(AttributeError, bing_images.response, None) - self.assertRaises(AttributeError, bing_images.response, []) - self.assertRaises(AttributeError, bing_images.response, '') - self.assertRaises(AttributeError, bing_images.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(bing_images.response(response), []) - - response = mock.Mock(text='') - self.assertEqual(bing_images.response(response), []) - - html = """ -
    - - - -
    - """ - html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') - response = mock.Mock(text=html) - results = bing_images.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Test Query') - self.assertEqual(results[0]['url'], 'http://www.page.url/') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['thumbnail_src'], 'https://www.bing.com/th?id=HN.608003696942779811') - self.assertEqual(results[0]['img_src'], 'http://test.url/Test%20Query.jpg') - - html = """ - - - - """ - response = mock.Mock(text=html) - results = bing_images.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - html = """ -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    -
    - - - -
    - """ - html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') - response = mock.Mock(text=html) - results = bing_images.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 10) diff --git a/searx/tests/engines/test_bing_news.py b/searx/tests/engines/test_bing_news.py deleted file mode 100644 index a64d59b7b..000000000 --- a/searx/tests/engines/test_bing_news.py +++ /dev/null @@ -1,138 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import bing_news -from searx.testing import SearxTestCase -import lxml - - -class TestBingNewsEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = bing_news.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('bing.com', params['url']) - self.assertIn('fr', params['url']) - - dicto['language'] = 'all' - params = bing_news.request(query, dicto) - self.assertIn('en', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, bing_news.response, None) - self.assertRaises(AttributeError, bing_news.response, []) - self.assertRaises(AttributeError, bing_news.response, '') - self.assertRaises(AttributeError, bing_news.response, '[]') - - response = mock.Mock(content='') - self.assertEqual(bing_news.response(response), []) - - response = mock.Mock(content='') - self.assertEqual(bing_news.response(response), []) - - html = """ - - - python - Bing News - https://www.bing.com:443/news/search?q=python&setmkt=en-US&first=1&format=RSS - Search results - - http://10.53.64.9/rsslogo.gif - test - https://www.bing.com:443/news/search?q=test&setmkt=en-US&first=1&format=RSS - - Copyright - - Title - https://www.bing.com/news/apiclick.aspx?ref=FexRss&aid=&tid=c237eccc50bd4758b106a5e3c94fce09&url=http%3a%2f%2furl.of.article%2f&c=xxxxxxxxx&mkt=en-us - Article Content - Tue, 02 Jun 2015 13:37:00 GMT - Infoworld - http://a1.bing4.com/th?id=ON.13371337133713371337133713371337&pid=News - w={0}&h={1}&c=7 - - 620 - 413 - - - Another Title - https://www.bing.com/news/apiclick.aspx?ref=FexRss&aid=&tid=c237eccc50bd4758b106a5e3c94fce09&url=http%3a%2f%2fanother.url.of.article%2f&c=xxxxxxxxx&mkt=en-us - Another Article Content - Tue, 02 Jun 2015 13:37:00 GMT - - -""" # noqa - response = mock.Mock(content=html) - results = bing_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 2) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://url.of.article/') - self.assertEqual(results[0]['content'], 'Article Content') - self.assertEqual(results[0]['thumbnail'], 'https://www.bing.com/th?id=ON.13371337133713371337133713371337') - self.assertEqual(results[1]['title'], 'Another Title') - self.assertEqual(results[1]['url'], 'http://another.url.of.article/') - self.assertEqual(results[1]['content'], 'Another Article Content') - self.assertNotIn('thumbnail', results[1]) - - html = """ - - - python - Bing News - https://www.bing.com:443/news/search?q=python&setmkt=en-US&first=1&format=RSS - Search results - - http://10.53.64.9/rsslogo.gif - test - https://www.bing.com:443/news/search?q=test&setmkt=en-US&first=1&format=RSS - - Copyright - - Title - http://another.url.of.article/ - Article Content - garbage - Infoworld - http://another.bing.com/image - w={0}&h={1}&c=7 - - 620 - 413 - - -""" # noqa - response = mock.Mock(content=html) - results = bing_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://another.url.of.article/') - self.assertEqual(results[0]['content'], 'Article Content') - self.assertEqual(results[0]['thumbnail'], 'http://another.bing.com/image') - - html = """ - - - python - Bing News - https://www.bing.com:443/news/search?q=python&setmkt=en-US&first=1&format=RSS - Search results - - http://10.53.64.9/rsslogo.gif - test - https://www.bing.com:443/news/search?q=test&setmkt=en-US&first=1&format=RSS - - -""" # noqa - - response = mock.Mock(content=html) - results = bing_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - html = """gabarge""" - response = mock.Mock(content=html) - self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response) diff --git a/searx/tests/engines/test_blekko_images.py b/searx/tests/engines/test_blekko_images.py deleted file mode 100644 index beb0853e3..000000000 --- a/searx/tests/engines/test_blekko_images.py +++ /dev/null @@ -1,71 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import blekko_images -from searx.testing import SearxTestCase - - -class TestBlekkoImagesEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['safesearch'] = 1 - params = blekko_images.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('blekko.com', params['url']) - self.assertIn('page', params['url']) - - dicto['pageno'] = 1 - params = blekko_images.request(query, dicto) - self.assertNotIn('page', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, blekko_images.response, None) - self.assertRaises(AttributeError, blekko_images.response, []) - self.assertRaises(AttributeError, blekko_images.response, '') - self.assertRaises(AttributeError, blekko_images.response, '[]') - - response = mock.Mock(text='[]') - self.assertEqual(blekko_images.response(response), []) - - json = """ - [ - { - "c": 1, - "page_url": "http://result_url.html", - "title": "Photo title", - "tn_url": "http://ts1.mm.bing.net/th?id=HN.608050619474382748&pid=15.1", - "url": "http://result_image.jpg" - }, - { - "c": 2, - "page_url": "http://companyorange.simpsite.nl/OSM", - "title": "OSM", - "tn_url": "http://ts2.mm.bing.net/th?id=HN.608048068264919461&pid=15.1", - "url": "http://simpsite.nl/userdata2/58985/Home/OSM.bmp" - }, - { - "c": 3, - "page_url": "http://invincible.webklik.nl/page/osm", - "title": "OSM", - "tn_url": "http://ts1.mm.bing.net/th?id=HN.608024514657649476&pid=15.1", - "url": "http://www.webklik.nl/user_files/2009_09/65324/osm.gif" - }, - { - "c": 4, - "page_url": "http://www.offshorenorway.no/event/companyDetail/id/12492", - "title": "Go to OSM Offshore AS homepage", - "tn_url": "http://ts2.mm.bing.net/th?id=HN.608054265899847285&pid=15.1", - "url": "http://www.offshorenorway.no/firmalogo/OSM-logo.png" - } - ] - """ - response = mock.Mock(text=json) - results = blekko_images.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 4) - self.assertEqual(results[0]['title'], 'Photo title') - self.assertEqual(results[0]['url'], 'http://result_url.html') - self.assertEqual(results[0]['img_src'], 'http://result_image.jpg') diff --git a/searx/tests/engines/test_btdigg.py b/searx/tests/engines/test_btdigg.py deleted file mode 100644 index 2721f4e7c..000000000 --- a/searx/tests/engines/test_btdigg.py +++ /dev/null @@ -1,384 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import btdigg -from searx.testing import SearxTestCase - - -class TestBtdiggEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = btdigg.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('btdigg.org', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, btdigg.response, None) - self.assertRaises(AttributeError, btdigg.response, []) - self.assertRaises(AttributeError, btdigg.response, '') - self.assertRaises(AttributeError, btdigg.response, '[]') - - response = mock.Mock(content='') - self.assertEqual(btdigg.response(response), []) - - html = """ -
    - - - - - -
    1 - - - - -
    - Should be the title -
    - - - - - - - - - - - -
    - [magnet] - - [cloud] - - Taille: - 8 B - - Fichiers: - 710 - - Téléchargements: - 5 - - Temps: - 417.8 jours - - Dernière mise à jour: - 5.3 jours - - Faux: - Aucun -
    -
    -                            Content
    -                        
    -
    -
    - """ - response = mock.Mock(content=html) - results = btdigg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Should be the title') - self.assertEqual(results[0]['url'], 'https://btdigg.org/url') - self.assertEqual(results[0]['content'], 'Content') - self.assertEqual(results[0]['seed'], 5) - self.assertEqual(results[0]['leech'], 0) - self.assertEqual(results[0]['filesize'], 8) - self.assertEqual(results[0]['files'], 710) - self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:magnet&dn=Test') - - html = """ -
    - -
    -
    - """ - response = mock.Mock(content=html) - results = btdigg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - html = """ -
    - - - - - - - - - - - - - - - - - - - - - -
    1 - - - - -
    - Should be the title -
    - - - - - - - - - - - -
    - [magnet] - - [cloud] - - Taille: - 1 KB - - Fichiers: - 710 - - Téléchargements: - 5 - - Temps: - 417.8 jours - - Dernière mise à jour: - 5.3 jours - - Faux: - Aucun -
    -
    -                            Content
    -                        
    -
    1 - - - - -
    - Should be the title -
    - - - - - - - - - - - -
    - [magnet] - - [cloud] - - Taille: - 1 MB - - Fichiers: - a - - Téléchargements: - 4 - - Temps: - 417.8 jours - - Dernière mise à jour: - 5.3 jours - - Faux: - Aucun -
    -
    -                            Content
    -                        
    -
    1 - - - - -
    - Should be the title -
    - - - - - - - - - - - -
    - [magnet] - - [cloud] - - Taille: - 1 GB - - Fichiers: - 710 - - Téléchargements: - 3 - - Temps: - 417.8 jours - - Dernière mise à jour: - 5.3 jours - - Faux: - Aucun -
    -
    -                            Content
    -                        
    -
    1 - - - - -
    - Should be the title -
    - - - - - - - - - - - -
    - [magnet] - - [cloud] - - Taille: - 1 TB - - Fichiers: - 710 - - Téléchargements: - 2 - - Temps: - 417.8 jours - - Dernière mise à jour: - 5.3 jours - - Faux: - Aucun -
    -
    -                            Content
    -                        
    -
    1 - - - - -
    - Should be the title -
    - - - - - - - - - - - -
    - [magnet] - - [cloud] - - Taille: - a TB - - Fichiers: - 710 - - Téléchargements: - z - - Temps: - 417.8 jours - - Dernière mise à jour: - 5.3 jours - - Faux: - Aucun -
    -
    -                            Content
    -                        
    -
    -
    - """ - response = mock.Mock(content=html) - results = btdigg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 5) - self.assertEqual(results[0]['title'], 'Should be the title') - self.assertEqual(results[0]['url'], 'https://btdigg.org/url') - self.assertEqual(results[0]['content'], 'Content') - self.assertEqual(results[0]['seed'], 5) - self.assertEqual(results[0]['leech'], 0) - self.assertEqual(results[0]['files'], 710) - self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:magnet&dn=Test') - self.assertEqual(results[0]['filesize'], 1024) - self.assertEqual(results[1]['filesize'], 1048576) - self.assertEqual(results[2]['filesize'], 1073741824) - self.assertEqual(results[3]['filesize'], 1099511627776) diff --git a/searx/tests/engines/test_currency_convert.py b/searx/tests/engines/test_currency_convert.py deleted file mode 100644 index 84ec3b742..000000000 --- a/searx/tests/engines/test_currency_convert.py +++ /dev/null @@ -1,46 +0,0 @@ -from collections import defaultdict -from datetime import datetime -import mock -from searx.engines import currency_convert -from searx.testing import SearxTestCase - - -class TestCurrencyConvertEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = currency_convert.request(query, dicto) - self.assertNotIn('url', params) - - query = '1.1.1 EUR in USD' - params = currency_convert.request(query, dicto) - self.assertNotIn('url', params) - - query = '10 eur in usd' - params = currency_convert.request(query, dicto) - self.assertIn('url', params) - self.assertIn('finance.yahoo.com', params['url']) - self.assertIn('EUR', params['url']) - self.assertIn('USD', params['url']) - - def test_response(self): - dicto = defaultdict(dict) - dicto['ammount'] = float(10) - dicto['from'] = "EUR" - dicto['to'] = "USD" - dicto['from_name'] = "euro" - dicto['to_name'] = "United States dollar" - response = mock.Mock(text='a,b,c,d', search_params=dicto) - self.assertEqual(currency_convert.response(response), []) - - csv = "2,0.5,1" - response = mock.Mock(text=csv, search_params=dicto) - results = currency_convert.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['answer'], '10.0 EUR = 5.0 USD, 1 EUR (euro) = 0.5 USD (United States dollar)') - now_date = datetime.now().strftime('%Y%m%d') - self.assertEqual(results[0]['url'], 'https://finance.yahoo.com/currency/converter-results/' + - now_date + '/10.0-eur-to-usd.html') diff --git a/searx/tests/engines/test_dailymotion.py b/searx/tests/engines/test_dailymotion.py deleted file mode 100644 index 4c31ff5d5..000000000 --- a/searx/tests/engines/test_dailymotion.py +++ /dev/null @@ -1,74 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import dailymotion -from searx.testing import SearxTestCase - - -class TestDailymotionEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['language'] = 'fr_FR' - params = dailymotion.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('dailymotion.com' in params['url']) - self.assertTrue('fr' in params['url']) - - dicto['language'] = 'all' - params = dailymotion.request(query, dicto) - self.assertTrue('en' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, dailymotion.response, None) - self.assertRaises(AttributeError, dailymotion.response, []) - self.assertRaises(AttributeError, dailymotion.response, '') - self.assertRaises(AttributeError, dailymotion.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(dailymotion.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(dailymotion.response(response), []) - - json = """ - { - "page": 1, - "limit": 5, - "explicit": false, - "total": 289487, - "has_more": true, - "list": [ - { - "created_time": 1422173451, - "title": "Title", - "description": "Description", - "duration": 81, - "url": "http://www.url", - "thumbnail_360_url": "http://thumbnail", - "id": "x2fit7q" - } - ] - } - """ - response = mock.Mock(text=json) - results = dailymotion.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://www.url') - self.assertEqual(results[0]['content'], 'Description') - self.assertIn('x2fit7q', results[0]['embedded']) - - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.dailymotion.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = dailymotion.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_deezer.py b/searx/tests/engines/test_deezer.py deleted file mode 100644 index ad09d2a2c..000000000 --- a/searx/tests/engines/test_deezer.py +++ /dev/null @@ -1,57 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import deezer -from searx.testing import SearxTestCase - - -class TestDeezerEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = deezer.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('deezer.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, deezer.response, None) - self.assertRaises(AttributeError, deezer.response, []) - self.assertRaises(AttributeError, deezer.response, '') - self.assertRaises(AttributeError, deezer.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(deezer.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(deezer.response(response), []) - - json = """ - {"data":[ - {"id":100, "title":"Title of track", - "link":"https:\/\/www.deezer.com\/track\/1094042","duration":232, - "artist":{"id":200,"name":"Artist Name", - "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"}, - "album":{"id":118106,"title":"Album Title","type":"album"},"type":"track"} - ]} - """ - response = mock.Mock(text=json) - results = deezer.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of track') - self.assertEqual(results[0]['url'], 'https://www.deezer.com/track/1094042') - self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') - self.assertTrue('100' in results[0]['embedded']) - - json = """ - {"data":[ - {"id":200,"name":"Artist Name", - "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = deezer.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_deviantart.py b/searx/tests/engines/test_deviantart.py deleted file mode 100644 index 78a391334..000000000 --- a/searx/tests/engines/test_deviantart.py +++ /dev/null @@ -1,118 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import deviantart -from searx.testing import SearxTestCase - - -class TestDeviantartEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = deviantart.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('deviantart.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, deviantart.response, None) - self.assertRaises(AttributeError, deviantart.response, []) - self.assertRaises(AttributeError, deviantart.response, '') - self.assertRaises(AttributeError, deviantart.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(deviantart.response(response), []) - - response = mock.Mock(status_code=302) - self.assertEqual(deviantart.response(response), []) - - html = """ -
    - - - - - - - Test - - - - - - - Title of image - - - - 5 years ago - - in Animation - - - - More Like This - - - -
    - """ - response = mock.Mock(text=html) - results = deviantart.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of image') - self.assertEqual(results[0]['url'], 'http://url.of.result/2nd.part.of.url') - self.assertNotIn('content', results[0]) - self.assertEqual(results[0]['thumbnail_src'], 'https://url.of.thumbnail') - - html = """ - - - - - - Test - - - - - - - Title of image - - - - 5 years ago - - in Animation - - - - More Like This - - - """ - response = mock.Mock(text=html) - results = deviantart.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_digg.py b/searx/tests/engines/test_digg.py deleted file mode 100644 index 6e7c9cc99..000000000 --- a/searx/tests/engines/test_digg.py +++ /dev/null @@ -1,101 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import digg -from searx.testing import SearxTestCase - - -class TestDiggEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = digg.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('digg.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, digg.response, None) - self.assertRaises(AttributeError, digg.response, []) - self.assertRaises(AttributeError, digg.response, '') - self.assertRaises(AttributeError, digg.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(digg.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(digg.response(response), []) - - json = """ - { - "status": "ok", - "num": 10, - "next_position": 20, - "html": "
    - \\"\\"
    " - } - """ - json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') - response = mock.Mock(text=json) - results = digg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of article') - self.assertEqual(results[0]['url'], 'http://url.of.link') - self.assertEqual(results[0]['thumbnail'], 'http://url.of.image.jpeg') - self.assertEqual(results[0]['content'], '') - - json = """ - { - "status": "error", - "num": 10, - "next_position": 20 - } - """ - response = mock.Mock(text=json) - results = digg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_duckduckgo.py b/searx/tests/engines/test_duckduckgo.py deleted file mode 100644 index 14cd9cd87..000000000 --- a/searx/tests/engines/test_duckduckgo.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import duckduckgo -from searx.testing import SearxTestCase - - -class TestDuckduckgoEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = duckduckgo.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('duckduckgo.com', params['url']) - self.assertIn('fr-fr', params['url']) - - dicto['language'] = 'all' - params = duckduckgo.request(query, dicto) - self.assertIn('en-us', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, duckduckgo.response, None) - self.assertRaises(AttributeError, duckduckgo.response, []) - self.assertRaises(AttributeError, duckduckgo.response, '') - self.assertRaises(AttributeError, duckduckgo.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(duckduckgo.response(response), []) - - html = u""" - - """ - response = mock.Mock(text=html) - results = duckduckgo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], u'http://this.should.be.the.link/ű') - self.assertEqual(results[0]['content'], 'This should be the content.') - - html = """ - - - """ - response = mock.Mock(text=html) - results = duckduckgo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_duckduckgo_definitions.py b/searx/tests/engines/test_duckduckgo_definitions.py deleted file mode 100644 index 71c84235c..000000000 --- a/searx/tests/engines/test_duckduckgo_definitions.py +++ /dev/null @@ -1,250 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import duckduckgo_definitions -from searx.testing import SearxTestCase - - -class TestDDGDefinitionsEngine(SearxTestCase): - - def test_result_to_text(self): - url = '' - text = 'Text' - html_result = 'Html' - result = duckduckgo_definitions.result_to_text(url, text, html_result) - self.assertEqual(result, text) - - html_result = 'Text in link' - result = duckduckgo_definitions.result_to_text(url, text, html_result) - self.assertEqual(result, 'Text in link') - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = duckduckgo_definitions.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('duckduckgo.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, duckduckgo_definitions.response, None) - self.assertRaises(AttributeError, duckduckgo_definitions.response, []) - self.assertRaises(AttributeError, duckduckgo_definitions.response, '') - self.assertRaises(AttributeError, duckduckgo_definitions.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(duckduckgo_definitions.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(duckduckgo_definitions.response(response), []) - - json = """ - { - "DefinitionSource": "definition source", - "Heading": "heading", - "ImageWidth": 0, - "RelatedTopics": [ - { - "Result": "Top-level domains", - "Icon": { - "URL": "", - "Height": "", - "Width": "" - }, - "FirstURL": "https://first.url", - "Text": "text" - }, - { - "Topics": [ - { - "Result": "result topic", - "Icon": { - "URL": "", - "Height": "", - "Width": "" - }, - "FirstURL": "https://duckduckgo.com/?q=2%2F2", - "Text": "result topic text" - } - ], - "Name": "name" - } - ], - "Entity": "Entity", - "Type": "A", - "Redirect": "", - "DefinitionURL": "http://definition.url", - "AbstractURL": "https://abstract.url", - "Definition": "this is the definition", - "AbstractSource": "abstract source", - "Infobox": { - "content": [ - { - "data_type": "string", - "value": "1999", - "label": "Introduced", - "wiki_order": 0 - } - ], - "meta": [ - { - "data_type": "string", - "value": ".test", - "label": "article_title" - } - ] - }, - "Image": "image.png", - "ImageIsLogo": 0, - "Abstract": "abstract", - "AbstractText": "abstract text", - "AnswerType": "", - "ImageHeight": 0, - "Results": [{ - "Result" : "result title", - "Icon" : { - "URL" : "result url", - "Height" : 16, - "Width" : 16 - }, - "FirstURL" : "result first url", - "Text" : "result text" - } - ], - "Answer": "answer" - } - """ - response = mock.Mock(text=json) - results = duckduckgo_definitions.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 4) - self.assertEqual(results[0]['answer'], 'answer') - self.assertEqual(results[1]['title'], 'heading') - self.assertEqual(results[1]['url'], 'result first url') - self.assertEqual(results[2]['suggestion'], 'text') - self.assertEqual(results[3]['infobox'], 'heading') - self.assertEqual(results[3]['id'], 'http://definition.url') - self.assertEqual(results[3]['entity'], 'Entity') - self.assertIn('abstract', results[3]['content']) - self.assertIn('this is the definition', results[3]['content']) - self.assertEqual(results[3]['img_src'], 'image.png') - self.assertIn('Introduced', results[3]['attributes'][0]['label']) - self.assertIn('1999', results[3]['attributes'][0]['value']) - self.assertIn({'url': 'https://abstract.url', 'title': 'abstract source'}, results[3]['urls']) - self.assertIn({'url': 'http://definition.url', 'title': 'definition source'}, results[3]['urls']) - self.assertIn({'name': 'name', 'suggestions': ['result topic text']}, results[3]['relatedTopics']) - - json = """ - { - "DefinitionSource": "definition source", - "Heading": "heading", - "ImageWidth": 0, - "RelatedTopics": [], - "Entity": "Entity", - "Type": "A", - "Redirect": "", - "DefinitionURL": "", - "AbstractURL": "https://abstract.url", - "Definition": "", - "AbstractSource": "abstract source", - "Image": "", - "ImageIsLogo": 0, - "Abstract": "", - "AbstractText": "abstract text", - "AnswerType": "", - "ImageHeight": 0, - "Results": [], - "Answer": "" - } - """ - response = mock.Mock(text=json) - results = duckduckgo_definitions.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['url'], 'https://abstract.url') - self.assertEqual(results[0]['title'], 'heading') - self.assertEqual(results[0]['content'], '') - - json = """ - { - "DefinitionSource": "definition source", - "Heading": "heading", - "ImageWidth": 0, - "RelatedTopics": [ - { - "Result": "Top-level domains", - "Icon": { - "URL": "", - "Height": "", - "Width": "" - }, - "FirstURL": "https://first.url", - "Text": "heading" - }, - { - "Name": "name" - }, - { - "Topics": [ - { - "Result": "result topic", - "Icon": { - "URL": "", - "Height": "", - "Width": "" - }, - "FirstURL": "https://duckduckgo.com/?q=2%2F2", - "Text": "heading" - } - ], - "Name": "name" - } - ], - "Entity": "Entity", - "Type": "A", - "Redirect": "", - "DefinitionURL": "http://definition.url", - "AbstractURL": "https://abstract.url", - "Definition": "this is the definition", - "AbstractSource": "abstract source", - "Infobox": { - "meta": [ - { - "data_type": "string", - "value": ".test", - "label": "article_title" - } - ] - }, - "Image": "image.png", - "ImageIsLogo": 0, - "Abstract": "abstract", - "AbstractText": "abstract text", - "AnswerType": "", - "ImageHeight": 0, - "Results": [{ - "Result" : "result title", - "Icon" : { - "URL" : "result url", - "Height" : 16, - "Width" : 16 - }, - "Text" : "result text" - } - ], - "Answer": "" - } - """ - response = mock.Mock(text=json) - results = duckduckgo_definitions.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['infobox'], 'heading') - self.assertEqual(results[0]['id'], 'http://definition.url') - self.assertEqual(results[0]['entity'], 'Entity') - self.assertIn('abstract', results[0]['content']) - self.assertIn('this is the definition', results[0]['content']) - self.assertEqual(results[0]['img_src'], 'image.png') - self.assertIn({'url': 'https://abstract.url', 'title': 'abstract source'}, results[0]['urls']) - self.assertIn({'url': 'http://definition.url', 'title': 'definition source'}, results[0]['urls']) - self.assertIn({'name': 'name', 'suggestions': []}, results[0]['relatedTopics']) diff --git a/searx/tests/engines/test_dummy.py b/searx/tests/engines/test_dummy.py deleted file mode 100644 index 9399beaaf..000000000 --- a/searx/tests/engines/test_dummy.py +++ /dev/null @@ -1,26 +0,0 @@ -from searx.engines import dummy -from searx.testing import SearxTestCase - - -class TestDummyEngine(SearxTestCase): - - def test_request(self): - test_params = [ - [1, 2, 3], - ['a'], - [], - 1 - ] - for params in test_params: - self.assertEqual(dummy.request(None, params), params) - - def test_response(self): - responses = [ - None, - [], - True, - dict(), - tuple() - ] - for response in responses: - self.assertEqual(dummy.response(response), []) diff --git a/searx/tests/engines/test_faroo.py b/searx/tests/engines/test_faroo.py deleted file mode 100644 index acebdda86..000000000 --- a/searx/tests/engines/test_faroo.py +++ /dev/null @@ -1,116 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import faroo -from searx.testing import SearxTestCase - - -class TestFarooEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - dicto['category'] = 'general' - params = faroo.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('faroo.com', params['url']) - self.assertIn('en', params['url']) - self.assertIn('web', params['url']) - - dicto['language'] = 'all' - params = faroo.request(query, dicto) - self.assertIn('en', params['url']) - - dicto['language'] = 'de_DE' - params = faroo.request(query, dicto) - self.assertIn('de', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, faroo.response, None) - self.assertRaises(AttributeError, faroo.response, []) - self.assertRaises(AttributeError, faroo.response, '') - self.assertRaises(AttributeError, faroo.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(faroo.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(faroo.response(response), []) - - response = mock.Mock(text='{"data": []}', status_code=401) - self.assertRaises(Exception, faroo.response, response) - - response = mock.Mock(text='{"data": []}', status_code=429) - self.assertRaises(Exception, faroo.response, response) - - json = """ - { - "results": [ - { - "title": "This is the title", - "kwic": "This is the content", - "content": "", - "url": "http://this.is.the.url/", - "iurl": "", - "domain": "css3test.com", - "author": "Jim Dalrymple", - "news": true, - "votes": "10", - "date": 1360622563000, - "related": [] - }, - { - "title": "This is the title2", - "kwic": "This is the content2", - "content": "", - "url": "http://this.is.the.url2/", - "iurl": "", - "domain": "css3test.com", - "author": "Jim Dalrymple", - "news": false, - "votes": "10", - "related": [] - }, - { - "title": "This is the title3", - "kwic": "This is the content3", - "content": "", - "url": "http://this.is.the.url3/", - "iurl": "http://upload.wikimedia.org/optimized.jpg", - "domain": "css3test.com", - "author": "Jim Dalrymple", - "news": false, - "votes": "10", - "related": [] - } - ], - "query": "test", - "suggestions": [], - "count": 100, - "start": 1, - "length": 10, - "time": "15" - } - """ - response = mock.Mock(text=json) - results = faroo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 4) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'http://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertEqual(results[1]['title'], 'This is the title2') - self.assertEqual(results[1]['url'], 'http://this.is.the.url2/') - self.assertEqual(results[1]['content'], 'This is the content2') - self.assertEqual(results[3]['img_src'], 'http://upload.wikimedia.org/optimized.jpg') - - json = """ - {} - """ - response = mock.Mock(text=json) - results = faroo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_flickr.py b/searx/tests/engines/test_flickr.py deleted file mode 100644 index 8b39e922f..000000000 --- a/searx/tests/engines/test_flickr.py +++ /dev/null @@ -1,142 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import flickr -from searx.testing import SearxTestCase - - -class TestFlickrEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = flickr.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('flickr.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, flickr.response, None) - self.assertRaises(AttributeError, flickr.response, []) - self.assertRaises(AttributeError, flickr.response, '') - self.assertRaises(AttributeError, flickr.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(flickr.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(flickr.response(response), []) - - json = """ - { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", - "photo": [ - { "id": "15751017054", "owner": "66847915@N08", - "secret": "69c22afc40", "server": "7285", "farm": 8, - "title": "Photo title", "ispublic": 1, - "isfriend": 0, "isfamily": 0, - "description": { "_content": "Description" }, - "ownername": "Owner", - "url_o": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_9178e0f963_o.jpg", - "height_o": "2100", "width_o": "2653", - "url_n": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_n.jpg", - "height_n": "253", "width_n": "320", - "url_z": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_z.jpg", - "height_z": "507", "width_z": "640" } - ] }, "stat": "ok" } - """ - response = mock.Mock(text=json) - results = flickr.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Photo title') - self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') - self.assertTrue('o.jpg' in results[0]['img_src']) - self.assertTrue('n.jpg' in results[0]['thumbnail_src']) - self.assertTrue('Owner' in results[0]['content']) - self.assertTrue('Description' in results[0]['content']) - - json = """ - { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", - "photo": [ - { "id": "15751017054", "owner": "66847915@N08", - "secret": "69c22afc40", "server": "7285", "farm": 8, - "title": "Photo title", "ispublic": 1, - "isfriend": 0, "isfamily": 0, - "description": { "_content": "Description" }, - "ownername": "Owner", - "url_z": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_z.jpg", - "height_z": "507", "width_z": "640" } - ] }, "stat": "ok" } - """ - response = mock.Mock(text=json) - results = flickr.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Photo title') - self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') - self.assertTrue('z.jpg' in results[0]['img_src']) - self.assertTrue('z.jpg' in results[0]['thumbnail_src']) - self.assertTrue('Owner' in results[0]['content']) - self.assertTrue('Description' in results[0]['content']) - - json = """ - { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", - "photo": [ - { "id": "15751017054", "owner": "66847915@N08", - "secret": "69c22afc40", "server": "7285", "farm": 8, - "title": "Photo title", "ispublic": 1, - "isfriend": 0, "isfamily": 0, - "description": { "_content": "Description" }, - "ownername": "Owner", - "url_o": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_9178e0f963_o.jpg", - "height_o": "2100", "width_o": "2653" } - ] }, "stat": "ok" } - """ - response = mock.Mock(text=json) - results = flickr.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Photo title') - self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') - self.assertTrue('o.jpg' in results[0]['img_src']) - self.assertTrue('o.jpg' in results[0]['thumbnail_src']) - self.assertTrue('Owner' in results[0]['content']) - self.assertTrue('Description' in results[0]['content']) - - json = """ - { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", - "photo": [ - { "id": "15751017054", "owner": "66847915@N08", - "secret": "69c22afc40", "server": "7285", "farm": 8, - "title": "Photo title", "ispublic": 1, - "isfriend": 0, "isfamily": 0, - "description": { "_content": "Description" }, - "ownername": "Owner", - "url_n": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_n.jpg", - "height_n": "253", "width_n": "320" } - ] }, "stat": "ok" } - """ - response = mock.Mock(text=json) - results = flickr.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", - "toto": [] }, "stat": "ok" } - """ - response = mock.Mock(text=json) - results = flickr.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = flickr.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_flickr_noapi.py b/searx/tests/engines/test_flickr_noapi.py deleted file mode 100644 index 3b337a2d8..000000000 --- a/searx/tests/engines/test_flickr_noapi.py +++ /dev/null @@ -1,328 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import flickr_noapi -from searx.testing import SearxTestCase - - -class TestFlickrNoapiEngine(SearxTestCase): - - def test_build_flickr_url(self): - url = flickr_noapi.build_flickr_url("uid", "pid") - self.assertIn("uid", url) - self.assertIn("pid", url) - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = flickr_noapi.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('flickr.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, flickr_noapi.response, None) - self.assertRaises(AttributeError, flickr_noapi.response, []) - self.assertRaises(AttributeError, flickr_noapi.response, '') - self.assertRaises(AttributeError, flickr_noapi.response, '[]') - - response = mock.Mock(text='"search-photos-lite-models","photos":{},"totalItems":') - self.assertEqual(flickr_noapi.response(response), []) - - response = mock.Mock(text='search-photos-lite-models","photos":{"data": []},"totalItems":') - self.assertEqual(flickr_noapi.response(response), []) - - # everthing is ok test - json = """ - "search-photos-lite-models","photos": - { - "_data": [ - { - "_flickrModelRegistry": "photo-lite-models", - "title": "This is the title", - "username": "Owner", - "pathAlias": "klink692", - "realname": "Owner", - "license": 0, - "ownerNsid": "59729010@N00", - "canComment": false, - "commentCount": 14, - "faveCount": 21, - "id": "14001294434", - "sizes": { - "c": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_c.jpg", - "width": 541, - "height": 800, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_c.jpg", - "key": "c" - }, - "h": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_761d32237a_h.jpg", - "width": 1081, - "height": 1600, - "url": "//c4.staticflickr.com/8/7246/14001294434_761d32237a_h.jpg", - "key": "h" - }, - "k": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_f145a2c11a_k.jpg", - "width": 1383, - "height": 2048, - "url": "//c4.staticflickr.com/8/7246/14001294434_f145a2c11a_k.jpg", - "key": "k" - }, - "l": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_b.jpg", - "width": 692, - "height": 1024, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_b.jpg", - "key": "l" - }, - "m": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777.jpg", - "width": 338, - "height": 500, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777.jpg", - "key": "m" - }, - "n": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_n.jpg", - "width": 216, - "height": 320, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_n.jpg", - "key": "n" - }, - "q": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_q.jpg", - "width": 150, - "height": 150, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_q.jpg", - "key": "q" - }, - "s": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_m.jpg", - "width": 162, - "height": 240, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_m.jpg", - "key": "s" - }, - "sq": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_s.jpg", - "width": 75, - "height": 75, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_s.jpg", - "key": "sq" - }, - "t": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_t.jpg", - "width": 68, - "height": 100, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_t.jpg", - "key": "t" - }, - "z": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg", - "width": 433, - "height": 640, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg", - "key": "z" - } - } - } - ], - "fetchedStart": true, - "fetchedEnd": false, - "totalItems": "4386039" - },"totalItems": - """ - json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') - self.assertIn('k.jpg', results[0]['img_src']) - self.assertIn('n.jpg', results[0]['thumbnail_src']) - self.assertIn('Owner', results[0]['content']) - - # no n size, only the z size - json = """ - "search-photos-lite-models","photos": - { - "_data": [ - { - "_flickrModelRegistry": "photo-lite-models", - "title": "This is the title", - "username": "Owner", - "pathAlias": "klink692", - "realname": "Owner", - "license": 0, - "ownerNsid": "59729010@N00", - "canComment": false, - "commentCount": 14, - "faveCount": 21, - "id": "14001294434", - "sizes": { - "z": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg", - "width": 433, - "height": 640, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg", - "key": "z" - } - } - } - ], - "fetchedStart": true, - "fetchedEnd": false, - "totalItems": "4386039" - },"totalItems": - """ - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') - self.assertIn('z.jpg', results[0]['img_src']) - self.assertIn('z.jpg', results[0]['thumbnail_src']) - self.assertIn('Owner', results[0]['content']) - - # no z or n size - json = """ - "search-photos-lite-models","photos": - { - "_data": [ - { - "_flickrModelRegistry": "photo-lite-models", - "title": "This is the title", - "username": "Owner", - "pathAlias": "klink692", - "realname": "Owner", - "license": 0, - "ownerNsid": "59729010@N00", - "canComment": false, - "commentCount": 14, - "faveCount": 21, - "id": "14001294434", - "sizes": { - "o": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg", - "width": 433, - "height": 640, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg", - "key": "o" - } - } - } - ], - "fetchedStart": true, - "fetchedEnd": false, - "totalItems": "4386039" - },"totalItems": - """ - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') - self.assertIn('o.jpg', results[0]['img_src']) - self.assertIn('o.jpg', results[0]['thumbnail_src']) - self.assertIn('Owner', results[0]['content']) - - # no image test - json = """ - "search-photos-lite-models","photos": - { - "_data": [ - { - "_flickrModelRegistry": "photo-lite-models", - "title": "This is the title", - "username": "Owner", - "pathAlias": "klink692", - "realname": "Owner", - "license": 0, - "ownerNsid": "59729010@N00", - "canComment": false, - "commentCount": 14, - "faveCount": 21, - "id": "14001294434", - "sizes": { - } - } - ], - "fetchedStart": true, - "fetchedEnd": false, - "totalItems": "4386039" - },"totalItems": - """ - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - # null test - json = """ - "search-photos-models","photos": - { - "_data": [null], - "fetchedStart": true, - "fetchedEnd": false, - "totalItems": "4386039" - },"totalItems": - """ - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - # no ownerNsid test - json = """ - "search-photos-lite-models","photos": - { - "_data": [ - { - "_flickrModelRegistry": "photo-lite-models", - "title": "This is the title", - "username": "Owner", - "pathAlias": "klink692", - "realname": "Owner", - "license": 0, - "canComment": false, - "commentCount": 14, - "faveCount": 21, - "id": "14001294434", - "sizes": { - "o": { - "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg", - "width": 433, - "height": 640, - "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg", - "key": "o" - } - } - } - ], - "fetchedStart": true, - "fetchedEnd": false, - "totalItems": "4386039" - },"totalItems": - """ - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - # garbage test - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = flickr_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_gigablast.py b/searx/tests/engines/test_gigablast.py deleted file mode 100644 index 4ae0c51a9..000000000 --- a/searx/tests/engines/test_gigablast.py +++ /dev/null @@ -1,58 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import gigablast -from searx.testing import SearxTestCase - - -class TestGigablastEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['language'] = 'all' - params = gigablast.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('gigablast.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, gigablast.response, None) - self.assertRaises(AttributeError, gigablast.response, []) - self.assertRaises(AttributeError, gigablast.response, '') - self.assertRaises(AttributeError, gigablast.response, '[]') - - response = mock.Mock(content='') - self.assertEqual(gigablast.response(response), []) - - response = mock.Mock(content='') - self.assertEqual(gigablast.response(response), []) - - xml = """ - - 5941888 - 1 - - <![CDATA[This should be the title]]> - - - 90.5 - 145414002633 - 2660021087 - 2660021087 - 1320519373 - 1320519373 - 4294967295 - 0 - - - - - """ - response = mock.Mock(content=xml) - results = gigablast.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') - self.assertEqual(results[0]['content'], 'This should be the content.') diff --git a/searx/tests/engines/test_github.py b/searx/tests/engines/test_github.py deleted file mode 100644 index 460be8c3d..000000000 --- a/searx/tests/engines/test_github.py +++ /dev/null @@ -1,61 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import github -from searx.testing import SearxTestCase - - -class TestGitHubEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - params = github.request(query, defaultdict(dict)) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('github.com' in params['url']) - self.assertEqual(params['headers']['Accept'], github.accept_header) - - def test_response(self): - self.assertRaises(AttributeError, github.response, None) - self.assertRaises(AttributeError, github.response, []) - self.assertRaises(AttributeError, github.response, '') - self.assertRaises(AttributeError, github.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(github.response(response), []) - - response = mock.Mock(text='{"items": []}') - self.assertEqual(github.response(response), []) - - json = """ - { - "items": [ - { - "name": "title", - "html_url": "url", - "description": "" - } - ] - } - """ - response = mock.Mock(text=json) - results = github.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'title') - self.assertEqual(results[0]['url'], 'url') - self.assertEqual(results[0]['content'], '') - - json = """ - { - "items": [ - { - "name": "title", - "html_url": "url", - "description": "desc" - } - ] - } - """ - response = mock.Mock(text=json) - results = github.response(response) - self.assertEqual(results[0]['content'], "desc") diff --git a/searx/tests/engines/test_google.py b/searx/tests/engines/test_google.py deleted file mode 100644 index 37a83cae3..000000000 --- a/searx/tests/engines/test_google.py +++ /dev/null @@ -1,178 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -import lxml -from searx.engines import google -from searx.testing import SearxTestCase - - -class TestGoogleEngine(SearxTestCase): - - def mock_response(self, text): - response = mock.Mock(text=text, url='https://www.google.com/search?q=test&start=0&gbv=1&gws_rd=cr') - response.search_params = mock.Mock() - response.search_params.get = mock.Mock(return_value='www.google.com') - return response - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = google.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('google.fr', params['url']) - self.assertIn('fr', params['headers']['Accept-Language']) - - dicto['language'] = 'all' - params = google.request(query, dicto) - self.assertIn('google.com', params['url']) - self.assertIn('en', params['headers']['Accept-Language']) - - def test_response(self): - self.assertRaises(AttributeError, google.response, None) - self.assertRaises(AttributeError, google.response, []) - self.assertRaises(AttributeError, google.response, '') - self.assertRaises(AttributeError, google.response, '[]') - - response = self.mock_response('') - self.assertEqual(google.response(response), []) - - html = """ -
    -

    - - This is the title - -

    -
    -
    - - test.psychologies.com/ - -
    ‎ - - -
    -
    - - This should be the content. - -
    - -
    -
    -
    -

    - - This - -

    -
    -
    -

    - - This is - -

    -
    -
    -

    - - This is the - -

    -
    -
    -

    - - This is the - -

    -
    -

    - - suggestion title - -

    - """ - response = self.mock_response(html) - results = google.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 2) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') - self.assertEqual(results[0]['content'], 'This should be the content.') - self.assertEqual(results[1]['suggestion'], 'suggestion title') - - html = """ -
  • -
  • - """ - response = self.mock_response(html) - results = google.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - response = mock.Mock(text='', url='https://sorry.google.com') - response.search_params = mock.Mock() - response.search_params.get = mock.Mock(return_value='www.google.com') - self.assertRaises(RuntimeWarning, google.response, response) - - response = mock.Mock(text='', url='https://www.google.com/sorry/IndexRedirect') - response.search_params = mock.Mock() - response.search_params.get = mock.Mock(return_value='www.google.com') - self.assertRaises(RuntimeWarning, google.response, response) - - def test_parse_images(self): - html = """ -
  • -
    - - - -
    -
  • - """ - dom = lxml.html.fromstring(html) - results = google.parse_images(dom, 'www.google.com') - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['url'], 'http://this.is.the.url/') - self.assertEqual(results[0]['title'], '') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['img_src'], 'https://this.is.the.image/image.jpg') diff --git a/searx/tests/engines/test_google_images.py b/searx/tests/engines/test_google_images.py deleted file mode 100644 index 876d0af1e..000000000 --- a/searx/tests/engines/test_google_images.py +++ /dev/null @@ -1,58 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import google_images -from searx.testing import SearxTestCase - - -class TestGoogleImagesEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['safesearch'] = 1 - params = google_images.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('safe=active', params['url']) - - dicto['safesearch'] = 0 - params = google_images.request(query, dicto) - self.assertNotIn('safe', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, google_images.response, None) - self.assertRaises(AttributeError, google_images.response, []) - self.assertRaises(AttributeError, google_images.response, '') - self.assertRaises(AttributeError, google_images.response, '[]') - - response = mock.Mock(text='
    ') - self.assertEqual(google_images.response(response), []) - - html = """ -
    - -
    -
    - Image result for south -
    -
    504 × 598 - clker.com -
    -
    -
    -
    - {"id":"bQWQ9wz9loJmjM:","isu":"clker.com","ity":"png","md":"/search?tbs\u003dsbi:AMhZZit7u1mHyop9pQisu-5idR-8W_1Itvwc3afChmsjQYPx_1yYMzBvUZgtkcGoojqekKZ-6n_1rjX9ySH0OWA_1eO5OijFY6BBDw_1GApr6xxb1bXJcBcj-DiguMoXWW7cZSG7MRQbwnI5SoDZNXcv_1xGszy886I7NVb_1oRKSliTHtzqbXAxhvYreM","msu":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAQSEgltBZD3DP2WgiG-U42R4G0RFw","oh":598,"os":"13KB","ow":504,"pt":"South Arrow Clip Art at Clker.com - vector clip art online ...","rid":"vlONkeBtERfDuM","s":"Download this image as:","sc":1,"si":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAESEgltBZD3DP2WgiG-U42R4G0RFw","th":245,"tu":"https://thumbnail.url/","tw":206} -
    -
    -
    -
    - """ # noqa - response = mock.Mock(text=html) - results = google_images.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], u'South Arrow Clip Art at Clker.com - vector clip art online ...') - self.assertEqual(results[0]['url'], 'http://www.clker.com/clipart-south-arrow.html') - self.assertEqual(results[0]['thumbnail_src'], 'https://thumbnail.url/') - self.assertEqual(results[0]['img_src'], 'http://www.clker.com/cliparts/H/X/l/b/0/0/south-arrow-hi.png') - self.assertEqual(results[0]['content'], 'Download this image as:') diff --git a/searx/tests/engines/test_google_news.py b/searx/tests/engines/test_google_news.py deleted file mode 100644 index 31d674121..000000000 --- a/searx/tests/engines/test_google_news.py +++ /dev/null @@ -1,136 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import google_news -from searx.testing import SearxTestCase - - -class TestGoogleNewsEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = google_news.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('googleapis.com', params['url']) - self.assertIn('fr', params['url']) - - dicto['language'] = 'all' - params = google_news.request(query, dicto) - self.assertIn('url', params) - self.assertIn('en', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, google_news.response, None) - self.assertRaises(AttributeError, google_news.response, []) - self.assertRaises(AttributeError, google_news.response, '') - self.assertRaises(AttributeError, google_news.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(google_news.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(google_news.response(response), []) - - json = """ - { - "responseData": { - "results": [ - { - "GsearchResultClass": "GnewsSearch", - "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr", - "content": "This is the content", - "unescapedUrl": "http://this.is.the.url", - "url": "http://this.is.the.url", - "title": "This is the title", - "titleNoFormatting": "This is the title", - "location": "", - "publisher": "Jeux Actu", - "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800", - "signedRedirectUrl": "http://news.google.com/", - "language": "fr", - "image": { - "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg", - "tbUrl": "http://t1.gstatic.com/images?q=tbn:ANd9GcSF4yYrs9Ycw23DGiOSAZ-5SEPXYwG3LNs", - "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm", - "publisher": "Jeux Actu", - "tbWidth": 80, - "tbHeight": 30 - }, - "relatedStories": [ - { - "unescapedUrl": "http://www.jeuxvideo.com/test/415823/dying-light.htm", - "url": "http%3A%2F%2Fwww.jeuxvideo.com%2Ftest%2F415823%2Fdying-light.htm", - "title": "Test du jeu Dying Light - jeuxvideo.com", - "titleNoFormatting": "Test du jeu Dying Light - jeuxvideo.com", - "location": "", - "publisher": "JeuxVideo.com", - "publishedDate": "Fri, 30 Jan 2015 08:52:30 -0800", - "signedRedirectUrl": "http://news.google.com/news/url?sa=T&", - "language": "fr" - } - ] - } - ] - }, - "responseDetails": null, - "responseStatus": 200 - } - """ - response = mock.Mock(text=json) - results = google_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'http://this.is.the.url') - self.assertEqual(results[0]['content'], 'This is the content') - - json = """ - { - "responseData": { - "results": [ - { - "GsearchResultClass": "GnewsSearch", - "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr", - "content": "This is the content", - "unescapedUrl": "http://this.is.the.url", - "title": "This is the title", - "titleNoFormatting": "This is the title", - "location": "", - "publisher": "Jeux Actu", - "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800", - "signedRedirectUrl": "http://news.google.com/news/", - "language": "fr", - "image": { - "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg", - "tbUrl": "http://t1.gstatic.com/images?q=tbn:b_6f-OSAZ-5SEPXYwG3LNs", - "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm", - "publisher": "Jeux Actu", - "tbWidth": 80, - "tbHeight": 30 - } - } - ] - }, - "responseDetails": null, - "responseStatus": 200 - } - """ - response = mock.Mock(text=json) - results = google_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "responseData": {}, - "responseDetails": null, - "responseStatus": 200 - } - """ - response = mock.Mock(text=json) - results = google_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_kickass.py b/searx/tests/engines/test_kickass.py deleted file mode 100644 index 4cfcaa63c..000000000 --- a/searx/tests/engines/test_kickass.py +++ /dev/null @@ -1,397 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import kickass -from searx.testing import SearxTestCase - - -class TestKickassEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = kickass.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('kickass.to', params['url']) - self.assertFalse(params['verify']) - - def test_response(self): - self.assertRaises(AttributeError, kickass.response, None) - self.assertRaises(AttributeError, kickass.response, []) - self.assertRaises(AttributeError, kickass.response, '') - self.assertRaises(AttributeError, kickass.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(kickass.response(response), []) - - html = """ - - - - - - - - - - - - - - - - - -
    torrent name - size - - files - - age - - seed - - leech -
    - -
    - - -
    - - This should be the title - - - Posted by - riri in - - Other > Unsorted - - -
    -
    449 bytes42 years101
    - """ - response = mock.Mock(text=html) - results = kickass.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') - self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') - self.assertEqual(results[0]['seed'], 10) - self.assertEqual(results[0]['leech'], 1) - self.assertEqual(results[0]['filesize'], 449) - self.assertEqual(results[0]['files'], 4) - self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETURL&dn=test') - self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/53917.torrent?title=test') - - html = """ - - - - - - - - - -
    torrent name - size - - files - - age - - seed - - leech -
    - """ - response = mock.Mock(text=html) - results = kickass.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - html = """ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    torrent name - size - - files - - age - - seed - - leech -
    - -
    - - -
    - - This should be the title - - - Posted by - riri in - - Other > Unsorted - - -
    -
    1 KB42 years101
    - -
    - - -
    - - This should be the title - - - Posted by - riri in - - Other > Unsorted - - -
    -
    1 MB42 years91
    - -
    - - -
    - - This should be the title - - - Posted by - riri in - - Other > Unsorted - - -
    -
    1 GB42 years81
    - -
    - - -
    - - This should be the title - - - Posted by - riri in - - Other > Unsorted - - -
    -
    1 TB42 years71
    - -
    - - -
    - - This should be the title - - - Posted by - riri in - - Other > Unsorted - - -
    -
    z bytesr2 yearsat
    - """ - response = mock.Mock(text=html) - results = kickass.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 5) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') - self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') - self.assertEqual(results[0]['seed'], 10) - self.assertEqual(results[0]['leech'], 1) - self.assertEqual(results[0]['files'], 4) - self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETURL&dn=test') - self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/53917.torrent?title=test') - self.assertEqual(results[0]['filesize'], 1024) - self.assertEqual(results[1]['filesize'], 1048576) - self.assertEqual(results[2]['filesize'], 1073741824) - self.assertEqual(results[3]['filesize'], 1099511627776) - self.assertEqual(results[4]['seed'], 0) - self.assertEqual(results[4]['leech'], 0) - self.assertEqual(results[4]['files'], None) - self.assertEqual(results[4]['filesize'], None) diff --git a/searx/tests/engines/test_mediawiki.py b/searx/tests/engines/test_mediawiki.py deleted file mode 100644 index 63f7da6b2..000000000 --- a/searx/tests/engines/test_mediawiki.py +++ /dev/null @@ -1,130 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import mediawiki -from searx.testing import SearxTestCase - - -class TestMediawikiEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = mediawiki.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('wikipedia.org', params['url']) - self.assertIn('fr', params['url']) - - dicto['language'] = 'all' - params = mediawiki.request(query, dicto) - self.assertIn('en', params['url']) - - mediawiki.base_url = "http://test.url/" - mediawiki.search_url = mediawiki.base_url +\ - 'w/api.php?action=query'\ - '&list=search'\ - '&{query}'\ - '&srprop=timestamp'\ - '&format=json'\ - '&sroffset={offset}'\ - '&srlimit={limit}' # noqa - params = mediawiki.request(query, dicto) - self.assertIn('test.url', params['url']) - - def test_response(self): - dicto = defaultdict(dict) - dicto['language'] = 'fr' - mediawiki.base_url = "https://{language}.wikipedia.org/" - - self.assertRaises(AttributeError, mediawiki.response, None) - self.assertRaises(AttributeError, mediawiki.response, []) - self.assertRaises(AttributeError, mediawiki.response, '') - self.assertRaises(AttributeError, mediawiki.response, '[]') - - response = mock.Mock(text='{}', search_params=dicto) - self.assertEqual(mediawiki.response(response), []) - - response = mock.Mock(text='{"data": []}', search_params=dicto) - self.assertEqual(mediawiki.response(response), []) - - json = """ - { - "query-continue": { - "search": { - "sroffset": 1 - } - }, - "query": { - "searchinfo": { - "totalhits": 29721 - }, - "search": [ - { - "ns": 0, - "title": "This is the title étude", - "timestamp": "2014-12-19T17:42:52Z" - } - ] - } - } - """ - response = mock.Mock(text=json, search_params=dicto) - results = mediawiki.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], u'This is the title étude') - self.assertIn('fr.wikipedia.org', results[0]['url']) - self.assertIn('This_is_the_title', results[0]['url']) - self.assertIn('%C3%A9tude', results[0]['url']) - self.assertEqual(results[0]['content'], '') - - json = """ - { - "query-continue": { - "search": { - "sroffset": 1 - } - }, - "query": { - "searchinfo": { - "totalhits": 29721 - }, - "search": [ - ] - } - } - """ - response = mock.Mock(text=json, search_params=dicto) - results = mediawiki.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "query-continue": { - "search": { - "sroffset": 1 - } - }, - "query": { - } - } - """ - response = mock.Mock(text=json, search_params=dicto) - results = mediawiki.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.mediawiki.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json, search_params=dicto) - results = mediawiki.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_mixcloud.py b/searx/tests/engines/test_mixcloud.py deleted file mode 100644 index a2ea47cf9..000000000 --- a/searx/tests/engines/test_mixcloud.py +++ /dev/null @@ -1,67 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import mixcloud -from searx.testing import SearxTestCase - - -class TestMixcloudEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = mixcloud.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('mixcloud.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, mixcloud.response, None) - self.assertRaises(AttributeError, mixcloud.response, []) - self.assertRaises(AttributeError, mixcloud.response, '') - self.assertRaises(AttributeError, mixcloud.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(mixcloud.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(mixcloud.response(response), []) - - json = """ - {"data":[ - { - "user": { - "url": "http://www.mixcloud.com/user/", - "username": "user", - "name": "User", - "key": "/user/" - }, - "key": "/user/this-is-the-url/", - "created_time": "2014-11-14T13:30:02Z", - "audio_length": 3728, - "slug": "this-is-the-url", - "name": "Title of track", - "url": "http://www.mixcloud.com/user/this-is-the-url/", - "updated_time": "2014-11-14T13:14:10Z" - } - ]} - """ - response = mock.Mock(text=json) - results = mixcloud.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of track') - self.assertEqual(results[0]['url'], 'http://www.mixcloud.com/user/this-is-the-url/') - self.assertEqual(results[0]['content'], 'User') - self.assertTrue('http://www.mixcloud.com/user/this-is-the-url/' in results[0]['embedded']) - - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.mixcloud.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = mixcloud.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_openstreetmap.py b/searx/tests/engines/test_openstreetmap.py deleted file mode 100644 index 7b7783f04..000000000 --- a/searx/tests/engines/test_openstreetmap.py +++ /dev/null @@ -1,199 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import openstreetmap -from searx.testing import SearxTestCase - - -class TestOpenstreetmapEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = openstreetmap.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('openstreetmap.org', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, openstreetmap.response, None) - self.assertRaises(AttributeError, openstreetmap.response, []) - self.assertRaises(AttributeError, openstreetmap.response, '') - self.assertRaises(AttributeError, openstreetmap.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(openstreetmap.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(openstreetmap.response(response), []) - - json = """ - [ - { - "place_id": "127732055", - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", - "osm_type": "relation", - "osm_id": "7444", - "boundingbox": [ - "48.8155755", - "48.902156", - "2.224122", - "2.4697602" - ], - "lat": "48.8565056", - "lon": "2.3521334", - "display_name": "This is the title", - "class": "place", - "type": "city", - "importance": 0.96893459932191, - "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", - "address": { - "city": "Paris", - "county": "Paris", - "state": "Île-de-France", - "country": "France", - "country_code": "fr" - }, - "geojson": { - "type": "Polygon", - "coordinates": [ - [ - [ - 2.224122, - 48.854199 - ] - ] - ] - } - } - ] - """ - response = mock.Mock(text=json) - results = openstreetmap.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://openstreetmap.org/relation/7444') - self.assertIn('coordinates', results[0]['geojson']) - self.assertEqual(results[0]['geojson']['coordinates'][0][0][0], 2.224122) - self.assertEqual(results[0]['geojson']['coordinates'][0][0][1], 48.854199) - self.assertEqual(results[0]['address'], None) - self.assertIn('48.8155755', results[0]['boundingbox']) - self.assertIn('48.902156', results[0]['boundingbox']) - self.assertIn('2.224122', results[0]['boundingbox']) - self.assertIn('2.4697602', results[0]['boundingbox']) - - json = """ - [ - { - "place_id": "127732055", - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", - "osm_type": "relation", - "osm_id": "7444", - "boundingbox": [ - "48.8155755", - "48.902156", - "2.224122", - "2.4697602" - ], - "lat": "48.8565056", - "lon": "2.3521334", - "display_name": "This is the title", - "class": "tourism", - "type": "city", - "importance": 0.96893459932191, - "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", - "address": { - "city": "Paris", - "county": "Paris", - "state": "Île-de-France", - "country": "France", - "country_code": "fr", - "address29": "Address" - }, - "geojson": { - "type": "Polygon", - "coordinates": [ - [ - [ - 2.224122, - 48.854199 - ] - ] - ] - } - }, - { - "place_id": "127732055", - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", - "osm_type": "relation", - "osm_id": "7444", - "boundingbox": [ - "48.8155755", - "48.902156", - "2.224122", - "2.4697602" - ], - "lat": "48.8565056", - "lon": "2.3521334", - "display_name": "This is the title", - "class": "tourism", - "type": "city", - "importance": 0.96893459932191, - "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", - "address": { - "city": "Paris", - "county": "Paris", - "state": "Île-de-France", - "country": "France", - "postcode": 75000, - "country_code": "fr" - }, - "geojson": { - "type": "Polygon", - "coordinates": [ - [ - [ - 2.224122, - 48.854199 - ] - ] - ] - } - }, - { - "place_id": "127732055", - "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", - "osm_type": "node", - "osm_id": "7444", - "boundingbox": [ - "48.8155755", - "48.902156", - "2.224122", - "2.4697602" - ], - "lat": "48.8565056", - "lon": "2.3521334", - "display_name": "This is the title", - "class": "tourism", - "type": "city", - "importance": 0.96893459932191, - "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", - "address": { - "city": "Paris", - "county": "Paris", - "state": "Île-de-France", - "country": "France", - "country_code": "fr", - "address29": "Address" - } - } - ] - """ - response = mock.Mock(text=json) - results = openstreetmap.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 3) - self.assertIn('48.8565056', results[2]['geojson']['coordinates']) - self.assertIn('2.3521334', results[2]['geojson']['coordinates']) diff --git a/searx/tests/engines/test_photon.py b/searx/tests/engines/test_photon.py deleted file mode 100644 index 734497884..000000000 --- a/searx/tests/engines/test_photon.py +++ /dev/null @@ -1,166 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import photon -from searx.testing import SearxTestCase - - -class TestPhotonEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'all' - params = photon.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('photon.komoot.de', params['url']) - - dicto['language'] = 'all' - params = photon.request(query, dicto) - self.assertNotIn('lang', params['url']) - - dicto['language'] = 'al' - params = photon.request(query, dicto) - self.assertNotIn('lang', params['url']) - - dicto['language'] = 'fr' - params = photon.request(query, dicto) - self.assertIn('fr', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, photon.response, None) - self.assertRaises(AttributeError, photon.response, []) - self.assertRaises(AttributeError, photon.response, '') - self.assertRaises(AttributeError, photon.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(photon.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(photon.response(response), []) - - json = """ - { - "features": [ - { - "properties": { - "osm_key": "waterway", - "extent": [ - -1.4508446, - 51.1614997, - -1.4408036, - 51.1525635 - ], - "name": "This is the title", - "state": "England", - "osm_id": 114823817, - "osm_type": "W", - "osm_value": "river", - "city": "Test Valley", - "country": "United Kingdom" - }, - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - -1.4458571, - 51.1576661 - ] - } - }, - { - "properties": { - "osm_key": "place", - "street": "Rue", - "state": "Ile-de-France", - "osm_id": 129211377, - "osm_type": "R", - "housenumber": "10", - "postcode": "75011", - "osm_value": "house", - "city": "Paris", - "country": "France" - }, - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - 2.3725025, - 48.8654481 - ] - } - }, - { - "properties": { - "osm_key": "amenity", - "street": "Allée", - "name": "Bibliothèque", - "state": "Ile-de-France", - "osm_id": 1028573132, - "osm_type": "N", - "postcode": "75001", - "osm_value": "library", - "city": "Paris", - "country": "France" - }, - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - 2.3445634, - 48.862494 - ] - } - }, - { - "properties": { - "osm_key": "amenity", - "osm_id": 1028573132, - "osm_type": "Y", - "postcode": "75001", - "osm_value": "library", - "city": "Paris", - "country": "France" - }, - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ - 2.3445634, - 48.862494 - ] - } - }, - { - } - ], - "type": "FeatureCollection" - } - """ - response = mock.Mock(text=json) - results = photon.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 3) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['longitude'], -1.4458571) - self.assertEqual(results[0]['latitude'], 51.1576661) - self.assertIn(-1.4508446, results[0]['boundingbox']) - self.assertIn(51.1614997, results[0]['boundingbox']) - self.assertIn(-1.4408036, results[0]['boundingbox']) - self.assertIn(51.1525635, results[0]['boundingbox']) - self.assertIn('type', results[0]['geojson']) - self.assertEqual(results[0]['geojson']['type'], 'Point') - self.assertEqual(results[0]['address'], None) - self.assertEqual(results[0]['osm']['type'], 'way') - self.assertEqual(results[0]['osm']['id'], 114823817) - self.assertEqual(results[0]['url'], 'https://openstreetmap.org/way/114823817') - self.assertEqual(results[1]['osm']['type'], 'relation') - self.assertEqual(results[2]['address']['name'], u'Bibliothèque') - self.assertEqual(results[2]['address']['house_number'], None) - self.assertEqual(results[2]['address']['locality'], 'Paris') - self.assertEqual(results[2]['address']['postcode'], '75001') - self.assertEqual(results[2]['address']['country'], 'France') - self.assertEqual(results[2]['osm']['type'], 'node') diff --git a/searx/tests/engines/test_piratebay.py b/searx/tests/engines/test_piratebay.py deleted file mode 100644 index 5699380be..000000000 --- a/searx/tests/engines/test_piratebay.py +++ /dev/null @@ -1,166 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import piratebay -from searx.testing import SearxTestCase - - -class TestPiratebayEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['category'] = 'Toto' - params = piratebay.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('piratebay.se', params['url']) - self.assertIn('0', params['url']) - - dicto['category'] = 'music' - params = piratebay.request(query, dicto) - self.assertIn('100', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, piratebay.response, None) - self.assertRaises(AttributeError, piratebay.response, []) - self.assertRaises(AttributeError, piratebay.response, '') - self.assertRaises(AttributeError, piratebay.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(piratebay.response(response), []) - - html = """ - - - - - - - - - - - - - - - -
    -
    - Anime
    - (Anime) -
    -
    - - - Magnet link - - - Download - - - VIP - - - - This is the content and should be OK - - 13334
    -
    - Anime
    - (Anime) -
    -
    - - - Magnet link - - - VIP - - - - This is the content and should be OK - - 13334
    - """ - response = mock.Mock(text=html) - results = piratebay.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 2) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link') - self.assertEqual(results[0]['content'], 'This is the content and should be OK') - self.assertEqual(results[0]['seed'], 13) - self.assertEqual(results[0]['leech'], 334) - self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') - self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') - - self.assertEqual(results[1]['torrentfile'], None) - - html = """ - - - - - - - - - -
    -
    - Anime
    - (Anime) -
    -
    - - - Magnet link - - - Download - - - VIP - - - - This is the content and should be OK - - sd
    - """ - response = mock.Mock(text=html) - results = piratebay.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link') - self.assertEqual(results[0]['content'], 'This is the content and should be OK') - self.assertEqual(results[0]['seed'], 0) - self.assertEqual(results[0]['leech'], 0) - self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') - self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') - - html = """ - -
    - """ - response = mock.Mock(text=html) - results = piratebay.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_qwant.py b/searx/tests/engines/test_qwant.py deleted file mode 100644 index 7d79d13d8..000000000 --- a/searx/tests/engines/test_qwant.py +++ /dev/null @@ -1,317 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import qwant -from searx.testing import SearxTestCase - - -class TestQwantEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['language'] = 'fr_FR' - qwant.categories = [''] - params = qwant.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('web', params['url']) - self.assertIn('qwant.com', params['url']) - self.assertIn('fr_fr', params['url']) - - dicto['language'] = 'all' - qwant.categories = ['news'] - params = qwant.request(query, dicto) - self.assertFalse('fr' in params['url']) - self.assertIn('news', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, qwant.response, None) - self.assertRaises(AttributeError, qwant.response, []) - self.assertRaises(AttributeError, qwant.response, '') - self.assertRaises(AttributeError, qwant.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(qwant.response(response), []) - - response = mock.Mock(text='{"data": {}}') - self.assertEqual(qwant.response(response), []) - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "result": { - "items": [ - { - "title": "Title", - "score": 9999, - "url": "http://www.url.xyz", - "source": "...", - "desc": "Description", - "date": "", - "_id": "db0aadd62c2a8565567ffc382f5c61fa", - "favicon": "https://s.qwant.com/fav.ico" - } - ], - "filters": [] - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - qwant.categories = ['general'] - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://www.url.xyz') - self.assertEqual(results[0]['content'], 'Description') - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "result": { - "items": [ - { - "title": "Title", - "score": 9999, - "url": "http://www.url.xyz", - "source": "...", - "media": "http://image.jpg", - "desc": "", - "thumbnail": "http://thumbnail.jpg", - "date": "", - "_id": "db0aadd62c2a8565567ffc382f5c61fa", - "favicon": "https://s.qwant.com/fav.ico" - } - ], - "filters": [] - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - qwant.categories = ['images'] - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://www.url.xyz') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['thumbnail_src'], 'http://thumbnail.jpg') - self.assertEqual(results[0]['img_src'], 'http://image.jpg') - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "result": { - "items": [ - { - "title": "Title", - "score": 9999, - "url": "http://www.url.xyz", - "source": "...", - "desc": "Description", - "date": 1433260920, - "_id": "db0aadd62c2a8565567ffc382f5c61fa", - "favicon": "https://s.qwant.com/fav.ico" - } - ], - "filters": [] - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - qwant.categories = ['news'] - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://www.url.xyz') - self.assertEqual(results[0]['content'], 'Description') - self.assertIn('publishedDate', results[0]) - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "result": { - "items": [ - { - "title": "Title", - "score": 9999, - "url": "http://www.url.xyz", - "source": "...", - "desc": "Description", - "date": 1433260920, - "_id": "db0aadd62c2a8565567ffc382f5c61fa", - "favicon": "https://s.qwant.com/fav.ico" - } - ], - "filters": [] - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - qwant.categories = ['social media'] - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'http://www.url.xyz') - self.assertEqual(results[0]['content'], 'Description') - self.assertIn('publishedDate', results[0]) - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "result": { - "items": [ - { - "title": "Title", - "score": 9999, - "url": "http://www.url.xyz", - "source": "...", - "desc": "Description", - "date": 1433260920, - "_id": "db0aadd62c2a8565567ffc382f5c61fa", - "favicon": "https://s.qwant.com/fav.ico" - } - ], - "filters": [] - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - qwant.categories = [''] - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "result": { - "filters": [] - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "status": "success", - "data": { - "query": { - "locale": "en_us", - "query": "Test", - "offset": 10 - }, - "cache": { - "key": "e66aa864c00147a0e3a16ff7a5efafde", - "created": 1433092754, - "expiration": 259200, - "status": "miss", - "age": 0 - } - } - } - """ - response = mock.Mock(text=json) - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "status": "success" - } - """ - response = mock.Mock(text=json) - results = qwant.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_searchcode_code.py b/searx/tests/engines/test_searchcode_code.py deleted file mode 100644 index c0ac2025c..000000000 --- a/searx/tests/engines/test_searchcode_code.py +++ /dev/null @@ -1,75 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import searchcode_code -from searx.testing import SearxTestCase - - -class TestSearchcodeCodeEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = searchcode_code.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('searchcode.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, searchcode_code.response, None) - self.assertRaises(AttributeError, searchcode_code.response, []) - self.assertRaises(AttributeError, searchcode_code.response, '') - self.assertRaises(AttributeError, searchcode_code.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(searchcode_code.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(searchcode_code.response(response), []) - - json = """ - { - "matchterm": "test", - "previouspage": null, - "searchterm": "test", - "query": "test", - "total": 1000, - "page": 0, - "nextpage": 1, - "results": [ - { - "repo": "https://repo", - "linescount": 1044, - "location": "/tests", - "name": "Name", - "url": "https://url", - "md5hash": "ecac6e479edd2b9406c9e08603cec655", - "lines": { - "1": "// Test 011", - "2": "// Source: " - }, - "id": 51223527, - "filename": "File.CPP" - } - ] - } - """ - response = mock.Mock(text=json) - results = searchcode_code.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Name - File.CPP') - self.assertEqual(results[0]['url'], 'https://url') - self.assertEqual(results[0]['repository'], 'https://repo') - self.assertEqual(results[0]['code_language'], 'cpp') - - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.searchcode_code.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = searchcode_code.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_searchcode_doc.py b/searx/tests/engines/test_searchcode_doc.py deleted file mode 100644 index b9dcf380b..000000000 --- a/searx/tests/engines/test_searchcode_doc.py +++ /dev/null @@ -1,73 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import searchcode_doc -from searx.testing import SearxTestCase - - -class TestSearchcodeDocEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = searchcode_doc.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('searchcode.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, searchcode_doc.response, None) - self.assertRaises(AttributeError, searchcode_doc.response, []) - self.assertRaises(AttributeError, searchcode_doc.response, '') - self.assertRaises(AttributeError, searchcode_doc.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(searchcode_doc.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(searchcode_doc.response(response), []) - - json = """ - { - "matchterm": "test", - "previouspage": null, - "searchterm": "test", - "query": "test", - "total": 60, - "page": 0, - "nextpage": 1, - "results": [ - { - "synopsis": "Synopsis", - "displayname": null, - "name": "test", - "url": "http://url", - "type": "Type", - "icon": null, - "namespace": "Namespace", - "description": "Description" - } - ] - } - """ - response = mock.Mock(text=json) - results = searchcode_doc.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], '[Type] Namespace test') - self.assertEqual(results[0]['url'], 'http://url') - self.assertIn('Synopsis', results[0]['content']) - self.assertIn('Type', results[0]['content']) - self.assertIn('test', results[0]['content']) - self.assertIn('Description', results[0]['content']) - - json = """ - {"toto":[ - {"id":200,"name":"Artist Name", - "link":"http:\/\/www.searchcode_doc.com\/artist\/1217","type":"artist"} - ]} - """ - response = mock.Mock(text=json) - results = searchcode_doc.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_soundcloud.py b/searx/tests/engines/test_soundcloud.py deleted file mode 100644 index 85495dc57..000000000 --- a/searx/tests/engines/test_soundcloud.py +++ /dev/null @@ -1,192 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import soundcloud -from searx.testing import SearxTestCase -from urllib import quote_plus - - -class TestSoundcloudEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = soundcloud.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('soundcloud.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, soundcloud.response, None) - self.assertRaises(AttributeError, soundcloud.response, []) - self.assertRaises(AttributeError, soundcloud.response, '') - self.assertRaises(AttributeError, soundcloud.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(soundcloud.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(soundcloud.response(response), []) - - json = """ - { - "collection": [ - { - "kind": "track", - "id": 159723640, - "created_at": "2014/07/22 00:51:21 +0000", - "user_id": 2976616, - "duration": 303780, - "commentable": true, - "state": "finished", - "original_content_size": 13236349, - "last_modified": "2015/01/31 15:14:50 +0000", - "sharing": "public", - "tag_list": "seekae flume", - "permalink": "seekae-test-recognise-flume-re-work", - "streamable": true, - "embeddable_by": "all", - "downloadable": true, - "purchase_url": "http://www.facebook.com/seekaemusic", - "label_id": null, - "purchase_title": "Seekae", - "genre": "freedownload", - "title": "This is the title", - "description": "This is the content", - "label_name": "Future Classic", - "release": "", - "track_type": "remix", - "key_signature": "", - "isrc": "", - "video_url": null, - "bpm": null, - "release_year": 2014, - "release_month": 7, - "release_day": 22, - "original_format": "mp3", - "license": "all-rights-reserved", - "uri": "https://api.soundcloud.com/tracks/159723640", - "user": { - "id": 2976616, - "kind": "user", - "permalink": "flume", - "username": "Flume", - "last_modified": "2014/11/24 19:21:29 +0000", - "uri": "https://api.soundcloud.com/users/2976616", - "permalink_url": "http://soundcloud.com/flume", - "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg" - }, - "permalink_url": "http://soundcloud.com/this.is.the.url", - "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg", - "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png", - "stream_url": "https://api.soundcloud.com/tracks/159723640/stream", - "download_url": "https://api.soundcloud.com/tracks/159723640/download", - "playback_count": 2190687, - "download_count": 54856, - "favoritings_count": 49061, - "comment_count": 826, - "likes_count": 49061, - "reposts_count": 15910, - "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments", - "policy": "ALLOW" - } - ], - "total_results": 375750, - "next_href": "https://api.soundcloud.com/search?&q=test", - "tx_id": "" - } - """ - response = mock.Mock(text=json) - results = soundcloud.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'http://soundcloud.com/this.is.the.url') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertIn(quote_plus('https://api.soundcloud.com/tracks/159723640'), results[0]['embedded']) - - json = """ - { - "collection": [ - { - "kind": "user", - "id": 159723640, - "created_at": "2014/07/22 00:51:21 +0000", - "user_id": 2976616, - "duration": 303780, - "commentable": true, - "state": "finished", - "original_content_size": 13236349, - "last_modified": "2015/01/31 15:14:50 +0000", - "sharing": "public", - "tag_list": "seekae flume", - "permalink": "seekae-test-recognise-flume-re-work", - "streamable": true, - "embeddable_by": "all", - "downloadable": true, - "purchase_url": "http://www.facebook.com/seekaemusic", - "label_id": null, - "purchase_title": "Seekae", - "genre": "freedownload", - "title": "This is the title", - "description": "This is the content", - "label_name": "Future Classic", - "release": "", - "track_type": "remix", - "key_signature": "", - "isrc": "", - "video_url": null, - "bpm": null, - "release_year": 2014, - "release_month": 7, - "release_day": 22, - "original_format": "mp3", - "license": "all-rights-reserved", - "uri": "https://api.soundcloud.com/tracks/159723640", - "user": { - "id": 2976616, - "kind": "user", - "permalink": "flume", - "username": "Flume", - "last_modified": "2014/11/24 19:21:29 +0000", - "uri": "https://api.soundcloud.com/users/2976616", - "permalink_url": "http://soundcloud.com/flume", - "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg" - }, - "permalink_url": "http://soundcloud.com/this.is.the.url", - "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg", - "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png", - "stream_url": "https://api.soundcloud.com/tracks/159723640/stream", - "download_url": "https://api.soundcloud.com/tracks/159723640/download", - "playback_count": 2190687, - "download_count": 54856, - "favoritings_count": 49061, - "comment_count": 826, - "likes_count": 49061, - "reposts_count": 15910, - "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments", - "policy": "ALLOW" - } - ], - "total_results": 375750, - "next_href": "https://api.soundcloud.com/search?&q=test", - "tx_id": "" - } - """ - response = mock.Mock(text=json) - results = soundcloud.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "collection": [], - "total_results": 375750, - "next_href": "https://api.soundcloud.com/search?&q=test", - "tx_id": "" - } - """ - response = mock.Mock(text=json) - results = soundcloud.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_spotify.py b/searx/tests/engines/test_spotify.py deleted file mode 100644 index fd274abbd..000000000 --- a/searx/tests/engines/test_spotify.py +++ /dev/null @@ -1,124 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import spotify -from searx.testing import SearxTestCase - - -class TestSpotifyEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = spotify.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('spotify.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, spotify.response, None) - self.assertRaises(AttributeError, spotify.response, []) - self.assertRaises(AttributeError, spotify.response, '') - self.assertRaises(AttributeError, spotify.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(spotify.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(spotify.response(response), []) - - json = """ - { - "tracks": { - "href": "https://api.spotify.com/v1/search?query=nosfell&offset=0&limit=20&type=track", - "items": [ - { - "album": { - "album_type": "album", - "external_urls": { - "spotify": "https://open.spotify.com/album/5c9ap1PBkSGLxT3J73toxA" - }, - "href": "https://api.spotify.com/v1/albums/5c9ap1PBkSGLxT3J73toxA", - "id": "5c9ap1PBkSGLxT3J73toxA", - "name": "Album Title", - "type": "album", - "uri": "spotify:album:5c9ap1PBkSGLxT3J73toxA" - }, - "artists": [ - { - "external_urls": { - "spotify": "https://open.spotify.com/artist/0bMc6b75FfZEpQHG1jifKu" - }, - "href": "https://api.spotify.com/v1/artists/0bMc6b75FfZEpQHG1jifKu", - "id": "0bMc6b75FfZEpQHG1jifKu", - "name": "Artist Name", - "type": "artist", - "uri": "spotify:artist:0bMc6b75FfZEpQHG1jifKu" - } - ], - "disc_number": 1, - "duration_ms": 202386, - "explicit": false, - "external_ids": { - "isrc": "FRV640600067" - }, - "external_urls": { - "spotify": "https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa" - }, - "href": "https://api.spotify.com/v1/tracks/2GzvFiedqW8hgqUpWcASZa", - "id": "1000", - "is_playable": true, - "name": "Title of track", - "popularity": 6, - "preview_url": "https://p.scdn.co/mp3-preview/7b8ecda580965a066b768c2647f877e43f7b1a0a", - "track_number": 3, - "type": "track", - "uri": "spotify:track:2GzvFiedqW8hgqUpWcASZa" - } - ], - "limit": 20, - "next": "https://api.spotify.com/v1/search?query=nosfell&offset=20&limit=20&type=track", - "offset": 0, - "previous": null, - "total": 107 - } - } - """ - response = mock.Mock(text=json) - results = spotify.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of track') - self.assertEqual(results[0]['url'], 'https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa') - self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') - self.assertIn('1000', results[0]['embedded']) - - json = """ - { - "tracks": { - "href": "https://api.spotify.com/v1/search?query=nosfell&offset=0&limit=20&type=track", - "items": [ - { - "href": "https://api.spotify.com/v1/tracks/2GzvFiedqW8hgqUpWcASZa", - "id": "1000", - "is_playable": true, - "name": "Title of track", - "popularity": 6, - "preview_url": "https://p.scdn.co/mp3-preview/7b8ecda580965a066b768c2647f877e43f7b1a0a", - "track_number": 3, - "type": "album", - "uri": "spotify:track:2GzvFiedqW8hgqUpWcASZa" - } - ], - "limit": 20, - "next": "https://api.spotify.com/v1/search?query=nosfell&offset=20&limit=20&type=track", - "offset": 0, - "previous": null, - "total": 107 - } - } - """ - response = mock.Mock(text=json) - results = spotify.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_stackoverflow.py b/searx/tests/engines/test_stackoverflow.py deleted file mode 100644 index 18a1ff4bd..000000000 --- a/searx/tests/engines/test_stackoverflow.py +++ /dev/null @@ -1,106 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import stackoverflow -from searx.testing import SearxTestCase - - -class TestStackoverflowEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = stackoverflow.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('stackoverflow.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, stackoverflow.response, None) - self.assertRaises(AttributeError, stackoverflow.response, []) - self.assertRaises(AttributeError, stackoverflow.response, '') - self.assertRaises(AttributeError, stackoverflow.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(stackoverflow.response(response), []) - - html = """ -
    -
    -
    -
    -
    -
    - 2583 -
    votes
    -
    -
    -
    -
    -
    - -
    - This is the content -
    -
    -
    -
    - answered nov 23 '09 by - hallski -
    -
    -
    - """ - response = mock.Mock(text=html) - results = stackoverflow.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://stackoverflow.com/questions/this.is.the.url') - self.assertEqual(results[0]['content'], 'This is the content') - - html = """ -
    -
    -
    -
    -
    - 2583 -
    votes
    -
    -
    -
    -
    -
    - -
    - This is the content -
    -
    -
    -
    - answered nov 23 '09 by - hallski -
    -
    - """ - response = mock.Mock(text=html) - results = stackoverflow.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_startpage.py b/searx/tests/engines/test_startpage.py deleted file mode 100644 index 9a1a09bc7..000000000 --- a/searx/tests/engines/test_startpage.py +++ /dev/null @@ -1,140 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import startpage -from searx.testing import SearxTestCase - - -class TestStartpageEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = startpage.request(query, dicto) - self.assertIn('url', params) - self.assertIn('startpage.com', params['url']) - self.assertIn('data', params) - self.assertIn('query', params['data']) - self.assertIn(query, params['data']['query']) - self.assertIn('with_language', params['data']) - self.assertIn('lang_fr', params['data']['with_language']) - - dicto['language'] = 'all' - params = startpage.request(query, dicto) - self.assertNotIn('with_language', params['data']) - - def test_response(self): - self.assertRaises(AttributeError, startpage.response, None) - self.assertRaises(AttributeError, startpage.response, []) - self.assertRaises(AttributeError, startpage.response, '') - self.assertRaises(AttributeError, startpage.response, '[]') - - response = mock.Mock(content='') - self.assertEqual(startpage.response(response), []) - - html = """ -
    -

    - - This should be the title - - -

    -

    - This should be the content. -

    -

    - www.speedtest.net/fr/ - - - - - Navigation avec Ixquick Proxy - - - - - Mis en surbrillance - -

    -
    - """ - response = mock.Mock(content=html) - results = startpage.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') - self.assertEqual(results[0]['content'], 'This should be the content.') - - html = """ -
    -

    - - This should be the title - - -

    -

    - This should be the content. -

    -

    - www.speedtest.net/fr/ - - - - - Navigation avec Ixquick Proxy - - - - - Mis en surbrillance - -

    -
    -
    -

    - -

    -

    - This should be the content. -

    -

    - www.speedtest.net/fr/ - -

    -
    -
    -

    - - This should be the title - - -

    -

    - www.speedtest.net/fr/ - - - - - Navigation avec Ixquick Proxy - - - - - Mis en surbrillance - -

    -
    - """ - response = mock.Mock(content=html) - results = startpage.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['content'], '') diff --git a/searx/tests/engines/test_subtitleseeker.py b/searx/tests/engines/test_subtitleseeker.py deleted file mode 100644 index a641601b2..000000000 --- a/searx/tests/engines/test_subtitleseeker.py +++ /dev/null @@ -1,169 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import subtitleseeker -from searx.testing import SearxTestCase - - -class TestSubtitleseekerEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = subtitleseeker.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('subtitleseeker.com' in params['url']) - - def test_response(self): - dicto = defaultdict(dict) - dicto['language'] = 'fr_FR' - response = mock.Mock(search_params=dicto) - - self.assertRaises(AttributeError, subtitleseeker.response, None) - self.assertRaises(AttributeError, subtitleseeker.response, []) - self.assertRaises(AttributeError, subtitleseeker.response, '') - self.assertRaises(AttributeError, subtitleseeker.response, '[]') - - response = mock.Mock(text='', search_params=dicto) - self.assertEqual(subtitleseeker.response(response), []) - - html = """ -
    -
    - - - This is the Title - -

    - - "Alternative Title" - -
    -
    - 1998 -
    -
    - - 1039 Subs -
    -
    - - 1 hours ago -
    -
    -
    - """ - response = mock.Mock(text=html, search_params=dicto) - results = subtitleseeker.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the Title') - self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/') - self.assertIn('1998', results[0]['content']) - self.assertIn('1039 Subs', results[0]['content']) - self.assertIn('Alternative Title', results[0]['content']) - - html = """ -
    - -
    - 1998 -
    -
    - - 1039 Subs -
    -
    - - 1 hours ago -
    -
    -
    - """ - dicto['language'] = 'all' - response = mock.Mock(text=html, search_params=dicto) - results = subtitleseeker.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the Title') - self.assertEqual(results[0]['url'], 'http://this.is.the.url/') - self.assertIn('1998', results[0]['content']) - self.assertIn('1039 Subs', results[0]['content']) - - html = """ -
    - -
    - 1998 -
    -
    - - 1039 Subs -
    -
    - - 1 hours ago -
    -
    -
    - """ - subtitleseeker.language = 'English' - response = mock.Mock(text=html, search_params=dicto) - results = subtitleseeker.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the Title') - self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/') - self.assertIn('1998', results[0]['content']) - self.assertIn('1039 Subs', results[0]['content']) - - html = """ -
    - - - This is the Title - -
    -
    - 1998 -
    -
    - - 1039 Subs -
    -
    - - 1 hours ago -
    - """ - response = mock.Mock(text=html, search_params=dicto) - results = subtitleseeker.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_swisscows.py b/searx/tests/engines/test_swisscows.py deleted file mode 100644 index 3b4ce7b0f..000000000 --- a/searx/tests/engines/test_swisscows.py +++ /dev/null @@ -1,128 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import swisscows -from searx.testing import SearxTestCase - - -class TestSwisscowsEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'de_DE' - params = swisscows.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('swisscows.ch' in params['url']) - self.assertTrue('uiLanguage=de' in params['url']) - self.assertTrue('region=de-DE' in params['url']) - - dicto['language'] = 'all' - params = swisscows.request(query, dicto) - self.assertTrue('uiLanguage=browser' in params['url']) - self.assertTrue('region=browser' in params['url']) - - dicto['category'] = 'images' - params = swisscows.request(query, dicto) - self.assertIn('image', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, swisscows.response, None) - self.assertRaises(AttributeError, swisscows.response, []) - self.assertRaises(AttributeError, swisscows.response, '') - self.assertRaises(AttributeError, swisscows.response, '[]') - - response = mock.Mock(content='') - self.assertEqual(swisscows.response(response), []) - - response = mock.Mock(content='') - self.assertEqual(swisscows.response(response), []) - - html = u""" - - """ - response = mock.Mock(content=html) - results = swisscows.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 3) - self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') - self.assertEqual(results[0]['content'], 'This should be the content.') - self.assertEqual(results[1]['title'], 'Datei:This should1.svg') - self.assertEqual(results[1]['url'], 'http://de.wikipedia.org/wiki/Datei:This should1.svg') - self.assertEqual(results[1]['img_src'], 'http://ts2.mm.This/should1.png') - self.assertEqual(results[1]['template'], 'images.html') - self.assertEqual(results[2]['title'], 'Datei:This should.svg') - self.assertEqual(results[2]['url'], 'http://de.wikipedia.org/wiki/Datei:This should.svg') - self.assertEqual(results[2]['img_src'], 'http://ts2.mm.This/should.png') - self.assertEqual(results[2]['template'], 'images.html') diff --git a/searx/tests/engines/test_twitter.py b/searx/tests/engines/test_twitter.py deleted file mode 100644 index b444b48ee..000000000 --- a/searx/tests/engines/test_twitter.py +++ /dev/null @@ -1,502 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import twitter -from searx.testing import SearxTestCase - - -class TestTwitterEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['language'] = 'fr_FR' - params = twitter.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('twitter.com', params['url']) - self.assertIn('cookies', params) - self.assertIn('lang', params['cookies']) - self.assertIn('fr', params['cookies']['lang']) - - dicto['language'] = 'all' - params = twitter.request(query, dicto) - self.assertIn('cookies', params) - self.assertIn('lang', params['cookies']) - self.assertIn('en', params['cookies']['lang']) - - def test_response(self): - self.assertRaises(AttributeError, twitter.response, None) - self.assertRaises(AttributeError, twitter.response, []) - self.assertRaises(AttributeError, twitter.response, '') - self.assertRaises(AttributeError, twitter.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(twitter.response(response), []) - - html = """ -
  • -
    -
    -
    -
    - -

    - This is the content étude à€ - - -

    -
    -
    - -
    -
    -
  • - """ - response = mock.Mock(text=html) - results = twitter.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], '@TitleName') - self.assertEqual(results[0]['url'], 'https://twitter.com/this.is.the.url') - self.assertIn(u'This is the content', results[0]['content']) - # self.assertIn(u'This is the content étude à€', results[0]['content']) - - html = """ -
  • -
    -
    -
    -
    - -

    - This is the content étude à€ - - -

    -
    -
    - -
    -
    -
  • - """ - response = mock.Mock(text=html) - results = twitter.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], '@TitleName') - self.assertEqual(results[0]['url'], 'https://twitter.com/this.is.the.url') - self.assertIn(u'This is the content', results[0]['content']) - - html = """ -
  • -
    - -
    - - this.meta.com - - - - -
    -

    - This should be the content.

    -
    -
  • - """ - response = mock.Mock(text=html) - results = twitter.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_vimeo.py b/searx/tests/engines/test_vimeo.py deleted file mode 100644 index 50b1cb563..000000000 --- a/searx/tests/engines/test_vimeo.py +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import vimeo -from searx.testing import SearxTestCase - - -class TestVimeoEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = vimeo.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('vimeo.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, vimeo.response, None) - self.assertRaises(AttributeError, vimeo.response, []) - self.assertRaises(AttributeError, vimeo.response, '') - self.assertRaises(AttributeError, vimeo.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(vimeo.response(response), []) - - html = """ -
    - -
    - """ - response = mock.Mock(text=html) - results = vimeo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://vimeo.com/videoid') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['thumbnail'], 'http://image.url.webp') - self.assertIn('/videoid', results[0]['embedded']) - - html = """ -
      -
    1. - - -
      -

      - This is the title -

      -

      - -

      -
      -
      -
    2. -
    - """ - response = mock.Mock(text=html) - results = vimeo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_www1x.py b/searx/tests/engines/test_www1x.py deleted file mode 100644 index 9df8de6bf..000000000 --- a/searx/tests/engines/test_www1x.py +++ /dev/null @@ -1,57 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import www1x -from searx.testing import SearxTestCase - - -class TestWww1xEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - params = www1x.request(query, defaultdict(dict)) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('1x.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, www1x.response, None) - self.assertRaises(AttributeError, www1x.response, []) - self.assertRaises(AttributeError, www1x.response, '') - self.assertRaises(AttributeError, www1x.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(www1x.response(response), []) - html = """ - - - - - - - ] - > - - -
    Photos
    -
    - - - - - - -
    - - - ]]>
    - """ - response = mock.Mock(text=html) - results = www1x.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['url'], 'https://1x.com/photo/123456') - self.assertEqual(results[0]['thumbnail_src'], 'https://1x.com/images/user/testimage-123456.jpg') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['template'], 'images.html') diff --git a/searx/tests/engines/test_www500px.py b/searx/tests/engines/test_www500px.py deleted file mode 100644 index 8df15b945..000000000 --- a/searx/tests/engines/test_www500px.py +++ /dev/null @@ -1,83 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import www500px -from searx.testing import SearxTestCase - - -class TestWww500pxImagesEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - params = www500px.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertTrue('500px.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, www500px.response, None) - self.assertRaises(AttributeError, www500px.response, []) - self.assertRaises(AttributeError, www500px.response, '') - self.assertRaises(AttributeError, www500px.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(www500px.response(response), []) - - html = """ -
    - - - - -
    - """ - response = mock.Mock(text=html) - results = www500px.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://500px.com/this.should.be.the.url') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertEqual(results[0]['thumbnail_src'], 'https://image.url/3.jpg?v=0') - self.assertEqual(results[0]['img_src'], 'https://image.url/2048.jpg') - - html = """ - - - -
    - -
    - """ - response = mock.Mock(text=html) - results = www500px.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_yacy.py b/searx/tests/engines/test_yacy.py deleted file mode 100644 index f49532cf4..000000000 --- a/searx/tests/engines/test_yacy.py +++ /dev/null @@ -1,96 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import yacy -from searx.testing import SearxTestCase - - -class TestYacyEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = yacy.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('localhost', params['url']) - self.assertIn('fr', params['url']) - - dicto['language'] = 'all' - params = yacy.request(query, dicto) - self.assertIn('url', params) - self.assertNotIn('lr=lang_', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, yacy.response, None) - self.assertRaises(AttributeError, yacy.response, []) - self.assertRaises(AttributeError, yacy.response, '') - self.assertRaises(AttributeError, yacy.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(yacy.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(yacy.response(response), []) - - json = """ - { - "channels": [ - { - "title": "YaCy P2P-Search for test", - "description": "Search for test", - "link": "http://search.yacy.de:7001/yacysearch.html?query=test&resource=global&contentdom=0", - "image": { - "url": "http://search.yacy.de:7001/env/grafics/yacy.png", - "title": "Search for test", - "link": "http://search.yacy.de:7001/yacysearch.html?query=test&resource=global&contentdom=0" - }, - "totalResults": "249", - "startIndex": "0", - "itemsPerPage": "5", - "searchTerms": "test", - "items": [ - { - "title": "This is the title", - "link": "http://this.is.the.url", - "code": "", - "description": "This should be the content", - "pubDate": "Sat, 08 Jun 2013 02:00:00 +0200", - "size": "44213", - "sizename": "43 kbyte", - "guid": "lzh_1T_5FP-A", - "faviconCode": "XTS4uQ_5FP-A", - "host": "www.gamestar.de", - "path": "/spiele/city-of-heroes-freedom/47019.html", - "file": "47019.html", - "urlhash": "lzh_1T_5FP-A", - "ranking": "0.20106804" - }, - { - "title": "This is the title2", - "icon": "/ViewImage.png?maxwidth=96&maxheight=96&code=7EbAbW6BpPOA", - "image": "http://image.url/image.png", - "cache": "/ViewImage.png?quadratic=&url=http://golem.ivwbox.de/cgi-bin/ivw/CP/G_INET?d=14071378", - "url": "http://this.is.the.url", - "urlhash": "7EbAbW6BpPOA", - "host": "www.golem.de", - "width": "-1", - "height": "-1" - } - ] - } - ] - } - """ - response = mock.Mock(text=json) - results = yacy.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 2) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'http://this.is.the.url') - self.assertEqual(results[0]['content'], 'This should be the content') - self.assertEqual(results[1]['img_src'], 'http://image.url/image.png') - self.assertEqual(results[1]['content'], '') - self.assertEqual(results[1]['url'], 'http://this.is.the.url') - self.assertEqual(results[1]['title'], 'This is the title2') diff --git a/searx/tests/engines/test_yahoo.py b/searx/tests/engines/test_yahoo.py deleted file mode 100644 index 11ef9db22..000000000 --- a/searx/tests/engines/test_yahoo.py +++ /dev/null @@ -1,141 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import yahoo -from searx.testing import SearxTestCase - - -class TestYahooEngine(SearxTestCase): - - def test_parse_url(self): - test_url = 'http://r.search.yahoo.com/_ylt=A0LEb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\ - '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=' +\ - 'dtcJsfP4mEeBOjnVfUQ-' - url = yahoo.parse_url(test_url) - self.assertEqual('https://this.is.the.url/', url) - - test_url = 'http://r.search.yahoo.com/_ylt=A0LElb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\ - '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RS=' +\ - 'dtcJsfP4mEeBOjnVfUQ-' - url = yahoo.parse_url(test_url) - self.assertEqual('https://this.is.the.url/', url) - - test_url = 'https://this.is.the.url/' - url = yahoo.parse_url(test_url) - self.assertEqual('https://this.is.the.url/', url) - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = yahoo.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('search.yahoo.com', params['url']) - self.assertIn('fr', params['url']) - self.assertIn('cookies', params) - self.assertIn('sB', params['cookies']) - self.assertIn('fr', params['cookies']['sB']) - - dicto['language'] = 'all' - params = yahoo.request(query, dicto) - self.assertIn('cookies', params) - self.assertIn('sB', params['cookies']) - self.assertIn('en', params['cookies']['sB']) - self.assertIn('en', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, yahoo.response, None) - self.assertRaises(AttributeError, yahoo.response, []) - self.assertRaises(AttributeError, yahoo.response, '') - self.assertRaises(AttributeError, yahoo.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(yahoo.response(response), []) - - html = """ -
      -
    1. -
      - -
      -

      This is the content -

      -
      -
      -
    2. -
    3. -
      -
      -
      -
      -

      This is the second content

      -
      -
      -
    4. -
    -
    -
    -

    Also Try

    - - - - - -
    This is the suggestion -
    -
    - """ - response = mock.Mock(text=html) - results = yahoo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 2) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertEqual(results[1]['suggestion'], 'This is the suggestion') - - html = """ -
      -
    1. -
      - -
      -

      This is the content -

      -
      -
      -
    2. -
    - """ - response = mock.Mock(text=html) - results = yahoo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - - html = """ -
  • -
  • - """ - response = mock.Mock(text=html) - results = yahoo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_yahoo_news.py b/searx/tests/engines/test_yahoo_news.py deleted file mode 100644 index 4d7fc0a10..000000000 --- a/searx/tests/engines/test_yahoo_news.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -from datetime import datetime -import mock -from searx.engines import yahoo_news -from searx.testing import SearxTestCase - - -class TestYahooNewsEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' - params = yahoo_news.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('news.search.yahoo.com', params['url']) - self.assertIn('fr', params['url']) - self.assertIn('cookies', params) - self.assertIn('sB', params['cookies']) - self.assertIn('fr', params['cookies']['sB']) - - dicto['language'] = 'all' - params = yahoo_news.request(query, dicto) - self.assertIn('cookies', params) - self.assertIn('sB', params['cookies']) - self.assertIn('en', params['cookies']['sB']) - self.assertIn('en', params['url']) - - def test_sanitize_url(self): - url = "test.url" - self.assertEqual(url, yahoo_news.sanitize_url(url)) - - url = "www.yahoo.com/;_ylt=test" - self.assertEqual("www.yahoo.com/", yahoo_news.sanitize_url(url)) - - def test_response(self): - self.assertRaises(AttributeError, yahoo_news.response, None) - self.assertRaises(AttributeError, yahoo_news.response, []) - self.assertRaises(AttributeError, yahoo_news.response, '') - self.assertRaises(AttributeError, yahoo_news.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(yahoo_news.response(response), []) - - html = """ -
      -
    1. - -
      - Business via Yahoo! - May 01 10:00 AM -
      -
      - This is the content -
      -
    2. -
    3. -
      -

      - - -

      -
      -
      -
      -
    4. -
    - """ - response = mock.Mock(text=html) - results = yahoo_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'This is the title...') - self.assertEqual(results[0]['url'], 'http://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - - html = """ -
      -
    1. - -
      - Business via Yahoo! - 2 hours, 22 minutes ago -
      -
      - This is the content -
      -
    2. -
    3. - -
      - Business via Yahoo! - 22 minutes ago -
      -
      - This is the content -
      -
    4. -
    5. - -
      - Business via Yahoo! - Feb 03 09:45AM 1900 -
      -
      - This is the content -
      -
    6. -
    - """ - response = mock.Mock(text=html) - results = yahoo_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 3) - self.assertEqual(results[0]['title'], 'This is the title...') - self.assertEqual(results[0]['url'], 'http://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertEqual(results[2]['publishedDate'].year, datetime.now().year) diff --git a/searx/tests/engines/test_youtube_api.py b/searx/tests/engines/test_youtube_api.py deleted file mode 100644 index 0d4d478c3..000000000 --- a/searx/tests/engines/test_youtube_api.py +++ /dev/null @@ -1,111 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import youtube_api -from searx.testing import SearxTestCase - - -class TestYoutubeAPIEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['language'] = 'fr_FR' - params = youtube_api.request(query, dicto) - self.assertTrue('url' in params) - self.assertTrue(query in params['url']) - self.assertIn('googleapis.com', params['url']) - self.assertIn('youtube', params['url']) - self.assertIn('fr', params['url']) - - dicto['language'] = 'all' - params = youtube_api.request(query, dicto) - self.assertFalse('fr' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, youtube_api.response, None) - self.assertRaises(AttributeError, youtube_api.response, []) - self.assertRaises(AttributeError, youtube_api.response, '') - self.assertRaises(AttributeError, youtube_api.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(youtube_api.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(youtube_api.response(response), []) - - json = """ - { - "kind": "youtube#searchListResponse", - "etag": "xmg9xJZuZD438sF4hb-VcBBREXc/YJQDcTBCDcaBvl-sRZJoXdvy1ME", - "nextPageToken": "CAUQAA", - "pageInfo": { - "totalResults": 1000000, - "resultsPerPage": 20 - }, - "items": [ - { - "kind": "youtube#searchResult", - "etag": "xmg9xJZuZD438sF4hb-VcBBREXc/IbLO64BMhbHIgWLwLw7MDYe7Hs4", - "id": { - "kind": "youtube#video", - "videoId": "DIVZCPfAOeM" - }, - "snippet": { - "publishedAt": "2015-05-29T22:41:04.000Z", - "channelId": "UCNodmx1ERIjKqvcJLtdzH5Q", - "title": "Title", - "description": "Description", - "thumbnails": { - "default": { - "url": "https://i.ytimg.com/vi/DIVZCPfAOeM/default.jpg" - }, - "medium": { - "url": "https://i.ytimg.com/vi/DIVZCPfAOeM/mqdefault.jpg" - }, - "high": { - "url": "https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg" - } - }, - "channelTitle": "MinecraftUniverse", - "liveBroadcastContent": "none" - } - } - ] - } - """ - response = mock.Mock(text=json) - results = youtube_api.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM') - self.assertEqual(results[0]['content'], 'Description') - self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg') - self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) - - json = """ - { - "kind": "youtube#searchListResponse", - "etag": "xmg9xJZuZD438sF4hb-VcBBREXc/YJQDcTBCDcaBvl-sRZJoXdvy1ME", - "nextPageToken": "CAUQAA", - "pageInfo": { - "totalResults": 1000000, - "resultsPerPage": 20 - } - } - """ - response = mock.Mock(text=json) - results = youtube_api.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - {"toto":{"entry":[] - } - } - """ - response = mock.Mock(text=json) - results = youtube_api.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_youtube_noapi.py b/searx/tests/engines/test_youtube_noapi.py deleted file mode 100644 index 9fa8fd20e..000000000 --- a/searx/tests/engines/test_youtube_noapi.py +++ /dev/null @@ -1,154 +0,0 @@ -# -*- coding: utf-8 -*- -from collections import defaultdict -import mock -from searx.engines import youtube_noapi -from searx.testing import SearxTestCase - - -class TestYoutubeNoAPIEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - params = youtube_noapi.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('youtube.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, youtube_noapi.response, None) - self.assertRaises(AttributeError, youtube_noapi.response, []) - self.assertRaises(AttributeError, youtube_noapi.response, '') - self.assertRaises(AttributeError, youtube_noapi.response, '[]') - - response = mock.Mock(text='') - self.assertEqual(youtube_noapi.response(response), []) - - html = """ -
      -
    1. -
      -
      - - - -
      -
      -

      - - Title - - - Durée : 11:35. -

      -
      -
        -
      • il y a 20 heures
      • -
      • 8 424 vues
      • -
      -
      -
      - Description -
      -
      -
        -
      • - Nouveauté -
      • -
      • HD
      • -
      -
      -
      -
      -
      -
      -
      -
      -
      -
    2. -
    - """ - response = mock.Mock(text=html) - results = youtube_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title') - self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM') - self.assertEqual(results[0]['content'], 'Description') - self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg') - self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) - - html = """ -
      -
    1. -
      -
      - - - -
      -
      -

      - - Durée : 11:35. -

      -
      -
        -
      • il y a 20 heures
      • -
      • 8 424 vues
      • -
      -
      -
      -
        -
      • - Nouveauté -
      • -
      • HD
      • -
      -
      -
      -
      -
      -
      -
      -
      -
      -
    2. -
    - """ - response = mock.Mock(text=html) - results = youtube_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - - html = """ -
      -
    1. -
    2. -
    - """ - response = mock.Mock(text=html) - results = youtube_noapi.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/searx/tests/robot/__init__.py b/searx/tests/robot/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/searx/tests/robot/test_basic.robot b/searx/tests/robot/test_basic.robot deleted file mode 100644 index 1b8e78fff..000000000 --- a/searx/tests/robot/test_basic.robot +++ /dev/null @@ -1,44 +0,0 @@ -*** 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 - -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 Form id=search_form - Location Should Be http://localhost:11111/ - 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 Form id=search_form - Location Should Be http://localhost:11111/ - Page Should Contain rólunk - Page Should Contain beállítások diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py deleted file mode 100644 index 793b77460..000000000 --- a/searx/tests/test_engines.py +++ /dev/null @@ -1,45 +0,0 @@ -from searx.tests.engines.test_bing import * # noqa -from searx.tests.engines.test_bing_images import * # noqa -from searx.tests.engines.test_bing_news import * # noqa -from searx.tests.engines.test_blekko_images import * # noqa -from searx.tests.engines.test_btdigg import * # noqa -from searx.tests.engines.test_currency_convert import * # noqa -from searx.tests.engines.test_dailymotion import * # noqa -from searx.tests.engines.test_deezer import * # noqa -from searx.tests.engines.test_deviantart import * # noqa -from searx.tests.engines.test_digg import * # noqa -from searx.tests.engines.test_duckduckgo import * # noqa -from searx.tests.engines.test_duckduckgo_definitions import * # noqa -from searx.tests.engines.test_dummy import * # noqa -from searx.tests.engines.test_faroo import * # noqa -from searx.tests.engines.test_flickr import * # noqa -from searx.tests.engines.test_flickr_noapi import * # noqa -from searx.tests.engines.test_gigablast import * # noqa -from searx.tests.engines.test_github import * # noqa -from searx.tests.engines.test_google import * # noqa -from searx.tests.engines.test_google_images import * # noqa -from searx.tests.engines.test_google_news import * # noqa -from searx.tests.engines.test_kickass import * # noqa -from searx.tests.engines.test_mediawiki import * # noqa -from searx.tests.engines.test_mixcloud import * # noqa -from searx.tests.engines.test_openstreetmap import * # noqa -from searx.tests.engines.test_photon import * # noqa -from searx.tests.engines.test_piratebay import * # noqa -from searx.tests.engines.test_qwant import * # noqa -from searx.tests.engines.test_searchcode_code import * # noqa -from searx.tests.engines.test_searchcode_doc import * # noqa -from searx.tests.engines.test_soundcloud import * # noqa -from searx.tests.engines.test_spotify import * # noqa -from searx.tests.engines.test_stackoverflow import * # noqa -from searx.tests.engines.test_startpage import * # noqa -from searx.tests.engines.test_subtitleseeker import * # noqa -from searx.tests.engines.test_swisscows import * # noqa -from searx.tests.engines.test_twitter import * # noqa -from searx.tests.engines.test_vimeo import * # noqa -from searx.tests.engines.test_www1x import * # noqa -from searx.tests.engines.test_www500px import * # noqa -from searx.tests.engines.test_yacy import * # noqa -from searx.tests.engines.test_yahoo import * # noqa -from searx.tests.engines.test_youtube_api import * # noqa -from searx.tests.engines.test_youtube_noapi import * # noqa -from searx.tests.engines.test_yahoo_news import * # noqa diff --git a/searx/tests/test_plugins.py b/searx/tests/test_plugins.py deleted file mode 100644 index 98d39ec14..000000000 --- a/searx/tests/test_plugins.py +++ /dev/null @@ -1,74 +0,0 @@ -# -*- coding: utf-8 -*- - -from searx.testing import SearxTestCase -from searx import plugins -from mock import Mock - - -def get_search_mock(query, **kwargs): - return {'search': Mock(query=query, - result_container=Mock(answers=set()), - **kwargs)} - - -class PluginStoreTest(SearxTestCase): - - def test_PluginStore_init(self): - store = plugins.PluginStore() - self.assertTrue(isinstance(store.plugins, list) and len(store.plugins) == 0) - - def test_PluginStore_register(self): - store = plugins.PluginStore() - testplugin = plugins.Plugin() - store.register(testplugin) - - self.assertTrue(len(store.plugins) == 1) - - def test_PluginStore_call(self): - store = plugins.PluginStore() - testplugin = plugins.Plugin() - store.register(testplugin) - setattr(testplugin, 'asdf', Mock()) - request = Mock(user_plugins=[]) - store.call('asdf', request, Mock()) - - self.assertFalse(testplugin.asdf.called) - - request.user_plugins.append(testplugin) - store.call('asdf', request, Mock()) - - self.assertTrue(testplugin.asdf.called) - - -class SelfIPTest(SearxTestCase): - - def test_PluginStore_init(self): - store = plugins.PluginStore() - store.register(plugins.self_info) - - self.assertTrue(len(store.plugins) == 1) - - # IP test - request = Mock(user_plugins=store.plugins, - remote_addr='127.0.0.1') - request.headers.getlist.return_value = [] - ctx = get_search_mock(query='ip') - store.call('post_search', request, ctx) - self.assertTrue('127.0.0.1' in ctx['search'].result_container.answers) - - # User agent test - request = Mock(user_plugins=store.plugins, - user_agent='Mock') - request.headers.getlist.return_value = [] - - ctx = get_search_mock(query='user-agent') - store.call('post_search', request, ctx) - self.assertTrue('Mock' in ctx['search'].result_container.answers) - - ctx = get_search_mock(query='user-agent') - store.call('post_search', request, ctx) - self.assertTrue('Mock' in ctx['search'].result_container.answers) - - ctx = get_search_mock(query='What is my User-Agent?') - store.call('post_search', request, ctx) - self.assertTrue('Mock' in ctx['search'].result_container.answers) diff --git a/searx/tests/test_results.py b/searx/tests/test_results.py deleted file mode 100644 index 274b5b37a..000000000 --- a/searx/tests/test_results.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- - -from searx.results import ResultContainer -from searx.testing import SearxTestCase - - -def fake_result(url='https://aa.bb/cc?dd=ee#ff', - title='aaa', - content='bbb', - engine='wikipedia', **kwargs): - result = {'url': url, - 'title': title, - 'content': content, - 'engine': engine} - result.update(kwargs) - return result - - -# TODO -class ResultContainerTestCase(SearxTestCase): - - def test_empty(self): - c = ResultContainer() - self.assertEqual(c.get_ordered_results(), []) - - def test_one_result(self): - c = ResultContainer() - c.extend('wikipedia', [fake_result()]) - self.assertEqual(c.results_length(), 1) - - def test_one_suggestion(self): - c = ResultContainer() - c.extend('wikipedia', [fake_result(suggestion=True)]) - self.assertEqual(len(c.suggestions), 1) - self.assertEqual(c.results_length(), 0) - - def test_result_merge(self): - c = ResultContainer() - c.extend('wikipedia', [fake_result()]) - c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')]) - self.assertEqual(c.results_length(), 2) diff --git a/searx/tests/test_robot.py b/searx/tests/test_robot.py deleted file mode 100644 index b48153fe4..000000000 --- a/searx/tests/test_robot.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import unittest2 as unittest -from plone.testing import layered -from robotsuite import RobotTestSuite -from searx.testing import SEARXROBOTLAYER - - -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_search.py b/searx/tests/test_search.py deleted file mode 100644 index af5fffd8b..000000000 --- a/searx/tests/test_search.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- - -from searx.testing import SearxTestCase - - -# TODO -class SearchTestCase(SearxTestCase): - - def test_(self): - pass diff --git a/searx/tests/test_utils.py b/searx/tests/test_utils.py deleted file mode 100644 index 04480791d..000000000 --- a/searx/tests/test_utils.py +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- -import mock -from searx.testing import SearxTestCase -from searx import utils - - -class TestUtils(SearxTestCase): - - def test_gen_useragent(self): - self.assertIsInstance(utils.gen_useragent(), str) - self.assertIsNotNone(utils.gen_useragent()) - self.assertTrue(utils.gen_useragent().startswith('Mozilla')) - - def test_searx_useragent(self): - self.assertIsInstance(utils.searx_useragent(), str) - self.assertIsNotNone(utils.searx_useragent()) - self.assertTrue(utils.searx_useragent().startswith('searx')) - - def test_highlight_content(self): - self.assertEqual(utils.highlight_content(0, None), None) - self.assertEqual(utils.highlight_content(None, None), None) - self.assertEqual(utils.highlight_content('', None), None) - self.assertEqual(utils.highlight_content(False, None), None) - - contents = [ - '' - 'not<' - ] - for content in contents: - self.assertEqual(utils.highlight_content(content, None), content) - - content = 'a' - query = 'test' - self.assertEqual(utils.highlight_content(content, query), content) - query = 'a test' - self.assertEqual(utils.highlight_content(content, query), content) - - def test_html_to_text(self): - html = """ - - - - - - - - Test text - - - """ - self.assertIsInstance(utils.html_to_text(html), unicode) - self.assertIsNotNone(utils.html_to_text(html)) - self.assertEqual(utils.html_to_text(html), "Test text") - - def test_prettify_url(self): - data = (('https://searx.me/', 'https://searx.me/'), - (u'https://searx.me/ű', u'https://searx.me/ű'), - ('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'), - (u'https://searx.me/' + (100 * u'ű'), u'https://searx.me/[...]űűűűűűűűűűűűűűűűű')) - - for test_url, expected in data: - self.assertEqual(utils.prettify_url(test_url, max_length=32), expected) - - -class TestHTMLTextExtractor(SearxTestCase): - - def setUp(self): - self.html_text_extractor = utils.HTMLTextExtractor() - - def test__init__(self): - self.assertEqual(self.html_text_extractor.result, []) - - def test_handle_charref(self): - self.html_text_extractor.handle_charref('xF') - self.assertIn(u'\x0f', self.html_text_extractor.result) - self.html_text_extractor.handle_charref('XF') - self.assertIn(u'\x0f', self.html_text_extractor.result) - - self.html_text_extractor.handle_charref('97') - self.assertIn(u'a', self.html_text_extractor.result) - - def test_handle_entityref(self): - entity = 'test' - self.html_text_extractor.handle_entityref(entity) - self.assertIn(entity, self.html_text_extractor.result) - - -class TestUnicodeWriter(SearxTestCase): - - def setUp(self): - self.unicode_writer = utils.UnicodeWriter(mock.MagicMock()) - - def test_write_row(self): - row = [1, 2, 3] - self.assertEqual(self.unicode_writer.writerow(row), None) - - def test_write_rows(self): - self.unicode_writer.writerow = mock.MagicMock() - rows = [1, 2, 3] - self.unicode_writer.writerows(rows) - self.assertEqual(self.unicode_writer.writerow.call_count, len(rows)) diff --git a/searx/tests/test_webapp.py b/searx/tests/test_webapp.py deleted file mode 100644 index 071c01df3..000000000 --- a/searx/tests/test_webapp.py +++ /dev/null @@ -1,151 +0,0 @@ -# -*- coding: utf-8 -*- - -import json -from mock import Mock -from urlparse import ParseResult -from searx import webapp -from searx.testing import SearxTestCase - - -class ViewsTestCase(SearxTestCase): - - def setUp(self): - webapp.app.config['TESTING'] = True # to get better error messages - self.app = webapp.app.test_client() - webapp.default_theme = 'default' - - # set some defaults - self.test_results = [ - { - 'content': 'first test content', - 'title': 'First Test', - 'url': 'http://first.test.xyz', - 'engines': ['youtube', 'startpage'], - 'engine': 'startpage', - 'parsed_url': ParseResult(scheme='http', netloc='first.test.xyz', path='/', params='', query='', fragment=''), # noqa - }, { - 'content': 'second test content', - 'title': 'Second Test', - 'url': 'http://second.test.xyz', - 'engines': ['youtube', 'startpage'], - 'engine': 'youtube', - 'parsed_url': ParseResult(scheme='http', netloc='second.test.xyz', path='/', params='', query='', fragment=''), # noqa - }, - ] - - def search_mock(search_self, *args): - search_self.result_container = Mock(get_ordered_results=lambda: self.test_results, - answers=set(), - suggestions=set(), - infoboxes=[], - results=self.test_results, - results_length=lambda: len(self.test_results)) - - webapp.Search.search = search_mock - - self.maxDiff = None # to see full diffs - - def test_index_empty(self): - result = self.app.post('/') - self.assertEqual(result.status_code, 200) - self.assertIn('

    searx

    ', result.data) - - def test_index_html(self): - result = self.app.post('/', data={'q': 'test'}) - self.assertIn( - '

    youtubeSecond Test

    ', # noqa - result.data - ) - self.assertIn( - '

    first test content

    ', # noqa - result.data - ) - - def test_index_json(self): - result = self.app.post('/', data={'q': 'test', 'format': 'json'}) - - result_dict = json.loads(result.data) - - self.assertEqual('test', result_dict['query']) - self.assertEqual( - result_dict['results'][0]['content'], 'first test content') - self.assertEqual( - result_dict['results'][0]['url'], 'http://first.test.xyz') - - def test_index_csv(self): - result = self.app.post('/', data={'q': 'test', 'format': 'csv'}) - - self.assertEqual( - 'title,url,content,host,engine,score\r\n' - 'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa - 'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa - result.data - ) - - def test_index_rss(self): - result = self.app.post('/', data={'q': 'test', 'format': 'rss'}) - - self.assertIn( - 'Search results for "test" - searx', - result.data - ) - - self.assertIn( - '2', - result.data - ) - - self.assertIn( - 'First Test', - result.data - ) - - self.assertIn( - 'http://first.test.xyz', - result.data - ) - - self.assertIn( - 'first test content', - result.data - ) - - def test_about(self): - result = self.app.get('/about') - self.assertEqual(result.status_code, 200) - self.assertIn('

    About searx

    ', result.data) - - def test_preferences(self): - result = self.app.get('/preferences') - self.assertEqual(result.status_code, 200) - self.assertIn( - '
    ', - result.data - ) - self.assertIn( - 'Default categories', - result.data - ) - self.assertIn( - 'Interface language', - result.data - ) - - def test_stats(self): - result = self.app.get('/stats') - self.assertEqual(result.status_code, 200) - self.assertIn('

    Engine stats

    ', result.data) - - def test_robots_txt(self): - result = self.app.get('/robots.txt') - self.assertEqual(result.status_code, 200) - self.assertIn('Allow: /', result.data) - - def test_opensearch_xml(self): - result = self.app.get('/opensearch.xml') - self.assertEqual(result.status_code, 200) - self.assertIn('a privacy-respecting, hackable metasearch engine', result.data) - - def test_favicon(self): - result = self.app.get('/favicon.ico') - self.assertEqual(result.status_code, 200) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/robot/__init__.py b/tests/robot/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/robot/test_basic.robot b/tests/robot/test_basic.robot new file mode 100644 index 000000000..1b8e78fff --- /dev/null +++ b/tests/robot/test_basic.robot @@ -0,0 +1,44 @@ +*** 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 + +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 Form id=search_form + Location Should Be http://localhost:11111/ + 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 Form id=search_form + Location Should Be http://localhost:11111/ + Page Should Contain rólunk + Page Should Contain beállítások diff --git a/tests/test_robot.py b/tests/test_robot.py new file mode 100644 index 000000000..b48153fe4 --- /dev/null +++ b/tests/test_robot.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +import os +import unittest2 as unittest +from plone.testing import layered +from robotsuite import RobotTestSuite +from searx.testing import SEARXROBOTLAYER + + +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/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/engines/__init__.py b/tests/unit/engines/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py new file mode 100644 index 000000000..bce221440 --- /dev/null +++ b/tests/unit/engines/test_bing.py @@ -0,0 +1,90 @@ +from collections import defaultdict +import mock +from searx.engines import bing +from searx.testing import SearxTestCase + + +class TestBingEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = bing.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('bing.com' in params['url']) + self.assertTrue('SRCHHPGUSR' in params['cookies']) + self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) + + dicto['language'] = 'all' + params = bing.request(query, dicto) + self.assertTrue('SRCHHPGUSR' in params['cookies']) + self.assertTrue('en' in params['cookies']['SRCHHPGUSR']) + + def test_response(self): + self.assertRaises(AttributeError, bing.response, None) + self.assertRaises(AttributeError, bing.response, []) + self.assertRaises(AttributeError, bing.response, '') + self.assertRaises(AttributeError, bing.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(bing.response(response), []) + + response = mock.Mock(text='') + self.assertEqual(bing.response(response), []) + + html = """ +
    +
    + +
    this.meta.com + + + + +
    +

    This should be the content.

    +
    +
    + """ + response = mock.Mock(text=html) + results = bing.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') + + html = """ +
  • +
    + +
    this.meta.com + + + + +
    +

    This should be the content.

    +
    +
  • + """ + response = mock.Mock(text=html) + results = bing.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py new file mode 100644 index 000000000..f42dff7e8 --- /dev/null +++ b/tests/unit/engines/test_bing_images.py @@ -0,0 +1,269 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import bing_images +from searx.testing import SearxTestCase + + +class TestBingImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + dicto['safesearch'] = 1 + params = bing_images.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('bing.com' in params['url']) + self.assertTrue('SRCHHPGUSR' in params['cookies']) + self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) + + dicto['language'] = 'all' + params = bing_images.request(query, dicto) + self.assertIn('SRCHHPGUSR', params['cookies']) + self.assertIn('en', params['cookies']['SRCHHPGUSR']) + + def test_response(self): + self.assertRaises(AttributeError, bing_images.response, None) + self.assertRaises(AttributeError, bing_images.response, []) + self.assertRaises(AttributeError, bing_images.response, '') + self.assertRaises(AttributeError, bing_images.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(bing_images.response(response), []) + + response = mock.Mock(text='') + self.assertEqual(bing_images.response(response), []) + + html = """ +
    + + + +
    + """ + html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(text=html) + results = bing_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Test Query') + self.assertEqual(results[0]['url'], 'http://www.page.url/') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['thumbnail_src'], 'https://www.bing.com/th?id=HN.608003696942779811') + self.assertEqual(results[0]['img_src'], 'http://test.url/Test%20Query.jpg') + + html = """ + + + + """ + response = mock.Mock(text=html) + results = bing_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    + """ + html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(text=html) + results = bing_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 10) diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py new file mode 100644 index 000000000..a64d59b7b --- /dev/null +++ b/tests/unit/engines/test_bing_news.py @@ -0,0 +1,138 @@ +from collections import defaultdict +import mock +from searx.engines import bing_news +from searx.testing import SearxTestCase +import lxml + + +class TestBingNewsEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = bing_news.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('bing.com', params['url']) + self.assertIn('fr', params['url']) + + dicto['language'] = 'all' + params = bing_news.request(query, dicto) + self.assertIn('en', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, bing_news.response, None) + self.assertRaises(AttributeError, bing_news.response, []) + self.assertRaises(AttributeError, bing_news.response, '') + self.assertRaises(AttributeError, bing_news.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(bing_news.response(response), []) + + response = mock.Mock(content='') + self.assertEqual(bing_news.response(response), []) + + html = """ + + + python - Bing News + https://www.bing.com:443/news/search?q=python&setmkt=en-US&first=1&format=RSS + Search results + + http://10.53.64.9/rsslogo.gif + test + https://www.bing.com:443/news/search?q=test&setmkt=en-US&first=1&format=RSS + + Copyright + + Title + https://www.bing.com/news/apiclick.aspx?ref=FexRss&aid=&tid=c237eccc50bd4758b106a5e3c94fce09&url=http%3a%2f%2furl.of.article%2f&c=xxxxxxxxx&mkt=en-us + Article Content + Tue, 02 Jun 2015 13:37:00 GMT + Infoworld + http://a1.bing4.com/th?id=ON.13371337133713371337133713371337&pid=News + w={0}&h={1}&c=7 + + 620 + 413 + + + Another Title + https://www.bing.com/news/apiclick.aspx?ref=FexRss&aid=&tid=c237eccc50bd4758b106a5e3c94fce09&url=http%3a%2f%2fanother.url.of.article%2f&c=xxxxxxxxx&mkt=en-us + Another Article Content + Tue, 02 Jun 2015 13:37:00 GMT + + +""" # noqa + response = mock.Mock(content=html) + results = bing_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://url.of.article/') + self.assertEqual(results[0]['content'], 'Article Content') + self.assertEqual(results[0]['thumbnail'], 'https://www.bing.com/th?id=ON.13371337133713371337133713371337') + self.assertEqual(results[1]['title'], 'Another Title') + self.assertEqual(results[1]['url'], 'http://another.url.of.article/') + self.assertEqual(results[1]['content'], 'Another Article Content') + self.assertNotIn('thumbnail', results[1]) + + html = """ + + + python - Bing News + https://www.bing.com:443/news/search?q=python&setmkt=en-US&first=1&format=RSS + Search results + + http://10.53.64.9/rsslogo.gif + test + https://www.bing.com:443/news/search?q=test&setmkt=en-US&first=1&format=RSS + + Copyright + + Title + http://another.url.of.article/ + Article Content + garbage + Infoworld + http://another.bing.com/image + w={0}&h={1}&c=7 + + 620 + 413 + + +""" # noqa + response = mock.Mock(content=html) + results = bing_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://another.url.of.article/') + self.assertEqual(results[0]['content'], 'Article Content') + self.assertEqual(results[0]['thumbnail'], 'http://another.bing.com/image') + + html = """ + + + python - Bing News + https://www.bing.com:443/news/search?q=python&setmkt=en-US&first=1&format=RSS + Search results + + http://10.53.64.9/rsslogo.gif + test + https://www.bing.com:443/news/search?q=test&setmkt=en-US&first=1&format=RSS + + +""" # noqa + + response = mock.Mock(content=html) + results = bing_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """gabarge""" + response = mock.Mock(content=html) + self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response) diff --git a/tests/unit/engines/test_blekko_images.py b/tests/unit/engines/test_blekko_images.py new file mode 100644 index 000000000..beb0853e3 --- /dev/null +++ b/tests/unit/engines/test_blekko_images.py @@ -0,0 +1,71 @@ +from collections import defaultdict +import mock +from searx.engines import blekko_images +from searx.testing import SearxTestCase + + +class TestBlekkoImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['safesearch'] = 1 + params = blekko_images.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('blekko.com', params['url']) + self.assertIn('page', params['url']) + + dicto['pageno'] = 1 + params = blekko_images.request(query, dicto) + self.assertNotIn('page', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, blekko_images.response, None) + self.assertRaises(AttributeError, blekko_images.response, []) + self.assertRaises(AttributeError, blekko_images.response, '') + self.assertRaises(AttributeError, blekko_images.response, '[]') + + response = mock.Mock(text='[]') + self.assertEqual(blekko_images.response(response), []) + + json = """ + [ + { + "c": 1, + "page_url": "http://result_url.html", + "title": "Photo title", + "tn_url": "http://ts1.mm.bing.net/th?id=HN.608050619474382748&pid=15.1", + "url": "http://result_image.jpg" + }, + { + "c": 2, + "page_url": "http://companyorange.simpsite.nl/OSM", + "title": "OSM", + "tn_url": "http://ts2.mm.bing.net/th?id=HN.608048068264919461&pid=15.1", + "url": "http://simpsite.nl/userdata2/58985/Home/OSM.bmp" + }, + { + "c": 3, + "page_url": "http://invincible.webklik.nl/page/osm", + "title": "OSM", + "tn_url": "http://ts1.mm.bing.net/th?id=HN.608024514657649476&pid=15.1", + "url": "http://www.webklik.nl/user_files/2009_09/65324/osm.gif" + }, + { + "c": 4, + "page_url": "http://www.offshorenorway.no/event/companyDetail/id/12492", + "title": "Go to OSM Offshore AS homepage", + "tn_url": "http://ts2.mm.bing.net/th?id=HN.608054265899847285&pid=15.1", + "url": "http://www.offshorenorway.no/firmalogo/OSM-logo.png" + } + ] + """ + response = mock.Mock(text=json) + results = blekko_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 4) + self.assertEqual(results[0]['title'], 'Photo title') + self.assertEqual(results[0]['url'], 'http://result_url.html') + self.assertEqual(results[0]['img_src'], 'http://result_image.jpg') diff --git a/tests/unit/engines/test_btdigg.py b/tests/unit/engines/test_btdigg.py new file mode 100644 index 000000000..2721f4e7c --- /dev/null +++ b/tests/unit/engines/test_btdigg.py @@ -0,0 +1,384 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import btdigg +from searx.testing import SearxTestCase + + +class TestBtdiggEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = btdigg.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('btdigg.org', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, btdigg.response, None) + self.assertRaises(AttributeError, btdigg.response, []) + self.assertRaises(AttributeError, btdigg.response, '') + self.assertRaises(AttributeError, btdigg.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(btdigg.response(response), []) + + html = """ +
    + + + + + +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 8 B + + Fichiers: + 710 + + Téléchargements: + 5 + + Temps: + 417.8 jours + + Dernière mise à jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    +
    + """ + response = mock.Mock(content=html) + results = btdigg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Should be the title') + self.assertEqual(results[0]['url'], 'https://btdigg.org/url') + self.assertEqual(results[0]['content'], 'Content') + self.assertEqual(results[0]['seed'], 5) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['filesize'], 8) + self.assertEqual(results[0]['files'], 710) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:magnet&dn=Test') + + html = """ +
    + +
    +
    + """ + response = mock.Mock(content=html) + results = btdigg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ +
    + + + + + + + + + + + + + + + + + + + + + +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 KB + + Fichiers: + 710 + + Téléchargements: + 5 + + Temps: + 417.8 jours + + Dernière mise à jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 MB + + Fichiers: + a + + Téléchargements: + 4 + + Temps: + 417.8 jours + + Dernière mise à jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 GB + + Fichiers: + 710 + + Téléchargements: + 3 + + Temps: + 417.8 jours + + Dernière mise à jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 TB + + Fichiers: + 710 + + Téléchargements: + 2 + + Temps: + 417.8 jours + + Dernière mise à jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + a TB + + Fichiers: + 710 + + Téléchargements: + z + + Temps: + 417.8 jours + + Dernière mise à jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    +
    + """ + response = mock.Mock(content=html) + results = btdigg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 5) + self.assertEqual(results[0]['title'], 'Should be the title') + self.assertEqual(results[0]['url'], 'https://btdigg.org/url') + self.assertEqual(results[0]['content'], 'Content') + self.assertEqual(results[0]['seed'], 5) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['files'], 710) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:magnet&dn=Test') + self.assertEqual(results[0]['filesize'], 1024) + self.assertEqual(results[1]['filesize'], 1048576) + self.assertEqual(results[2]['filesize'], 1073741824) + self.assertEqual(results[3]['filesize'], 1099511627776) diff --git a/tests/unit/engines/test_currency_convert.py b/tests/unit/engines/test_currency_convert.py new file mode 100644 index 000000000..84ec3b742 --- /dev/null +++ b/tests/unit/engines/test_currency_convert.py @@ -0,0 +1,46 @@ +from collections import defaultdict +from datetime import datetime +import mock +from searx.engines import currency_convert +from searx.testing import SearxTestCase + + +class TestCurrencyConvertEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = currency_convert.request(query, dicto) + self.assertNotIn('url', params) + + query = '1.1.1 EUR in USD' + params = currency_convert.request(query, dicto) + self.assertNotIn('url', params) + + query = '10 eur in usd' + params = currency_convert.request(query, dicto) + self.assertIn('url', params) + self.assertIn('finance.yahoo.com', params['url']) + self.assertIn('EUR', params['url']) + self.assertIn('USD', params['url']) + + def test_response(self): + dicto = defaultdict(dict) + dicto['ammount'] = float(10) + dicto['from'] = "EUR" + dicto['to'] = "USD" + dicto['from_name'] = "euro" + dicto['to_name'] = "United States dollar" + response = mock.Mock(text='a,b,c,d', search_params=dicto) + self.assertEqual(currency_convert.response(response), []) + + csv = "2,0.5,1" + response = mock.Mock(text=csv, search_params=dicto) + results = currency_convert.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['answer'], '10.0 EUR = 5.0 USD, 1 EUR (euro) = 0.5 USD (United States dollar)') + now_date = datetime.now().strftime('%Y%m%d') + self.assertEqual(results[0]['url'], 'https://finance.yahoo.com/currency/converter-results/' + + now_date + '/10.0-eur-to-usd.html') diff --git a/tests/unit/engines/test_dailymotion.py b/tests/unit/engines/test_dailymotion.py new file mode 100644 index 000000000..4c31ff5d5 --- /dev/null +++ b/tests/unit/engines/test_dailymotion.py @@ -0,0 +1,74 @@ +from collections import defaultdict +import mock +from searx.engines import dailymotion +from searx.testing import SearxTestCase + + +class TestDailymotionEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = dailymotion.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('dailymotion.com' in params['url']) + self.assertTrue('fr' in params['url']) + + dicto['language'] = 'all' + params = dailymotion.request(query, dicto) + self.assertTrue('en' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, dailymotion.response, None) + self.assertRaises(AttributeError, dailymotion.response, []) + self.assertRaises(AttributeError, dailymotion.response, '') + self.assertRaises(AttributeError, dailymotion.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(dailymotion.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(dailymotion.response(response), []) + + json = """ + { + "page": 1, + "limit": 5, + "explicit": false, + "total": 289487, + "has_more": true, + "list": [ + { + "created_time": 1422173451, + "title": "Title", + "description": "Description", + "duration": 81, + "url": "http://www.url", + "thumbnail_360_url": "http://thumbnail", + "id": "x2fit7q" + } + ] + } + """ + response = mock.Mock(text=json) + results = dailymotion.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://www.url') + self.assertEqual(results[0]['content'], 'Description') + self.assertIn('x2fit7q', results[0]['embedded']) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.dailymotion.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = dailymotion.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_deezer.py b/tests/unit/engines/test_deezer.py new file mode 100644 index 000000000..ad09d2a2c --- /dev/null +++ b/tests/unit/engines/test_deezer.py @@ -0,0 +1,57 @@ +from collections import defaultdict +import mock +from searx.engines import deezer +from searx.testing import SearxTestCase + + +class TestDeezerEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = deezer.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('deezer.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, deezer.response, None) + self.assertRaises(AttributeError, deezer.response, []) + self.assertRaises(AttributeError, deezer.response, '') + self.assertRaises(AttributeError, deezer.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(deezer.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(deezer.response(response), []) + + json = """ + {"data":[ + {"id":100, "title":"Title of track", + "link":"https:\/\/www.deezer.com\/track\/1094042","duration":232, + "artist":{"id":200,"name":"Artist Name", + "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"}, + "album":{"id":118106,"title":"Album Title","type":"album"},"type":"track"} + ]} + """ + response = mock.Mock(text=json) + results = deezer.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of track') + self.assertEqual(results[0]['url'], 'https://www.deezer.com/track/1094042') + self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') + self.assertTrue('100' in results[0]['embedded']) + + json = """ + {"data":[ + {"id":200,"name":"Artist Name", + "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = deezer.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_deviantart.py b/tests/unit/engines/test_deviantart.py new file mode 100644 index 000000000..78a391334 --- /dev/null +++ b/tests/unit/engines/test_deviantart.py @@ -0,0 +1,118 @@ +from collections import defaultdict +import mock +from searx.engines import deviantart +from searx.testing import SearxTestCase + + +class TestDeviantartEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = deviantart.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('deviantart.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, deviantart.response, None) + self.assertRaises(AttributeError, deviantart.response, []) + self.assertRaises(AttributeError, deviantart.response, '') + self.assertRaises(AttributeError, deviantart.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(deviantart.response(response), []) + + response = mock.Mock(status_code=302) + self.assertEqual(deviantart.response(response), []) + + html = """ +
    + + + + + + + Test + + + + + + + Title of image + + + + 5 years ago + + in Animation + + + + More Like This + + + +
    + """ + response = mock.Mock(text=html) + results = deviantart.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of image') + self.assertEqual(results[0]['url'], 'http://url.of.result/2nd.part.of.url') + self.assertNotIn('content', results[0]) + self.assertEqual(results[0]['thumbnail_src'], 'https://url.of.thumbnail') + + html = """ + + + + + + Test + + + + + + + Title of image + + + + 5 years ago + + in Animation + + + + More Like This + + + """ + response = mock.Mock(text=html) + results = deviantart.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_digg.py b/tests/unit/engines/test_digg.py new file mode 100644 index 000000000..6e7c9cc99 --- /dev/null +++ b/tests/unit/engines/test_digg.py @@ -0,0 +1,101 @@ +from collections import defaultdict +import mock +from searx.engines import digg +from searx.testing import SearxTestCase + + +class TestDiggEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = digg.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('digg.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, digg.response, None) + self.assertRaises(AttributeError, digg.response, []) + self.assertRaises(AttributeError, digg.response, '') + self.assertRaises(AttributeError, digg.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(digg.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(digg.response(response), []) + + json = """ + { + "status": "ok", + "num": 10, + "next_position": 20, + "html": "" + } + """ + json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(text=json) + results = digg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of article') + self.assertEqual(results[0]['url'], 'http://url.of.link') + self.assertEqual(results[0]['thumbnail'], 'http://url.of.image.jpeg') + self.assertEqual(results[0]['content'], '') + + json = """ + { + "status": "error", + "num": 10, + "next_position": 20 + } + """ + response = mock.Mock(text=json) + results = digg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py new file mode 100644 index 000000000..14cd9cd87 --- /dev/null +++ b/tests/unit/engines/test_duckduckgo.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import duckduckgo +from searx.testing import SearxTestCase + + +class TestDuckduckgoEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = duckduckgo.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('duckduckgo.com', params['url']) + self.assertIn('fr-fr', params['url']) + + dicto['language'] = 'all' + params = duckduckgo.request(query, dicto) + self.assertIn('en-us', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, duckduckgo.response, None) + self.assertRaises(AttributeError, duckduckgo.response, []) + self.assertRaises(AttributeError, duckduckgo.response, '') + self.assertRaises(AttributeError, duckduckgo.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(duckduckgo.response(response), []) + + html = u""" + + """ + response = mock.Mock(text=html) + results = duckduckgo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], u'http://this.should.be.the.link/ű') + self.assertEqual(results[0]['content'], 'This should be the content.') + + html = """ + + + """ + response = mock.Mock(text=html) + results = duckduckgo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_duckduckgo_definitions.py b/tests/unit/engines/test_duckduckgo_definitions.py new file mode 100644 index 000000000..71c84235c --- /dev/null +++ b/tests/unit/engines/test_duckduckgo_definitions.py @@ -0,0 +1,250 @@ +from collections import defaultdict +import mock +from searx.engines import duckduckgo_definitions +from searx.testing import SearxTestCase + + +class TestDDGDefinitionsEngine(SearxTestCase): + + def test_result_to_text(self): + url = '' + text = 'Text' + html_result = 'Html' + result = duckduckgo_definitions.result_to_text(url, text, html_result) + self.assertEqual(result, text) + + html_result = 'Text in link' + result = duckduckgo_definitions.result_to_text(url, text, html_result) + self.assertEqual(result, 'Text in link') + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = duckduckgo_definitions.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('duckduckgo.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, duckduckgo_definitions.response, None) + self.assertRaises(AttributeError, duckduckgo_definitions.response, []) + self.assertRaises(AttributeError, duckduckgo_definitions.response, '') + self.assertRaises(AttributeError, duckduckgo_definitions.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(duckduckgo_definitions.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(duckduckgo_definitions.response(response), []) + + json = """ + { + "DefinitionSource": "definition source", + "Heading": "heading", + "ImageWidth": 0, + "RelatedTopics": [ + { + "Result": "Top-level domains", + "Icon": { + "URL": "", + "Height": "", + "Width": "" + }, + "FirstURL": "https://first.url", + "Text": "text" + }, + { + "Topics": [ + { + "Result": "result topic", + "Icon": { + "URL": "", + "Height": "", + "Width": "" + }, + "FirstURL": "https://duckduckgo.com/?q=2%2F2", + "Text": "result topic text" + } + ], + "Name": "name" + } + ], + "Entity": "Entity", + "Type": "A", + "Redirect": "", + "DefinitionURL": "http://definition.url", + "AbstractURL": "https://abstract.url", + "Definition": "this is the definition", + "AbstractSource": "abstract source", + "Infobox": { + "content": [ + { + "data_type": "string", + "value": "1999", + "label": "Introduced", + "wiki_order": 0 + } + ], + "meta": [ + { + "data_type": "string", + "value": ".test", + "label": "article_title" + } + ] + }, + "Image": "image.png", + "ImageIsLogo": 0, + "Abstract": "abstract", + "AbstractText": "abstract text", + "AnswerType": "", + "ImageHeight": 0, + "Results": [{ + "Result" : "result title", + "Icon" : { + "URL" : "result url", + "Height" : 16, + "Width" : 16 + }, + "FirstURL" : "result first url", + "Text" : "result text" + } + ], + "Answer": "answer" + } + """ + response = mock.Mock(text=json) + results = duckduckgo_definitions.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 4) + self.assertEqual(results[0]['answer'], 'answer') + self.assertEqual(results[1]['title'], 'heading') + self.assertEqual(results[1]['url'], 'result first url') + self.assertEqual(results[2]['suggestion'], 'text') + self.assertEqual(results[3]['infobox'], 'heading') + self.assertEqual(results[3]['id'], 'http://definition.url') + self.assertEqual(results[3]['entity'], 'Entity') + self.assertIn('abstract', results[3]['content']) + self.assertIn('this is the definition', results[3]['content']) + self.assertEqual(results[3]['img_src'], 'image.png') + self.assertIn('Introduced', results[3]['attributes'][0]['label']) + self.assertIn('1999', results[3]['attributes'][0]['value']) + self.assertIn({'url': 'https://abstract.url', 'title': 'abstract source'}, results[3]['urls']) + self.assertIn({'url': 'http://definition.url', 'title': 'definition source'}, results[3]['urls']) + self.assertIn({'name': 'name', 'suggestions': ['result topic text']}, results[3]['relatedTopics']) + + json = """ + { + "DefinitionSource": "definition source", + "Heading": "heading", + "ImageWidth": 0, + "RelatedTopics": [], + "Entity": "Entity", + "Type": "A", + "Redirect": "", + "DefinitionURL": "", + "AbstractURL": "https://abstract.url", + "Definition": "", + "AbstractSource": "abstract source", + "Image": "", + "ImageIsLogo": 0, + "Abstract": "", + "AbstractText": "abstract text", + "AnswerType": "", + "ImageHeight": 0, + "Results": [], + "Answer": "" + } + """ + response = mock.Mock(text=json) + results = duckduckgo_definitions.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['url'], 'https://abstract.url') + self.assertEqual(results[0]['title'], 'heading') + self.assertEqual(results[0]['content'], '') + + json = """ + { + "DefinitionSource": "definition source", + "Heading": "heading", + "ImageWidth": 0, + "RelatedTopics": [ + { + "Result": "Top-level domains", + "Icon": { + "URL": "", + "Height": "", + "Width": "" + }, + "FirstURL": "https://first.url", + "Text": "heading" + }, + { + "Name": "name" + }, + { + "Topics": [ + { + "Result": "result topic", + "Icon": { + "URL": "", + "Height": "", + "Width": "" + }, + "FirstURL": "https://duckduckgo.com/?q=2%2F2", + "Text": "heading" + } + ], + "Name": "name" + } + ], + "Entity": "Entity", + "Type": "A", + "Redirect": "", + "DefinitionURL": "http://definition.url", + "AbstractURL": "https://abstract.url", + "Definition": "this is the definition", + "AbstractSource": "abstract source", + "Infobox": { + "meta": [ + { + "data_type": "string", + "value": ".test", + "label": "article_title" + } + ] + }, + "Image": "image.png", + "ImageIsLogo": 0, + "Abstract": "abstract", + "AbstractText": "abstract text", + "AnswerType": "", + "ImageHeight": 0, + "Results": [{ + "Result" : "result title", + "Icon" : { + "URL" : "result url", + "Height" : 16, + "Width" : 16 + }, + "Text" : "result text" + } + ], + "Answer": "" + } + """ + response = mock.Mock(text=json) + results = duckduckgo_definitions.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['infobox'], 'heading') + self.assertEqual(results[0]['id'], 'http://definition.url') + self.assertEqual(results[0]['entity'], 'Entity') + self.assertIn('abstract', results[0]['content']) + self.assertIn('this is the definition', results[0]['content']) + self.assertEqual(results[0]['img_src'], 'image.png') + self.assertIn({'url': 'https://abstract.url', 'title': 'abstract source'}, results[0]['urls']) + self.assertIn({'url': 'http://definition.url', 'title': 'definition source'}, results[0]['urls']) + self.assertIn({'name': 'name', 'suggestions': []}, results[0]['relatedTopics']) diff --git a/tests/unit/engines/test_dummy.py b/tests/unit/engines/test_dummy.py new file mode 100644 index 000000000..9399beaaf --- /dev/null +++ b/tests/unit/engines/test_dummy.py @@ -0,0 +1,26 @@ +from searx.engines import dummy +from searx.testing import SearxTestCase + + +class TestDummyEngine(SearxTestCase): + + def test_request(self): + test_params = [ + [1, 2, 3], + ['a'], + [], + 1 + ] + for params in test_params: + self.assertEqual(dummy.request(None, params), params) + + def test_response(self): + responses = [ + None, + [], + True, + dict(), + tuple() + ] + for response in responses: + self.assertEqual(dummy.response(response), []) diff --git a/tests/unit/engines/test_faroo.py b/tests/unit/engines/test_faroo.py new file mode 100644 index 000000000..acebdda86 --- /dev/null +++ b/tests/unit/engines/test_faroo.py @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import faroo +from searx.testing import SearxTestCase + + +class TestFarooEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + dicto['category'] = 'general' + params = faroo.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('faroo.com', params['url']) + self.assertIn('en', params['url']) + self.assertIn('web', params['url']) + + dicto['language'] = 'all' + params = faroo.request(query, dicto) + self.assertIn('en', params['url']) + + dicto['language'] = 'de_DE' + params = faroo.request(query, dicto) + self.assertIn('de', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, faroo.response, None) + self.assertRaises(AttributeError, faroo.response, []) + self.assertRaises(AttributeError, faroo.response, '') + self.assertRaises(AttributeError, faroo.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(faroo.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(faroo.response(response), []) + + response = mock.Mock(text='{"data": []}', status_code=401) + self.assertRaises(Exception, faroo.response, response) + + response = mock.Mock(text='{"data": []}', status_code=429) + self.assertRaises(Exception, faroo.response, response) + + json = """ + { + "results": [ + { + "title": "This is the title", + "kwic": "This is the content", + "content": "", + "url": "http://this.is.the.url/", + "iurl": "", + "domain": "css3test.com", + "author": "Jim Dalrymple", + "news": true, + "votes": "10", + "date": 1360622563000, + "related": [] + }, + { + "title": "This is the title2", + "kwic": "This is the content2", + "content": "", + "url": "http://this.is.the.url2/", + "iurl": "", + "domain": "css3test.com", + "author": "Jim Dalrymple", + "news": false, + "votes": "10", + "related": [] + }, + { + "title": "This is the title3", + "kwic": "This is the content3", + "content": "", + "url": "http://this.is.the.url3/", + "iurl": "http://upload.wikimedia.org/optimized.jpg", + "domain": "css3test.com", + "author": "Jim Dalrymple", + "news": false, + "votes": "10", + "related": [] + } + ], + "query": "test", + "suggestions": [], + "count": 100, + "start": 1, + "length": 10, + "time": "15" + } + """ + response = mock.Mock(text=json) + results = faroo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 4) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertEqual(results[1]['title'], 'This is the title2') + self.assertEqual(results[1]['url'], 'http://this.is.the.url2/') + self.assertEqual(results[1]['content'], 'This is the content2') + self.assertEqual(results[3]['img_src'], 'http://upload.wikimedia.org/optimized.jpg') + + json = """ + {} + """ + response = mock.Mock(text=json) + results = faroo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_flickr.py b/tests/unit/engines/test_flickr.py new file mode 100644 index 000000000..8b39e922f --- /dev/null +++ b/tests/unit/engines/test_flickr.py @@ -0,0 +1,142 @@ +from collections import defaultdict +import mock +from searx.engines import flickr +from searx.testing import SearxTestCase + + +class TestFlickrEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = flickr.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('flickr.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, flickr.response, None) + self.assertRaises(AttributeError, flickr.response, []) + self.assertRaises(AttributeError, flickr.response, '') + self.assertRaises(AttributeError, flickr.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(flickr.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(flickr.response(response), []) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_o": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_9178e0f963_o.jpg", + "height_o": "2100", "width_o": "2653", + "url_n": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_n.jpg", + "height_n": "253", "width_n": "320", + "url_z": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_z.jpg", + "height_z": "507", "width_z": "640" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Photo title') + self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') + self.assertTrue('o.jpg' in results[0]['img_src']) + self.assertTrue('n.jpg' in results[0]['thumbnail_src']) + self.assertTrue('Owner' in results[0]['content']) + self.assertTrue('Description' in results[0]['content']) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_z": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_z.jpg", + "height_z": "507", "width_z": "640" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Photo title') + self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') + self.assertTrue('z.jpg' in results[0]['img_src']) + self.assertTrue('z.jpg' in results[0]['thumbnail_src']) + self.assertTrue('Owner' in results[0]['content']) + self.assertTrue('Description' in results[0]['content']) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_o": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_9178e0f963_o.jpg", + "height_o": "2100", "width_o": "2653" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Photo title') + self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') + self.assertTrue('o.jpg' in results[0]['img_src']) + self.assertTrue('o.jpg' in results[0]['thumbnail_src']) + self.assertTrue('Owner' in results[0]['content']) + self.assertTrue('Description' in results[0]['content']) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_n": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_n.jpg", + "height_n": "253", "width_n": "320" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "toto": [] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_flickr_noapi.py b/tests/unit/engines/test_flickr_noapi.py new file mode 100644 index 000000000..3b337a2d8 --- /dev/null +++ b/tests/unit/engines/test_flickr_noapi.py @@ -0,0 +1,328 @@ +from collections import defaultdict +import mock +from searx.engines import flickr_noapi +from searx.testing import SearxTestCase + + +class TestFlickrNoapiEngine(SearxTestCase): + + def test_build_flickr_url(self): + url = flickr_noapi.build_flickr_url("uid", "pid") + self.assertIn("uid", url) + self.assertIn("pid", url) + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = flickr_noapi.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('flickr.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, flickr_noapi.response, None) + self.assertRaises(AttributeError, flickr_noapi.response, []) + self.assertRaises(AttributeError, flickr_noapi.response, '') + self.assertRaises(AttributeError, flickr_noapi.response, '[]') + + response = mock.Mock(text='"search-photos-lite-models","photos":{},"totalItems":') + self.assertEqual(flickr_noapi.response(response), []) + + response = mock.Mock(text='search-photos-lite-models","photos":{"data": []},"totalItems":') + self.assertEqual(flickr_noapi.response(response), []) + + # everthing is ok test + json = """ + "search-photos-lite-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-lite-models", + "title": "This is the title", + "username": "Owner", + "pathAlias": "klink692", + "realname": "Owner", + "license": 0, + "ownerNsid": "59729010@N00", + "canComment": false, + "commentCount": 14, + "faveCount": 21, + "id": "14001294434", + "sizes": { + "c": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_c.jpg", + "width": 541, + "height": 800, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_c.jpg", + "key": "c" + }, + "h": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_761d32237a_h.jpg", + "width": 1081, + "height": 1600, + "url": "//c4.staticflickr.com/8/7246/14001294434_761d32237a_h.jpg", + "key": "h" + }, + "k": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_f145a2c11a_k.jpg", + "width": 1383, + "height": 2048, + "url": "//c4.staticflickr.com/8/7246/14001294434_f145a2c11a_k.jpg", + "key": "k" + }, + "l": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_b.jpg", + "width": 692, + "height": 1024, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_b.jpg", + "key": "l" + }, + "m": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777.jpg", + "width": 338, + "height": 500, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777.jpg", + "key": "m" + }, + "n": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_n.jpg", + "width": 216, + "height": 320, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_n.jpg", + "key": "n" + }, + "q": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_q.jpg", + "width": 150, + "height": 150, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_q.jpg", + "key": "q" + }, + "s": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_m.jpg", + "width": 162, + "height": 240, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_m.jpg", + "key": "s" + }, + "sq": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_s.jpg", + "width": 75, + "height": 75, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_s.jpg", + "key": "sq" + }, + "t": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_t.jpg", + "width": 68, + "height": 100, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_t.jpg", + "key": "t" + }, + "z": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg", + "key": "z" + } + } + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') + self.assertIn('k.jpg', results[0]['img_src']) + self.assertIn('n.jpg', results[0]['thumbnail_src']) + self.assertIn('Owner', results[0]['content']) + + # no n size, only the z size + json = """ + "search-photos-lite-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-lite-models", + "title": "This is the title", + "username": "Owner", + "pathAlias": "klink692", + "realname": "Owner", + "license": 0, + "ownerNsid": "59729010@N00", + "canComment": false, + "commentCount": 14, + "faveCount": 21, + "id": "14001294434", + "sizes": { + "z": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg", + "key": "z" + } + } + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') + self.assertIn('z.jpg', results[0]['img_src']) + self.assertIn('z.jpg', results[0]['thumbnail_src']) + self.assertIn('Owner', results[0]['content']) + + # no z or n size + json = """ + "search-photos-lite-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-lite-models", + "title": "This is the title", + "username": "Owner", + "pathAlias": "klink692", + "realname": "Owner", + "license": 0, + "ownerNsid": "59729010@N00", + "canComment": false, + "commentCount": 14, + "faveCount": 21, + "id": "14001294434", + "sizes": { + "o": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg", + "key": "o" + } + } + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') + self.assertIn('o.jpg', results[0]['img_src']) + self.assertIn('o.jpg', results[0]['thumbnail_src']) + self.assertIn('Owner', results[0]['content']) + + # no image test + json = """ + "search-photos-lite-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-lite-models", + "title": "This is the title", + "username": "Owner", + "pathAlias": "klink692", + "realname": "Owner", + "license": 0, + "ownerNsid": "59729010@N00", + "canComment": false, + "commentCount": 14, + "faveCount": 21, + "id": "14001294434", + "sizes": { + } + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + # null test + json = """ + "search-photos-models","photos": + { + "_data": [null], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + # no ownerNsid test + json = """ + "search-photos-lite-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-lite-models", + "title": "This is the title", + "username": "Owner", + "pathAlias": "klink692", + "realname": "Owner", + "license": 0, + "canComment": false, + "commentCount": 14, + "faveCount": 21, + "id": "14001294434", + "sizes": { + "o": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg", + "key": "o" + } + } + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + # garbage test + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_gigablast.py b/tests/unit/engines/test_gigablast.py new file mode 100644 index 000000000..4ae0c51a9 --- /dev/null +++ b/tests/unit/engines/test_gigablast.py @@ -0,0 +1,58 @@ +from collections import defaultdict +import mock +from searx.engines import gigablast +from searx.testing import SearxTestCase + + +class TestGigablastEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'all' + params = gigablast.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('gigablast.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, gigablast.response, None) + self.assertRaises(AttributeError, gigablast.response, []) + self.assertRaises(AttributeError, gigablast.response, '') + self.assertRaises(AttributeError, gigablast.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(gigablast.response(response), []) + + response = mock.Mock(content='') + self.assertEqual(gigablast.response(response), []) + + xml = """ + + 5941888 + 1 + + <![CDATA[This should be the title]]> + + + 90.5 + 145414002633 + 2660021087 + 2660021087 + 1320519373 + 1320519373 + 4294967295 + 0 + + + + + """ + response = mock.Mock(content=xml) + results = gigablast.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') diff --git a/tests/unit/engines/test_github.py b/tests/unit/engines/test_github.py new file mode 100644 index 000000000..460be8c3d --- /dev/null +++ b/tests/unit/engines/test_github.py @@ -0,0 +1,61 @@ +from collections import defaultdict +import mock +from searx.engines import github +from searx.testing import SearxTestCase + + +class TestGitHubEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + params = github.request(query, defaultdict(dict)) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('github.com' in params['url']) + self.assertEqual(params['headers']['Accept'], github.accept_header) + + def test_response(self): + self.assertRaises(AttributeError, github.response, None) + self.assertRaises(AttributeError, github.response, []) + self.assertRaises(AttributeError, github.response, '') + self.assertRaises(AttributeError, github.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(github.response(response), []) + + response = mock.Mock(text='{"items": []}') + self.assertEqual(github.response(response), []) + + json = """ + { + "items": [ + { + "name": "title", + "html_url": "url", + "description": "" + } + ] + } + """ + response = mock.Mock(text=json) + results = github.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'title') + self.assertEqual(results[0]['url'], 'url') + self.assertEqual(results[0]['content'], '') + + json = """ + { + "items": [ + { + "name": "title", + "html_url": "url", + "description": "desc" + } + ] + } + """ + response = mock.Mock(text=json) + results = github.response(response) + self.assertEqual(results[0]['content'], "desc") diff --git a/tests/unit/engines/test_google.py b/tests/unit/engines/test_google.py new file mode 100644 index 000000000..37a83cae3 --- /dev/null +++ b/tests/unit/engines/test_google.py @@ -0,0 +1,178 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +import lxml +from searx.engines import google +from searx.testing import SearxTestCase + + +class TestGoogleEngine(SearxTestCase): + + def mock_response(self, text): + response = mock.Mock(text=text, url='https://www.google.com/search?q=test&start=0&gbv=1&gws_rd=cr') + response.search_params = mock.Mock() + response.search_params.get = mock.Mock(return_value='www.google.com') + return response + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = google.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('google.fr', params['url']) + self.assertIn('fr', params['headers']['Accept-Language']) + + dicto['language'] = 'all' + params = google.request(query, dicto) + self.assertIn('google.com', params['url']) + self.assertIn('en', params['headers']['Accept-Language']) + + def test_response(self): + self.assertRaises(AttributeError, google.response, None) + self.assertRaises(AttributeError, google.response, []) + self.assertRaises(AttributeError, google.response, '') + self.assertRaises(AttributeError, google.response, '[]') + + response = self.mock_response('') + self.assertEqual(google.response(response), []) + + html = """ +
    +

    + + This is the title + +

    +
    +
    + + test.psychologies.com/ + +
    ‎ + + +
    +
    + + This should be the content. + +
    + +
    +
    +
    +

    + + This + +

    +
    + + + +

    + + suggestion title + +

    + """ + response = self.mock_response(html) + results = google.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') + self.assertEqual(results[1]['suggestion'], 'suggestion title') + + html = """ +
  • +
  • + """ + response = self.mock_response(html) + results = google.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + response = mock.Mock(text='', url='https://sorry.google.com') + response.search_params = mock.Mock() + response.search_params.get = mock.Mock(return_value='www.google.com') + self.assertRaises(RuntimeWarning, google.response, response) + + response = mock.Mock(text='', url='https://www.google.com/sorry/IndexRedirect') + response.search_params = mock.Mock() + response.search_params.get = mock.Mock(return_value='www.google.com') + self.assertRaises(RuntimeWarning, google.response, response) + + def test_parse_images(self): + html = """ +
  • +
    + + + +
    +
  • + """ + dom = lxml.html.fromstring(html) + results = google.parse_images(dom, 'www.google.com') + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertEqual(results[0]['title'], '') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['img_src'], 'https://this.is.the.image/image.jpg') diff --git a/tests/unit/engines/test_google_images.py b/tests/unit/engines/test_google_images.py new file mode 100644 index 000000000..876d0af1e --- /dev/null +++ b/tests/unit/engines/test_google_images.py @@ -0,0 +1,58 @@ +from collections import defaultdict +import mock +from searx.engines import google_images +from searx.testing import SearxTestCase + + +class TestGoogleImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['safesearch'] = 1 + params = google_images.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('safe=active', params['url']) + + dicto['safesearch'] = 0 + params = google_images.request(query, dicto) + self.assertNotIn('safe', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, google_images.response, None) + self.assertRaises(AttributeError, google_images.response, []) + self.assertRaises(AttributeError, google_images.response, '') + self.assertRaises(AttributeError, google_images.response, '[]') + + response = mock.Mock(text='
    ') + self.assertEqual(google_images.response(response), []) + + html = """ +
    + +
    +
    + Image result for south +
    +
    504 × 598 - clker.com +
    +
    +
    +
    + {"id":"bQWQ9wz9loJmjM:","isu":"clker.com","ity":"png","md":"/search?tbs\u003dsbi:AMhZZit7u1mHyop9pQisu-5idR-8W_1Itvwc3afChmsjQYPx_1yYMzBvUZgtkcGoojqekKZ-6n_1rjX9ySH0OWA_1eO5OijFY6BBDw_1GApr6xxb1bXJcBcj-DiguMoXWW7cZSG7MRQbwnI5SoDZNXcv_1xGszy886I7NVb_1oRKSliTHtzqbXAxhvYreM","msu":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAQSEgltBZD3DP2WgiG-U42R4G0RFw","oh":598,"os":"13KB","ow":504,"pt":"South Arrow Clip Art at Clker.com - vector clip art online ...","rid":"vlONkeBtERfDuM","s":"Download this image as:","sc":1,"si":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAESEgltBZD3DP2WgiG-U42R4G0RFw","th":245,"tu":"https://thumbnail.url/","tw":206} +
    +
    +
    +
    + """ # noqa + response = mock.Mock(text=html) + results = google_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], u'South Arrow Clip Art at Clker.com - vector clip art online ...') + self.assertEqual(results[0]['url'], 'http://www.clker.com/clipart-south-arrow.html') + self.assertEqual(results[0]['thumbnail_src'], 'https://thumbnail.url/') + self.assertEqual(results[0]['img_src'], 'http://www.clker.com/cliparts/H/X/l/b/0/0/south-arrow-hi.png') + self.assertEqual(results[0]['content'], 'Download this image as:') diff --git a/tests/unit/engines/test_google_news.py b/tests/unit/engines/test_google_news.py new file mode 100644 index 000000000..31d674121 --- /dev/null +++ b/tests/unit/engines/test_google_news.py @@ -0,0 +1,136 @@ +from collections import defaultdict +import mock +from searx.engines import google_news +from searx.testing import SearxTestCase + + +class TestGoogleNewsEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = google_news.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('googleapis.com', params['url']) + self.assertIn('fr', params['url']) + + dicto['language'] = 'all' + params = google_news.request(query, dicto) + self.assertIn('url', params) + self.assertIn('en', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, google_news.response, None) + self.assertRaises(AttributeError, google_news.response, []) + self.assertRaises(AttributeError, google_news.response, '') + self.assertRaises(AttributeError, google_news.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(google_news.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(google_news.response(response), []) + + json = """ + { + "responseData": { + "results": [ + { + "GsearchResultClass": "GnewsSearch", + "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr", + "content": "This is the content", + "unescapedUrl": "http://this.is.the.url", + "url": "http://this.is.the.url", + "title": "This is the title", + "titleNoFormatting": "This is the title", + "location": "", + "publisher": "Jeux Actu", + "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800", + "signedRedirectUrl": "http://news.google.com/", + "language": "fr", + "image": { + "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg", + "tbUrl": "http://t1.gstatic.com/images?q=tbn:ANd9GcSF4yYrs9Ycw23DGiOSAZ-5SEPXYwG3LNs", + "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm", + "publisher": "Jeux Actu", + "tbWidth": 80, + "tbHeight": 30 + }, + "relatedStories": [ + { + "unescapedUrl": "http://www.jeuxvideo.com/test/415823/dying-light.htm", + "url": "http%3A%2F%2Fwww.jeuxvideo.com%2Ftest%2F415823%2Fdying-light.htm", + "title": "Test du jeu Dying Light - jeuxvideo.com", + "titleNoFormatting": "Test du jeu Dying Light - jeuxvideo.com", + "location": "", + "publisher": "JeuxVideo.com", + "publishedDate": "Fri, 30 Jan 2015 08:52:30 -0800", + "signedRedirectUrl": "http://news.google.com/news/url?sa=T&", + "language": "fr" + } + ] + } + ] + }, + "responseDetails": null, + "responseStatus": 200 + } + """ + response = mock.Mock(text=json) + results = google_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'http://this.is.the.url') + self.assertEqual(results[0]['content'], 'This is the content') + + json = """ + { + "responseData": { + "results": [ + { + "GsearchResultClass": "GnewsSearch", + "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr", + "content": "This is the content", + "unescapedUrl": "http://this.is.the.url", + "title": "This is the title", + "titleNoFormatting": "This is the title", + "location": "", + "publisher": "Jeux Actu", + "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800", + "signedRedirectUrl": "http://news.google.com/news/", + "language": "fr", + "image": { + "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg", + "tbUrl": "http://t1.gstatic.com/images?q=tbn:b_6f-OSAZ-5SEPXYwG3LNs", + "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm", + "publisher": "Jeux Actu", + "tbWidth": 80, + "tbHeight": 30 + } + } + ] + }, + "responseDetails": null, + "responseStatus": 200 + } + """ + response = mock.Mock(text=json) + results = google_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "responseData": {}, + "responseDetails": null, + "responseStatus": 200 + } + """ + response = mock.Mock(text=json) + results = google_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_kickass.py b/tests/unit/engines/test_kickass.py new file mode 100644 index 000000000..4cfcaa63c --- /dev/null +++ b/tests/unit/engines/test_kickass.py @@ -0,0 +1,397 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import kickass +from searx.testing import SearxTestCase + + +class TestKickassEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = kickass.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('kickass.to', params['url']) + self.assertFalse(params['verify']) + + def test_response(self): + self.assertRaises(AttributeError, kickass.response, None) + self.assertRaises(AttributeError, kickass.response, []) + self.assertRaises(AttributeError, kickass.response, '') + self.assertRaises(AttributeError, kickass.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(kickass.response(response), []) + + html = """ + + + + + + + + + + + + + + + + + +
    torrent name + size + + files + + age + + seed + + leech +
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    449 bytes42 years101
    + """ + response = mock.Mock(text=html) + results = kickass.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') + self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') + self.assertEqual(results[0]['seed'], 10) + self.assertEqual(results[0]['leech'], 1) + self.assertEqual(results[0]['filesize'], 449) + self.assertEqual(results[0]['files'], 4) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETURL&dn=test') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/53917.torrent?title=test') + + html = """ + + + + + + + + + +
    torrent name + size + + files + + age + + seed + + leech +
    + """ + response = mock.Mock(text=html) + results = kickass.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    torrent name + size + + files + + age + + seed + + leech +
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 KB42 years101
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 MB42 years91
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 GB42 years81
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 TB42 years71
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    z bytesr2 yearsat
    + """ + response = mock.Mock(text=html) + results = kickass.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 5) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') + self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') + self.assertEqual(results[0]['seed'], 10) + self.assertEqual(results[0]['leech'], 1) + self.assertEqual(results[0]['files'], 4) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETURL&dn=test') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/53917.torrent?title=test') + self.assertEqual(results[0]['filesize'], 1024) + self.assertEqual(results[1]['filesize'], 1048576) + self.assertEqual(results[2]['filesize'], 1073741824) + self.assertEqual(results[3]['filesize'], 1099511627776) + self.assertEqual(results[4]['seed'], 0) + self.assertEqual(results[4]['leech'], 0) + self.assertEqual(results[4]['files'], None) + self.assertEqual(results[4]['filesize'], None) diff --git a/tests/unit/engines/test_mediawiki.py b/tests/unit/engines/test_mediawiki.py new file mode 100644 index 000000000..63f7da6b2 --- /dev/null +++ b/tests/unit/engines/test_mediawiki.py @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import mediawiki +from searx.testing import SearxTestCase + + +class TestMediawikiEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = mediawiki.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('wikipedia.org', params['url']) + self.assertIn('fr', params['url']) + + dicto['language'] = 'all' + params = mediawiki.request(query, dicto) + self.assertIn('en', params['url']) + + mediawiki.base_url = "http://test.url/" + mediawiki.search_url = mediawiki.base_url +\ + 'w/api.php?action=query'\ + '&list=search'\ + '&{query}'\ + '&srprop=timestamp'\ + '&format=json'\ + '&sroffset={offset}'\ + '&srlimit={limit}' # noqa + params = mediawiki.request(query, dicto) + self.assertIn('test.url', params['url']) + + def test_response(self): + dicto = defaultdict(dict) + dicto['language'] = 'fr' + mediawiki.base_url = "https://{language}.wikipedia.org/" + + self.assertRaises(AttributeError, mediawiki.response, None) + self.assertRaises(AttributeError, mediawiki.response, []) + self.assertRaises(AttributeError, mediawiki.response, '') + self.assertRaises(AttributeError, mediawiki.response, '[]') + + response = mock.Mock(text='{}', search_params=dicto) + self.assertEqual(mediawiki.response(response), []) + + response = mock.Mock(text='{"data": []}', search_params=dicto) + self.assertEqual(mediawiki.response(response), []) + + json = """ + { + "query-continue": { + "search": { + "sroffset": 1 + } + }, + "query": { + "searchinfo": { + "totalhits": 29721 + }, + "search": [ + { + "ns": 0, + "title": "This is the title étude", + "timestamp": "2014-12-19T17:42:52Z" + } + ] + } + } + """ + response = mock.Mock(text=json, search_params=dicto) + results = mediawiki.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], u'This is the title étude') + self.assertIn('fr.wikipedia.org', results[0]['url']) + self.assertIn('This_is_the_title', results[0]['url']) + self.assertIn('%C3%A9tude', results[0]['url']) + self.assertEqual(results[0]['content'], '') + + json = """ + { + "query-continue": { + "search": { + "sroffset": 1 + } + }, + "query": { + "searchinfo": { + "totalhits": 29721 + }, + "search": [ + ] + } + } + """ + response = mock.Mock(text=json, search_params=dicto) + results = mediawiki.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "query-continue": { + "search": { + "sroffset": 1 + } + }, + "query": { + } + } + """ + response = mock.Mock(text=json, search_params=dicto) + results = mediawiki.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.mediawiki.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json, search_params=dicto) + results = mediawiki.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_mixcloud.py b/tests/unit/engines/test_mixcloud.py new file mode 100644 index 000000000..a2ea47cf9 --- /dev/null +++ b/tests/unit/engines/test_mixcloud.py @@ -0,0 +1,67 @@ +from collections import defaultdict +import mock +from searx.engines import mixcloud +from searx.testing import SearxTestCase + + +class TestMixcloudEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = mixcloud.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('mixcloud.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, mixcloud.response, None) + self.assertRaises(AttributeError, mixcloud.response, []) + self.assertRaises(AttributeError, mixcloud.response, '') + self.assertRaises(AttributeError, mixcloud.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(mixcloud.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(mixcloud.response(response), []) + + json = """ + {"data":[ + { + "user": { + "url": "http://www.mixcloud.com/user/", + "username": "user", + "name": "User", + "key": "/user/" + }, + "key": "/user/this-is-the-url/", + "created_time": "2014-11-14T13:30:02Z", + "audio_length": 3728, + "slug": "this-is-the-url", + "name": "Title of track", + "url": "http://www.mixcloud.com/user/this-is-the-url/", + "updated_time": "2014-11-14T13:14:10Z" + } + ]} + """ + response = mock.Mock(text=json) + results = mixcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of track') + self.assertEqual(results[0]['url'], 'http://www.mixcloud.com/user/this-is-the-url/') + self.assertEqual(results[0]['content'], 'User') + self.assertTrue('http://www.mixcloud.com/user/this-is-the-url/' in results[0]['embedded']) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.mixcloud.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = mixcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_openstreetmap.py b/tests/unit/engines/test_openstreetmap.py new file mode 100644 index 000000000..7b7783f04 --- /dev/null +++ b/tests/unit/engines/test_openstreetmap.py @@ -0,0 +1,199 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import openstreetmap +from searx.testing import SearxTestCase + + +class TestOpenstreetmapEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = openstreetmap.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('openstreetmap.org', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, openstreetmap.response, None) + self.assertRaises(AttributeError, openstreetmap.response, []) + self.assertRaises(AttributeError, openstreetmap.response, '') + self.assertRaises(AttributeError, openstreetmap.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(openstreetmap.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(openstreetmap.response(response), []) + + json = """ + [ + { + "place_id": "127732055", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", + "osm_type": "relation", + "osm_id": "7444", + "boundingbox": [ + "48.8155755", + "48.902156", + "2.224122", + "2.4697602" + ], + "lat": "48.8565056", + "lon": "2.3521334", + "display_name": "This is the title", + "class": "place", + "type": "city", + "importance": 0.96893459932191, + "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", + "address": { + "city": "Paris", + "county": "Paris", + "state": "Île-de-France", + "country": "France", + "country_code": "fr" + }, + "geojson": { + "type": "Polygon", + "coordinates": [ + [ + [ + 2.224122, + 48.854199 + ] + ] + ] + } + } + ] + """ + response = mock.Mock(text=json) + results = openstreetmap.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://openstreetmap.org/relation/7444') + self.assertIn('coordinates', results[0]['geojson']) + self.assertEqual(results[0]['geojson']['coordinates'][0][0][0], 2.224122) + self.assertEqual(results[0]['geojson']['coordinates'][0][0][1], 48.854199) + self.assertEqual(results[0]['address'], None) + self.assertIn('48.8155755', results[0]['boundingbox']) + self.assertIn('48.902156', results[0]['boundingbox']) + self.assertIn('2.224122', results[0]['boundingbox']) + self.assertIn('2.4697602', results[0]['boundingbox']) + + json = """ + [ + { + "place_id": "127732055", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", + "osm_type": "relation", + "osm_id": "7444", + "boundingbox": [ + "48.8155755", + "48.902156", + "2.224122", + "2.4697602" + ], + "lat": "48.8565056", + "lon": "2.3521334", + "display_name": "This is the title", + "class": "tourism", + "type": "city", + "importance": 0.96893459932191, + "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", + "address": { + "city": "Paris", + "county": "Paris", + "state": "Île-de-France", + "country": "France", + "country_code": "fr", + "address29": "Address" + }, + "geojson": { + "type": "Polygon", + "coordinates": [ + [ + [ + 2.224122, + 48.854199 + ] + ] + ] + } + }, + { + "place_id": "127732055", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", + "osm_type": "relation", + "osm_id": "7444", + "boundingbox": [ + "48.8155755", + "48.902156", + "2.224122", + "2.4697602" + ], + "lat": "48.8565056", + "lon": "2.3521334", + "display_name": "This is the title", + "class": "tourism", + "type": "city", + "importance": 0.96893459932191, + "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", + "address": { + "city": "Paris", + "county": "Paris", + "state": "Île-de-France", + "country": "France", + "postcode": 75000, + "country_code": "fr" + }, + "geojson": { + "type": "Polygon", + "coordinates": [ + [ + [ + 2.224122, + 48.854199 + ] + ] + ] + } + }, + { + "place_id": "127732055", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", + "osm_type": "node", + "osm_id": "7444", + "boundingbox": [ + "48.8155755", + "48.902156", + "2.224122", + "2.4697602" + ], + "lat": "48.8565056", + "lon": "2.3521334", + "display_name": "This is the title", + "class": "tourism", + "type": "city", + "importance": 0.96893459932191, + "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png", + "address": { + "city": "Paris", + "county": "Paris", + "state": "Île-de-France", + "country": "France", + "country_code": "fr", + "address29": "Address" + } + } + ] + """ + response = mock.Mock(text=json) + results = openstreetmap.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 3) + self.assertIn('48.8565056', results[2]['geojson']['coordinates']) + self.assertIn('2.3521334', results[2]['geojson']['coordinates']) diff --git a/tests/unit/engines/test_photon.py b/tests/unit/engines/test_photon.py new file mode 100644 index 000000000..734497884 --- /dev/null +++ b/tests/unit/engines/test_photon.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import photon +from searx.testing import SearxTestCase + + +class TestPhotonEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'all' + params = photon.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('photon.komoot.de', params['url']) + + dicto['language'] = 'all' + params = photon.request(query, dicto) + self.assertNotIn('lang', params['url']) + + dicto['language'] = 'al' + params = photon.request(query, dicto) + self.assertNotIn('lang', params['url']) + + dicto['language'] = 'fr' + params = photon.request(query, dicto) + self.assertIn('fr', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, photon.response, None) + self.assertRaises(AttributeError, photon.response, []) + self.assertRaises(AttributeError, photon.response, '') + self.assertRaises(AttributeError, photon.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(photon.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(photon.response(response), []) + + json = """ + { + "features": [ + { + "properties": { + "osm_key": "waterway", + "extent": [ + -1.4508446, + 51.1614997, + -1.4408036, + 51.1525635 + ], + "name": "This is the title", + "state": "England", + "osm_id": 114823817, + "osm_type": "W", + "osm_value": "river", + "city": "Test Valley", + "country": "United Kingdom" + }, + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + -1.4458571, + 51.1576661 + ] + } + }, + { + "properties": { + "osm_key": "place", + "street": "Rue", + "state": "Ile-de-France", + "osm_id": 129211377, + "osm_type": "R", + "housenumber": "10", + "postcode": "75011", + "osm_value": "house", + "city": "Paris", + "country": "France" + }, + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 2.3725025, + 48.8654481 + ] + } + }, + { + "properties": { + "osm_key": "amenity", + "street": "Allée", + "name": "Bibliothèque", + "state": "Ile-de-France", + "osm_id": 1028573132, + "osm_type": "N", + "postcode": "75001", + "osm_value": "library", + "city": "Paris", + "country": "France" + }, + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 2.3445634, + 48.862494 + ] + } + }, + { + "properties": { + "osm_key": "amenity", + "osm_id": 1028573132, + "osm_type": "Y", + "postcode": "75001", + "osm_value": "library", + "city": "Paris", + "country": "France" + }, + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 2.3445634, + 48.862494 + ] + } + }, + { + } + ], + "type": "FeatureCollection" + } + """ + response = mock.Mock(text=json) + results = photon.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 3) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['longitude'], -1.4458571) + self.assertEqual(results[0]['latitude'], 51.1576661) + self.assertIn(-1.4508446, results[0]['boundingbox']) + self.assertIn(51.1614997, results[0]['boundingbox']) + self.assertIn(-1.4408036, results[0]['boundingbox']) + self.assertIn(51.1525635, results[0]['boundingbox']) + self.assertIn('type', results[0]['geojson']) + self.assertEqual(results[0]['geojson']['type'], 'Point') + self.assertEqual(results[0]['address'], None) + self.assertEqual(results[0]['osm']['type'], 'way') + self.assertEqual(results[0]['osm']['id'], 114823817) + self.assertEqual(results[0]['url'], 'https://openstreetmap.org/way/114823817') + self.assertEqual(results[1]['osm']['type'], 'relation') + self.assertEqual(results[2]['address']['name'], u'Bibliothèque') + self.assertEqual(results[2]['address']['house_number'], None) + self.assertEqual(results[2]['address']['locality'], 'Paris') + self.assertEqual(results[2]['address']['postcode'], '75001') + self.assertEqual(results[2]['address']['country'], 'France') + self.assertEqual(results[2]['osm']['type'], 'node') diff --git a/tests/unit/engines/test_piratebay.py b/tests/unit/engines/test_piratebay.py new file mode 100644 index 000000000..5699380be --- /dev/null +++ b/tests/unit/engines/test_piratebay.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import piratebay +from searx.testing import SearxTestCase + + +class TestPiratebayEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['category'] = 'Toto' + params = piratebay.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('piratebay.se', params['url']) + self.assertIn('0', params['url']) + + dicto['category'] = 'music' + params = piratebay.request(query, dicto) + self.assertIn('100', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, piratebay.response, None) + self.assertRaises(AttributeError, piratebay.response, []) + self.assertRaises(AttributeError, piratebay.response, '') + self.assertRaises(AttributeError, piratebay.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(piratebay.response(response), []) + + html = """ + + + + + + + + + + + + + + + +
    +
    + Anime
    + (Anime) +
    +
    + + + Magnet link + + + Download + + + VIP + + + + This is the content and should be OK + + 13334
    +
    + Anime
    + (Anime) +
    +
    + + + Magnet link + + + VIP + + + + This is the content and should be OK + + 13334
    + """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link') + self.assertEqual(results[0]['content'], 'This is the content and should be OK') + self.assertEqual(results[0]['seed'], 13) + self.assertEqual(results[0]['leech'], 334) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') + + self.assertEqual(results[1]['torrentfile'], None) + + html = """ + + + + + + + + + +
    +
    + Anime
    + (Anime) +
    +
    + + + Magnet link + + + Download + + + VIP + + + + This is the content and should be OK + + sd
    + """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link') + self.assertEqual(results[0]['content'], 'This is the content and should be OK') + self.assertEqual(results[0]['seed'], 0) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') + + html = """ + +
    + """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_qwant.py b/tests/unit/engines/test_qwant.py new file mode 100644 index 000000000..7d79d13d8 --- /dev/null +++ b/tests/unit/engines/test_qwant.py @@ -0,0 +1,317 @@ +from collections import defaultdict +import mock +from searx.engines import qwant +from searx.testing import SearxTestCase + + +class TestQwantEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + qwant.categories = [''] + params = qwant.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('web', params['url']) + self.assertIn('qwant.com', params['url']) + self.assertIn('fr_fr', params['url']) + + dicto['language'] = 'all' + qwant.categories = ['news'] + params = qwant.request(query, dicto) + self.assertFalse('fr' in params['url']) + self.assertIn('news', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, qwant.response, None) + self.assertRaises(AttributeError, qwant.response, []) + self.assertRaises(AttributeError, qwant.response, '') + self.assertRaises(AttributeError, qwant.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(qwant.response(response), []) + + response = mock.Mock(text='{"data": {}}') + self.assertEqual(qwant.response(response), []) + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "result": { + "items": [ + { + "title": "Title", + "score": 9999, + "url": "http://www.url.xyz", + "source": "...", + "desc": "Description", + "date": "", + "_id": "db0aadd62c2a8565567ffc382f5c61fa", + "favicon": "https://s.qwant.com/fav.ico" + } + ], + "filters": [] + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + qwant.categories = ['general'] + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://www.url.xyz') + self.assertEqual(results[0]['content'], 'Description') + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "result": { + "items": [ + { + "title": "Title", + "score": 9999, + "url": "http://www.url.xyz", + "source": "...", + "media": "http://image.jpg", + "desc": "", + "thumbnail": "http://thumbnail.jpg", + "date": "", + "_id": "db0aadd62c2a8565567ffc382f5c61fa", + "favicon": "https://s.qwant.com/fav.ico" + } + ], + "filters": [] + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + qwant.categories = ['images'] + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://www.url.xyz') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['thumbnail_src'], 'http://thumbnail.jpg') + self.assertEqual(results[0]['img_src'], 'http://image.jpg') + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "result": { + "items": [ + { + "title": "Title", + "score": 9999, + "url": "http://www.url.xyz", + "source": "...", + "desc": "Description", + "date": 1433260920, + "_id": "db0aadd62c2a8565567ffc382f5c61fa", + "favicon": "https://s.qwant.com/fav.ico" + } + ], + "filters": [] + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + qwant.categories = ['news'] + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://www.url.xyz') + self.assertEqual(results[0]['content'], 'Description') + self.assertIn('publishedDate', results[0]) + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "result": { + "items": [ + { + "title": "Title", + "score": 9999, + "url": "http://www.url.xyz", + "source": "...", + "desc": "Description", + "date": 1433260920, + "_id": "db0aadd62c2a8565567ffc382f5c61fa", + "favicon": "https://s.qwant.com/fav.ico" + } + ], + "filters": [] + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + qwant.categories = ['social media'] + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://www.url.xyz') + self.assertEqual(results[0]['content'], 'Description') + self.assertIn('publishedDate', results[0]) + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "result": { + "items": [ + { + "title": "Title", + "score": 9999, + "url": "http://www.url.xyz", + "source": "...", + "desc": "Description", + "date": 1433260920, + "_id": "db0aadd62c2a8565567ffc382f5c61fa", + "favicon": "https://s.qwant.com/fav.ico" + } + ], + "filters": [] + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + qwant.categories = [''] + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "result": { + "filters": [] + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "status": "success", + "data": { + "query": { + "locale": "en_us", + "query": "Test", + "offset": 10 + }, + "cache": { + "key": "e66aa864c00147a0e3a16ff7a5efafde", + "created": 1433092754, + "expiration": 259200, + "status": "miss", + "age": 0 + } + } + } + """ + response = mock.Mock(text=json) + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "status": "success" + } + """ + response = mock.Mock(text=json) + results = qwant.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_searchcode_code.py b/tests/unit/engines/test_searchcode_code.py new file mode 100644 index 000000000..c0ac2025c --- /dev/null +++ b/tests/unit/engines/test_searchcode_code.py @@ -0,0 +1,75 @@ +from collections import defaultdict +import mock +from searx.engines import searchcode_code +from searx.testing import SearxTestCase + + +class TestSearchcodeCodeEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = searchcode_code.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('searchcode.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, searchcode_code.response, None) + self.assertRaises(AttributeError, searchcode_code.response, []) + self.assertRaises(AttributeError, searchcode_code.response, '') + self.assertRaises(AttributeError, searchcode_code.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(searchcode_code.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(searchcode_code.response(response), []) + + json = """ + { + "matchterm": "test", + "previouspage": null, + "searchterm": "test", + "query": "test", + "total": 1000, + "page": 0, + "nextpage": 1, + "results": [ + { + "repo": "https://repo", + "linescount": 1044, + "location": "/tests", + "name": "Name", + "url": "https://url", + "md5hash": "ecac6e479edd2b9406c9e08603cec655", + "lines": { + "1": "// Test 011", + "2": "// Source: " + }, + "id": 51223527, + "filename": "File.CPP" + } + ] + } + """ + response = mock.Mock(text=json) + results = searchcode_code.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Name - File.CPP') + self.assertEqual(results[0]['url'], 'https://url') + self.assertEqual(results[0]['repository'], 'https://repo') + self.assertEqual(results[0]['code_language'], 'cpp') + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.searchcode_code.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = searchcode_code.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_searchcode_doc.py b/tests/unit/engines/test_searchcode_doc.py new file mode 100644 index 000000000..b9dcf380b --- /dev/null +++ b/tests/unit/engines/test_searchcode_doc.py @@ -0,0 +1,73 @@ +from collections import defaultdict +import mock +from searx.engines import searchcode_doc +from searx.testing import SearxTestCase + + +class TestSearchcodeDocEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = searchcode_doc.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('searchcode.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, searchcode_doc.response, None) + self.assertRaises(AttributeError, searchcode_doc.response, []) + self.assertRaises(AttributeError, searchcode_doc.response, '') + self.assertRaises(AttributeError, searchcode_doc.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(searchcode_doc.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(searchcode_doc.response(response), []) + + json = """ + { + "matchterm": "test", + "previouspage": null, + "searchterm": "test", + "query": "test", + "total": 60, + "page": 0, + "nextpage": 1, + "results": [ + { + "synopsis": "Synopsis", + "displayname": null, + "name": "test", + "url": "http://url", + "type": "Type", + "icon": null, + "namespace": "Namespace", + "description": "Description" + } + ] + } + """ + response = mock.Mock(text=json) + results = searchcode_doc.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], '[Type] Namespace test') + self.assertEqual(results[0]['url'], 'http://url') + self.assertIn('Synopsis', results[0]['content']) + self.assertIn('Type', results[0]['content']) + self.assertIn('test', results[0]['content']) + self.assertIn('Description', results[0]['content']) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.searchcode_doc.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = searchcode_doc.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_soundcloud.py b/tests/unit/engines/test_soundcloud.py new file mode 100644 index 000000000..85495dc57 --- /dev/null +++ b/tests/unit/engines/test_soundcloud.py @@ -0,0 +1,192 @@ +from collections import defaultdict +import mock +from searx.engines import soundcloud +from searx.testing import SearxTestCase +from urllib import quote_plus + + +class TestSoundcloudEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = soundcloud.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('soundcloud.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, soundcloud.response, None) + self.assertRaises(AttributeError, soundcloud.response, []) + self.assertRaises(AttributeError, soundcloud.response, '') + self.assertRaises(AttributeError, soundcloud.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(soundcloud.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(soundcloud.response(response), []) + + json = """ + { + "collection": [ + { + "kind": "track", + "id": 159723640, + "created_at": "2014/07/22 00:51:21 +0000", + "user_id": 2976616, + "duration": 303780, + "commentable": true, + "state": "finished", + "original_content_size": 13236349, + "last_modified": "2015/01/31 15:14:50 +0000", + "sharing": "public", + "tag_list": "seekae flume", + "permalink": "seekae-test-recognise-flume-re-work", + "streamable": true, + "embeddable_by": "all", + "downloadable": true, + "purchase_url": "http://www.facebook.com/seekaemusic", + "label_id": null, + "purchase_title": "Seekae", + "genre": "freedownload", + "title": "This is the title", + "description": "This is the content", + "label_name": "Future Classic", + "release": "", + "track_type": "remix", + "key_signature": "", + "isrc": "", + "video_url": null, + "bpm": null, + "release_year": 2014, + "release_month": 7, + "release_day": 22, + "original_format": "mp3", + "license": "all-rights-reserved", + "uri": "https://api.soundcloud.com/tracks/159723640", + "user": { + "id": 2976616, + "kind": "user", + "permalink": "flume", + "username": "Flume", + "last_modified": "2014/11/24 19:21:29 +0000", + "uri": "https://api.soundcloud.com/users/2976616", + "permalink_url": "http://soundcloud.com/flume", + "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg" + }, + "permalink_url": "http://soundcloud.com/this.is.the.url", + "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg", + "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png", + "stream_url": "https://api.soundcloud.com/tracks/159723640/stream", + "download_url": "https://api.soundcloud.com/tracks/159723640/download", + "playback_count": 2190687, + "download_count": 54856, + "favoritings_count": 49061, + "comment_count": 826, + "likes_count": 49061, + "reposts_count": 15910, + "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments", + "policy": "ALLOW" + } + ], + "total_results": 375750, + "next_href": "https://api.soundcloud.com/search?&q=test", + "tx_id": "" + } + """ + response = mock.Mock(text=json) + results = soundcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'http://soundcloud.com/this.is.the.url') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertIn(quote_plus('https://api.soundcloud.com/tracks/159723640'), results[0]['embedded']) + + json = """ + { + "collection": [ + { + "kind": "user", + "id": 159723640, + "created_at": "2014/07/22 00:51:21 +0000", + "user_id": 2976616, + "duration": 303780, + "commentable": true, + "state": "finished", + "original_content_size": 13236349, + "last_modified": "2015/01/31 15:14:50 +0000", + "sharing": "public", + "tag_list": "seekae flume", + "permalink": "seekae-test-recognise-flume-re-work", + "streamable": true, + "embeddable_by": "all", + "downloadable": true, + "purchase_url": "http://www.facebook.com/seekaemusic", + "label_id": null, + "purchase_title": "Seekae", + "genre": "freedownload", + "title": "This is the title", + "description": "This is the content", + "label_name": "Future Classic", + "release": "", + "track_type": "remix", + "key_signature": "", + "isrc": "", + "video_url": null, + "bpm": null, + "release_year": 2014, + "release_month": 7, + "release_day": 22, + "original_format": "mp3", + "license": "all-rights-reserved", + "uri": "https://api.soundcloud.com/tracks/159723640", + "user": { + "id": 2976616, + "kind": "user", + "permalink": "flume", + "username": "Flume", + "last_modified": "2014/11/24 19:21:29 +0000", + "uri": "https://api.soundcloud.com/users/2976616", + "permalink_url": "http://soundcloud.com/flume", + "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg" + }, + "permalink_url": "http://soundcloud.com/this.is.the.url", + "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg", + "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png", + "stream_url": "https://api.soundcloud.com/tracks/159723640/stream", + "download_url": "https://api.soundcloud.com/tracks/159723640/download", + "playback_count": 2190687, + "download_count": 54856, + "favoritings_count": 49061, + "comment_count": 826, + "likes_count": 49061, + "reposts_count": 15910, + "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments", + "policy": "ALLOW" + } + ], + "total_results": 375750, + "next_href": "https://api.soundcloud.com/search?&q=test", + "tx_id": "" + } + """ + response = mock.Mock(text=json) + results = soundcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "collection": [], + "total_results": 375750, + "next_href": "https://api.soundcloud.com/search?&q=test", + "tx_id": "" + } + """ + response = mock.Mock(text=json) + results = soundcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_spotify.py b/tests/unit/engines/test_spotify.py new file mode 100644 index 000000000..fd274abbd --- /dev/null +++ b/tests/unit/engines/test_spotify.py @@ -0,0 +1,124 @@ +from collections import defaultdict +import mock +from searx.engines import spotify +from searx.testing import SearxTestCase + + +class TestSpotifyEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = spotify.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('spotify.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, spotify.response, None) + self.assertRaises(AttributeError, spotify.response, []) + self.assertRaises(AttributeError, spotify.response, '') + self.assertRaises(AttributeError, spotify.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(spotify.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(spotify.response(response), []) + + json = """ + { + "tracks": { + "href": "https://api.spotify.com/v1/search?query=nosfell&offset=0&limit=20&type=track", + "items": [ + { + "album": { + "album_type": "album", + "external_urls": { + "spotify": "https://open.spotify.com/album/5c9ap1PBkSGLxT3J73toxA" + }, + "href": "https://api.spotify.com/v1/albums/5c9ap1PBkSGLxT3J73toxA", + "id": "5c9ap1PBkSGLxT3J73toxA", + "name": "Album Title", + "type": "album", + "uri": "spotify:album:5c9ap1PBkSGLxT3J73toxA" + }, + "artists": [ + { + "external_urls": { + "spotify": "https://open.spotify.com/artist/0bMc6b75FfZEpQHG1jifKu" + }, + "href": "https://api.spotify.com/v1/artists/0bMc6b75FfZEpQHG1jifKu", + "id": "0bMc6b75FfZEpQHG1jifKu", + "name": "Artist Name", + "type": "artist", + "uri": "spotify:artist:0bMc6b75FfZEpQHG1jifKu" + } + ], + "disc_number": 1, + "duration_ms": 202386, + "explicit": false, + "external_ids": { + "isrc": "FRV640600067" + }, + "external_urls": { + "spotify": "https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa" + }, + "href": "https://api.spotify.com/v1/tracks/2GzvFiedqW8hgqUpWcASZa", + "id": "1000", + "is_playable": true, + "name": "Title of track", + "popularity": 6, + "preview_url": "https://p.scdn.co/mp3-preview/7b8ecda580965a066b768c2647f877e43f7b1a0a", + "track_number": 3, + "type": "track", + "uri": "spotify:track:2GzvFiedqW8hgqUpWcASZa" + } + ], + "limit": 20, + "next": "https://api.spotify.com/v1/search?query=nosfell&offset=20&limit=20&type=track", + "offset": 0, + "previous": null, + "total": 107 + } + } + """ + response = mock.Mock(text=json) + results = spotify.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of track') + self.assertEqual(results[0]['url'], 'https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa') + self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') + self.assertIn('1000', results[0]['embedded']) + + json = """ + { + "tracks": { + "href": "https://api.spotify.com/v1/search?query=nosfell&offset=0&limit=20&type=track", + "items": [ + { + "href": "https://api.spotify.com/v1/tracks/2GzvFiedqW8hgqUpWcASZa", + "id": "1000", + "is_playable": true, + "name": "Title of track", + "popularity": 6, + "preview_url": "https://p.scdn.co/mp3-preview/7b8ecda580965a066b768c2647f877e43f7b1a0a", + "track_number": 3, + "type": "album", + "uri": "spotify:track:2GzvFiedqW8hgqUpWcASZa" + } + ], + "limit": 20, + "next": "https://api.spotify.com/v1/search?query=nosfell&offset=20&limit=20&type=track", + "offset": 0, + "previous": null, + "total": 107 + } + } + """ + response = mock.Mock(text=json) + results = spotify.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_stackoverflow.py b/tests/unit/engines/test_stackoverflow.py new file mode 100644 index 000000000..18a1ff4bd --- /dev/null +++ b/tests/unit/engines/test_stackoverflow.py @@ -0,0 +1,106 @@ +from collections import defaultdict +import mock +from searx.engines import stackoverflow +from searx.testing import SearxTestCase + + +class TestStackoverflowEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = stackoverflow.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('stackoverflow.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, stackoverflow.response, None) + self.assertRaises(AttributeError, stackoverflow.response, []) + self.assertRaises(AttributeError, stackoverflow.response, '') + self.assertRaises(AttributeError, stackoverflow.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(stackoverflow.response(response), []) + + html = """ +
    +
    +
    +
    +
    +
    + 2583 +
    votes
    +
    +
    +
    +
    +
    + +
    + This is the content +
    +
    +
    +
    + answered nov 23 '09 by + hallski +
    +
    +
    + """ + response = mock.Mock(text=html) + results = stackoverflow.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://stackoverflow.com/questions/this.is.the.url') + self.assertEqual(results[0]['content'], 'This is the content') + + html = """ +
    +
    +
    +
    +
    + 2583 +
    votes
    +
    +
    +
    +
    +
    + +
    + This is the content +
    +
    +
    +
    + answered nov 23 '09 by + hallski +
    +
    + """ + response = mock.Mock(text=html) + results = stackoverflow.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_startpage.py b/tests/unit/engines/test_startpage.py new file mode 100644 index 000000000..9a1a09bc7 --- /dev/null +++ b/tests/unit/engines/test_startpage.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import startpage +from searx.testing import SearxTestCase + + +class TestStartpageEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = startpage.request(query, dicto) + self.assertIn('url', params) + self.assertIn('startpage.com', params['url']) + self.assertIn('data', params) + self.assertIn('query', params['data']) + self.assertIn(query, params['data']['query']) + self.assertIn('with_language', params['data']) + self.assertIn('lang_fr', params['data']['with_language']) + + dicto['language'] = 'all' + params = startpage.request(query, dicto) + self.assertNotIn('with_language', params['data']) + + def test_response(self): + self.assertRaises(AttributeError, startpage.response, None) + self.assertRaises(AttributeError, startpage.response, []) + self.assertRaises(AttributeError, startpage.response, '') + self.assertRaises(AttributeError, startpage.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(startpage.response(response), []) + + html = """ +
    +

    + + This should be the title + + +

    +

    + This should be the content. +

    +

    + www.speedtest.net/fr/ + + - + + Navigation avec Ixquick Proxy + + - + + Mis en surbrillance + +

    +
    + """ + response = mock.Mock(content=html) + results = startpage.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') + + html = """ +
    +

    + + This should be the title + + +

    +

    + This should be the content. +

    +

    + www.speedtest.net/fr/ + + - + + Navigation avec Ixquick Proxy + + - + + Mis en surbrillance + +

    +
    +
    +

    + +

    +

    + This should be the content. +

    +

    + www.speedtest.net/fr/ + +

    +
    + + """ + response = mock.Mock(content=html) + results = startpage.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['content'], '') diff --git a/tests/unit/engines/test_subtitleseeker.py b/tests/unit/engines/test_subtitleseeker.py new file mode 100644 index 000000000..a641601b2 --- /dev/null +++ b/tests/unit/engines/test_subtitleseeker.py @@ -0,0 +1,169 @@ +from collections import defaultdict +import mock +from searx.engines import subtitleseeker +from searx.testing import SearxTestCase + + +class TestSubtitleseekerEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = subtitleseeker.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('subtitleseeker.com' in params['url']) + + def test_response(self): + dicto = defaultdict(dict) + dicto['language'] = 'fr_FR' + response = mock.Mock(search_params=dicto) + + self.assertRaises(AttributeError, subtitleseeker.response, None) + self.assertRaises(AttributeError, subtitleseeker.response, []) + self.assertRaises(AttributeError, subtitleseeker.response, '') + self.assertRaises(AttributeError, subtitleseeker.response, '[]') + + response = mock.Mock(text='', search_params=dicto) + self.assertEqual(subtitleseeker.response(response), []) + + html = """ +
    +
    + + + This is the Title + +

    + + "Alternative Title" + +
    +
    + 1998 +
    +
    + + 1039 Subs +
    +
    + + 1 hours ago +
    +
    +
    + """ + response = mock.Mock(text=html, search_params=dicto) + results = subtitleseeker.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the Title') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/') + self.assertIn('1998', results[0]['content']) + self.assertIn('1039 Subs', results[0]['content']) + self.assertIn('Alternative Title', results[0]['content']) + + html = """ +
    + +
    + 1998 +
    +
    + + 1039 Subs +
    +
    + + 1 hours ago +
    +
    +
    + """ + dicto['language'] = 'all' + response = mock.Mock(text=html, search_params=dicto) + results = subtitleseeker.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the Title') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertIn('1998', results[0]['content']) + self.assertIn('1039 Subs', results[0]['content']) + + html = """ +
    + +
    + 1998 +
    +
    + + 1039 Subs +
    +
    + + 1 hours ago +
    +
    +
    + """ + subtitleseeker.language = 'English' + response = mock.Mock(text=html, search_params=dicto) + results = subtitleseeker.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the Title') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/') + self.assertIn('1998', results[0]['content']) + self.assertIn('1039 Subs', results[0]['content']) + + html = """ + +
    + 1998 +
    +
    + + 1039 Subs +
    +
    + + 1 hours ago +
    + """ + response = mock.Mock(text=html, search_params=dicto) + results = subtitleseeker.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_swisscows.py b/tests/unit/engines/test_swisscows.py new file mode 100644 index 000000000..3b4ce7b0f --- /dev/null +++ b/tests/unit/engines/test_swisscows.py @@ -0,0 +1,128 @@ +from collections import defaultdict +import mock +from searx.engines import swisscows +from searx.testing import SearxTestCase + + +class TestSwisscowsEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'de_DE' + params = swisscows.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('swisscows.ch' in params['url']) + self.assertTrue('uiLanguage=de' in params['url']) + self.assertTrue('region=de-DE' in params['url']) + + dicto['language'] = 'all' + params = swisscows.request(query, dicto) + self.assertTrue('uiLanguage=browser' in params['url']) + self.assertTrue('region=browser' in params['url']) + + dicto['category'] = 'images' + params = swisscows.request(query, dicto) + self.assertIn('image', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, swisscows.response, None) + self.assertRaises(AttributeError, swisscows.response, []) + self.assertRaises(AttributeError, swisscows.response, '') + self.assertRaises(AttributeError, swisscows.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(swisscows.response(response), []) + + response = mock.Mock(content='') + self.assertEqual(swisscows.response(response), []) + + html = u""" + + """ + response = mock.Mock(content=html) + results = swisscows.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 3) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') + self.assertEqual(results[1]['title'], 'Datei:This should1.svg') + self.assertEqual(results[1]['url'], 'http://de.wikipedia.org/wiki/Datei:This should1.svg') + self.assertEqual(results[1]['img_src'], 'http://ts2.mm.This/should1.png') + self.assertEqual(results[1]['template'], 'images.html') + self.assertEqual(results[2]['title'], 'Datei:This should.svg') + self.assertEqual(results[2]['url'], 'http://de.wikipedia.org/wiki/Datei:This should.svg') + self.assertEqual(results[2]['img_src'], 'http://ts2.mm.This/should.png') + self.assertEqual(results[2]['template'], 'images.html') diff --git a/tests/unit/engines/test_twitter.py b/tests/unit/engines/test_twitter.py new file mode 100644 index 000000000..b444b48ee --- /dev/null +++ b/tests/unit/engines/test_twitter.py @@ -0,0 +1,502 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import twitter +from searx.testing import SearxTestCase + + +class TestTwitterEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = twitter.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('twitter.com', params['url']) + self.assertIn('cookies', params) + self.assertIn('lang', params['cookies']) + self.assertIn('fr', params['cookies']['lang']) + + dicto['language'] = 'all' + params = twitter.request(query, dicto) + self.assertIn('cookies', params) + self.assertIn('lang', params['cookies']) + self.assertIn('en', params['cookies']['lang']) + + def test_response(self): + self.assertRaises(AttributeError, twitter.response, None) + self.assertRaises(AttributeError, twitter.response, []) + self.assertRaises(AttributeError, twitter.response, '') + self.assertRaises(AttributeError, twitter.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(twitter.response(response), []) + + html = """ +
  • +
    +
    +
    +
    + +

    + This is the content étude à€ + + +

    +
    +
    + +
    +
    +
  • + """ + response = mock.Mock(text=html) + results = twitter.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], '@TitleName') + self.assertEqual(results[0]['url'], 'https://twitter.com/this.is.the.url') + self.assertIn(u'This is the content', results[0]['content']) + # self.assertIn(u'This is the content étude à€', results[0]['content']) + + html = """ +
  • +
    +
    +
    +
    + +

    + This is the content étude à€ + + +

    +
    +
    + +
    +
    +
  • + """ + response = mock.Mock(text=html) + results = twitter.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], '@TitleName') + self.assertEqual(results[0]['url'], 'https://twitter.com/this.is.the.url') + self.assertIn(u'This is the content', results[0]['content']) + + html = """ +
  • +
    + +
    + + this.meta.com + + + + +
    +

    + This should be the content.

    +
    +
  • + """ + response = mock.Mock(text=html) + results = twitter.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_vimeo.py b/tests/unit/engines/test_vimeo.py new file mode 100644 index 000000000..50b1cb563 --- /dev/null +++ b/tests/unit/engines/test_vimeo.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import vimeo +from searx.testing import SearxTestCase + + +class TestVimeoEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = vimeo.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('vimeo.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, vimeo.response, None) + self.assertRaises(AttributeError, vimeo.response, []) + self.assertRaises(AttributeError, vimeo.response, '') + self.assertRaises(AttributeError, vimeo.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(vimeo.response(response), []) + + html = """ + + """ + response = mock.Mock(text=html) + results = vimeo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://vimeo.com/videoid') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['thumbnail'], 'http://image.url.webp') + self.assertIn('/videoid', results[0]['embedded']) + + html = """ +
      +
    1. + + +
      +

      + This is the title +

      +

      + +

      +
      +
      +
    2. +
    + """ + response = mock.Mock(text=html) + results = vimeo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_www1x.py b/tests/unit/engines/test_www1x.py new file mode 100644 index 000000000..9df8de6bf --- /dev/null +++ b/tests/unit/engines/test_www1x.py @@ -0,0 +1,57 @@ +from collections import defaultdict +import mock +from searx.engines import www1x +from searx.testing import SearxTestCase + + +class TestWww1xEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + params = www1x.request(query, defaultdict(dict)) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('1x.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, www1x.response, None) + self.assertRaises(AttributeError, www1x.response, []) + self.assertRaises(AttributeError, www1x.response, '') + self.assertRaises(AttributeError, www1x.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(www1x.response(response), []) + html = """ + + + + + + + ] + > + + +
    Photos
    +
    + + + + + + +
    + + + ]]>
    + """ + response = mock.Mock(text=html) + results = www1x.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['url'], 'https://1x.com/photo/123456') + self.assertEqual(results[0]['thumbnail_src'], 'https://1x.com/images/user/testimage-123456.jpg') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['template'], 'images.html') diff --git a/tests/unit/engines/test_www500px.py b/tests/unit/engines/test_www500px.py new file mode 100644 index 000000000..8df15b945 --- /dev/null +++ b/tests/unit/engines/test_www500px.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import www500px +from searx.testing import SearxTestCase + + +class TestWww500pxImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = www500px.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('500px.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, www500px.response, None) + self.assertRaises(AttributeError, www500px.response, []) + self.assertRaises(AttributeError, www500px.response, '') + self.assertRaises(AttributeError, www500px.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(www500px.response(response), []) + + html = """ + + """ + response = mock.Mock(text=html) + results = www500px.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://500px.com/this.should.be.the.url') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertEqual(results[0]['thumbnail_src'], 'https://image.url/3.jpg?v=0') + self.assertEqual(results[0]['img_src'], 'https://image.url/2048.jpg') + + html = """ + + + + + """ + response = mock.Mock(text=html) + results = www500px.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_yacy.py b/tests/unit/engines/test_yacy.py new file mode 100644 index 000000000..f49532cf4 --- /dev/null +++ b/tests/unit/engines/test_yacy.py @@ -0,0 +1,96 @@ +from collections import defaultdict +import mock +from searx.engines import yacy +from searx.testing import SearxTestCase + + +class TestYacyEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = yacy.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('localhost', params['url']) + self.assertIn('fr', params['url']) + + dicto['language'] = 'all' + params = yacy.request(query, dicto) + self.assertIn('url', params) + self.assertNotIn('lr=lang_', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, yacy.response, None) + self.assertRaises(AttributeError, yacy.response, []) + self.assertRaises(AttributeError, yacy.response, '') + self.assertRaises(AttributeError, yacy.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(yacy.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(yacy.response(response), []) + + json = """ + { + "channels": [ + { + "title": "YaCy P2P-Search for test", + "description": "Search for test", + "link": "http://search.yacy.de:7001/yacysearch.html?query=test&resource=global&contentdom=0", + "image": { + "url": "http://search.yacy.de:7001/env/grafics/yacy.png", + "title": "Search for test", + "link": "http://search.yacy.de:7001/yacysearch.html?query=test&resource=global&contentdom=0" + }, + "totalResults": "249", + "startIndex": "0", + "itemsPerPage": "5", + "searchTerms": "test", + "items": [ + { + "title": "This is the title", + "link": "http://this.is.the.url", + "code": "", + "description": "This should be the content", + "pubDate": "Sat, 08 Jun 2013 02:00:00 +0200", + "size": "44213", + "sizename": "43 kbyte", + "guid": "lzh_1T_5FP-A", + "faviconCode": "XTS4uQ_5FP-A", + "host": "www.gamestar.de", + "path": "/spiele/city-of-heroes-freedom/47019.html", + "file": "47019.html", + "urlhash": "lzh_1T_5FP-A", + "ranking": "0.20106804" + }, + { + "title": "This is the title2", + "icon": "/ViewImage.png?maxwidth=96&maxheight=96&code=7EbAbW6BpPOA", + "image": "http://image.url/image.png", + "cache": "/ViewImage.png?quadratic=&url=http://golem.ivwbox.de/cgi-bin/ivw/CP/G_INET?d=14071378", + "url": "http://this.is.the.url", + "urlhash": "7EbAbW6BpPOA", + "host": "www.golem.de", + "width": "-1", + "height": "-1" + } + ] + } + ] + } + """ + response = mock.Mock(text=json) + results = yacy.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'http://this.is.the.url') + self.assertEqual(results[0]['content'], 'This should be the content') + self.assertEqual(results[1]['img_src'], 'http://image.url/image.png') + self.assertEqual(results[1]['content'], '') + self.assertEqual(results[1]['url'], 'http://this.is.the.url') + self.assertEqual(results[1]['title'], 'This is the title2') diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py new file mode 100644 index 000000000..11ef9db22 --- /dev/null +++ b/tests/unit/engines/test_yahoo.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import yahoo +from searx.testing import SearxTestCase + + +class TestYahooEngine(SearxTestCase): + + def test_parse_url(self): + test_url = 'http://r.search.yahoo.com/_ylt=A0LEb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\ + '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=' +\ + 'dtcJsfP4mEeBOjnVfUQ-' + url = yahoo.parse_url(test_url) + self.assertEqual('https://this.is.the.url/', url) + + test_url = 'http://r.search.yahoo.com/_ylt=A0LElb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\ + '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RS=' +\ + 'dtcJsfP4mEeBOjnVfUQ-' + url = yahoo.parse_url(test_url) + self.assertEqual('https://this.is.the.url/', url) + + test_url = 'https://this.is.the.url/' + url = yahoo.parse_url(test_url) + self.assertEqual('https://this.is.the.url/', url) + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = yahoo.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('search.yahoo.com', params['url']) + self.assertIn('fr', params['url']) + self.assertIn('cookies', params) + self.assertIn('sB', params['cookies']) + self.assertIn('fr', params['cookies']['sB']) + + dicto['language'] = 'all' + params = yahoo.request(query, dicto) + self.assertIn('cookies', params) + self.assertIn('sB', params['cookies']) + self.assertIn('en', params['cookies']['sB']) + self.assertIn('en', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, yahoo.response, None) + self.assertRaises(AttributeError, yahoo.response, []) + self.assertRaises(AttributeError, yahoo.response, '') + self.assertRaises(AttributeError, yahoo.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(yahoo.response(response), []) + + html = """ +
      +
    1. +
      + +
      +

      This is the content +

      +
      +
      +
    2. +
    3. +
      +
      +
      +
      +

      This is the second content

      +
      +
      +
    4. +
    +
    +
    +

    Also Try

    + + + + + +
    This is the suggestion +
    +
    + """ + response = mock.Mock(text=html) + results = yahoo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertEqual(results[1]['suggestion'], 'This is the suggestion') + + html = """ +
      +
    1. +
      + +
      +

      This is the content +

      +
      +
      +
    2. +
    + """ + response = mock.Mock(text=html) + results = yahoo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + + html = """ +
  • +
  • + """ + response = mock.Mock(text=html) + results = yahoo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_yahoo_news.py b/tests/unit/engines/test_yahoo_news.py new file mode 100644 index 000000000..4d7fc0a10 --- /dev/null +++ b/tests/unit/engines/test_yahoo_news.py @@ -0,0 +1,149 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +from datetime import datetime +import mock +from searx.engines import yahoo_news +from searx.testing import SearxTestCase + + +class TestYahooNewsEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = yahoo_news.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('news.search.yahoo.com', params['url']) + self.assertIn('fr', params['url']) + self.assertIn('cookies', params) + self.assertIn('sB', params['cookies']) + self.assertIn('fr', params['cookies']['sB']) + + dicto['language'] = 'all' + params = yahoo_news.request(query, dicto) + self.assertIn('cookies', params) + self.assertIn('sB', params['cookies']) + self.assertIn('en', params['cookies']['sB']) + self.assertIn('en', params['url']) + + def test_sanitize_url(self): + url = "test.url" + self.assertEqual(url, yahoo_news.sanitize_url(url)) + + url = "www.yahoo.com/;_ylt=test" + self.assertEqual("www.yahoo.com/", yahoo_news.sanitize_url(url)) + + def test_response(self): + self.assertRaises(AttributeError, yahoo_news.response, None) + self.assertRaises(AttributeError, yahoo_news.response, []) + self.assertRaises(AttributeError, yahoo_news.response, '') + self.assertRaises(AttributeError, yahoo_news.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(yahoo_news.response(response), []) + + html = """ +
      +
    1. + +
      + Business via Yahoo! + May 01 10:00 AM +
      +
      + This is the content +
      +
    2. +
    3. +
      +

      + + +

      +
      +
      +
      +
    4. +
    + """ + response = mock.Mock(text=html) + results = yahoo_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title...') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + + html = """ +
      +
    1. + +
      + Business via Yahoo! + 2 hours, 22 minutes ago +
      +
      + This is the content +
      +
    2. +
    3. + +
      + Business via Yahoo! + 22 minutes ago +
      +
      + This is the content +
      +
    4. +
    5. + +
      + Business via Yahoo! + Feb 03 09:45AM 1900 +
      +
      + This is the content +
      +
    6. +
    + """ + response = mock.Mock(text=html) + results = yahoo_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 3) + self.assertEqual(results[0]['title'], 'This is the title...') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertEqual(results[2]['publishedDate'].year, datetime.now().year) diff --git a/tests/unit/engines/test_youtube_api.py b/tests/unit/engines/test_youtube_api.py new file mode 100644 index 000000000..0d4d478c3 --- /dev/null +++ b/tests/unit/engines/test_youtube_api.py @@ -0,0 +1,111 @@ +from collections import defaultdict +import mock +from searx.engines import youtube_api +from searx.testing import SearxTestCase + + +class TestYoutubeAPIEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = youtube_api.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertIn('googleapis.com', params['url']) + self.assertIn('youtube', params['url']) + self.assertIn('fr', params['url']) + + dicto['language'] = 'all' + params = youtube_api.request(query, dicto) + self.assertFalse('fr' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, youtube_api.response, None) + self.assertRaises(AttributeError, youtube_api.response, []) + self.assertRaises(AttributeError, youtube_api.response, '') + self.assertRaises(AttributeError, youtube_api.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(youtube_api.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(youtube_api.response(response), []) + + json = """ + { + "kind": "youtube#searchListResponse", + "etag": "xmg9xJZuZD438sF4hb-VcBBREXc/YJQDcTBCDcaBvl-sRZJoXdvy1ME", + "nextPageToken": "CAUQAA", + "pageInfo": { + "totalResults": 1000000, + "resultsPerPage": 20 + }, + "items": [ + { + "kind": "youtube#searchResult", + "etag": "xmg9xJZuZD438sF4hb-VcBBREXc/IbLO64BMhbHIgWLwLw7MDYe7Hs4", + "id": { + "kind": "youtube#video", + "videoId": "DIVZCPfAOeM" + }, + "snippet": { + "publishedAt": "2015-05-29T22:41:04.000Z", + "channelId": "UCNodmx1ERIjKqvcJLtdzH5Q", + "title": "Title", + "description": "Description", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/DIVZCPfAOeM/default.jpg" + }, + "medium": { + "url": "https://i.ytimg.com/vi/DIVZCPfAOeM/mqdefault.jpg" + }, + "high": { + "url": "https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg" + } + }, + "channelTitle": "MinecraftUniverse", + "liveBroadcastContent": "none" + } + } + ] + } + """ + response = mock.Mock(text=json) + results = youtube_api.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM') + self.assertEqual(results[0]['content'], 'Description') + self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg') + self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) + + json = """ + { + "kind": "youtube#searchListResponse", + "etag": "xmg9xJZuZD438sF4hb-VcBBREXc/YJQDcTBCDcaBvl-sRZJoXdvy1ME", + "nextPageToken": "CAUQAA", + "pageInfo": { + "totalResults": 1000000, + "resultsPerPage": 20 + } + } + """ + response = mock.Mock(text=json) + results = youtube_api.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + {"toto":{"entry":[] + } + } + """ + response = mock.Mock(text=json) + results = youtube_api.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_youtube_noapi.py b/tests/unit/engines/test_youtube_noapi.py new file mode 100644 index 000000000..9fa8fd20e --- /dev/null +++ b/tests/unit/engines/test_youtube_noapi.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import youtube_noapi +from searx.testing import SearxTestCase + + +class TestYoutubeNoAPIEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = youtube_noapi.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('youtube.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, youtube_noapi.response, None) + self.assertRaises(AttributeError, youtube_noapi.response, []) + self.assertRaises(AttributeError, youtube_noapi.response, '') + self.assertRaises(AttributeError, youtube_noapi.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(youtube_noapi.response(response), []) + + html = """ +
      +
    1. +
      +
      + + + +
      +
      +

      + + Title + + - Durée : 11:35. +

      +
      +
        +
      • il y a 20 heures
      • +
      • 8 424 vues
      • +
      +
      +
      + Description +
      +
      +
        +
      • + Nouveauté +
      • +
      • HD
      • +
      +
      +
      +
      +
      +
      +
      +
      +
      +
    2. +
    + """ + response = mock.Mock(text=html) + results = youtube_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM') + self.assertEqual(results[0]['content'], 'Description') + self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg') + self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) + + html = """ +
      +
    1. +
      +
      + + + +
      +
      +

      + - Durée : 11:35. +

      +
      +
        +
      • il y a 20 heures
      • +
      • 8 424 vues
      • +
      +
      +
      +
        +
      • + Nouveauté +
      • +
      • HD
      • +
      +
      +
      +
      +
      +
      +
      +
      +
      +
    2. +
    + """ + response = mock.Mock(text=html) + results = youtube_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + + html = """ +
      +
    1. +
    2. +
    + """ + response = mock.Mock(text=html) + results = youtube_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/tests/unit/test_plugins.py b/tests/unit/test_plugins.py new file mode 100644 index 000000000..98d39ec14 --- /dev/null +++ b/tests/unit/test_plugins.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +from searx.testing import SearxTestCase +from searx import plugins +from mock import Mock + + +def get_search_mock(query, **kwargs): + return {'search': Mock(query=query, + result_container=Mock(answers=set()), + **kwargs)} + + +class PluginStoreTest(SearxTestCase): + + def test_PluginStore_init(self): + store = plugins.PluginStore() + self.assertTrue(isinstance(store.plugins, list) and len(store.plugins) == 0) + + def test_PluginStore_register(self): + store = plugins.PluginStore() + testplugin = plugins.Plugin() + store.register(testplugin) + + self.assertTrue(len(store.plugins) == 1) + + def test_PluginStore_call(self): + store = plugins.PluginStore() + testplugin = plugins.Plugin() + store.register(testplugin) + setattr(testplugin, 'asdf', Mock()) + request = Mock(user_plugins=[]) + store.call('asdf', request, Mock()) + + self.assertFalse(testplugin.asdf.called) + + request.user_plugins.append(testplugin) + store.call('asdf', request, Mock()) + + self.assertTrue(testplugin.asdf.called) + + +class SelfIPTest(SearxTestCase): + + def test_PluginStore_init(self): + store = plugins.PluginStore() + store.register(plugins.self_info) + + self.assertTrue(len(store.plugins) == 1) + + # IP test + request = Mock(user_plugins=store.plugins, + remote_addr='127.0.0.1') + request.headers.getlist.return_value = [] + ctx = get_search_mock(query='ip') + store.call('post_search', request, ctx) + self.assertTrue('127.0.0.1' in ctx['search'].result_container.answers) + + # User agent test + request = Mock(user_plugins=store.plugins, + user_agent='Mock') + request.headers.getlist.return_value = [] + + ctx = get_search_mock(query='user-agent') + store.call('post_search', request, ctx) + self.assertTrue('Mock' in ctx['search'].result_container.answers) + + ctx = get_search_mock(query='user-agent') + store.call('post_search', request, ctx) + self.assertTrue('Mock' in ctx['search'].result_container.answers) + + ctx = get_search_mock(query='What is my User-Agent?') + store.call('post_search', request, ctx) + self.assertTrue('Mock' in ctx['search'].result_container.answers) diff --git a/tests/unit/test_results.py b/tests/unit/test_results.py new file mode 100644 index 000000000..274b5b37a --- /dev/null +++ b/tests/unit/test_results.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +from searx.results import ResultContainer +from searx.testing import SearxTestCase + + +def fake_result(url='https://aa.bb/cc?dd=ee#ff', + title='aaa', + content='bbb', + engine='wikipedia', **kwargs): + result = {'url': url, + 'title': title, + 'content': content, + 'engine': engine} + result.update(kwargs) + return result + + +# TODO +class ResultContainerTestCase(SearxTestCase): + + def test_empty(self): + c = ResultContainer() + self.assertEqual(c.get_ordered_results(), []) + + def test_one_result(self): + c = ResultContainer() + c.extend('wikipedia', [fake_result()]) + self.assertEqual(c.results_length(), 1) + + def test_one_suggestion(self): + c = ResultContainer() + c.extend('wikipedia', [fake_result(suggestion=True)]) + self.assertEqual(len(c.suggestions), 1) + self.assertEqual(c.results_length(), 0) + + def test_result_merge(self): + c = ResultContainer() + c.extend('wikipedia', [fake_result()]) + c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')]) + self.assertEqual(c.results_length(), 2) diff --git a/tests/unit/test_search.py b/tests/unit/test_search.py new file mode 100644 index 000000000..af5fffd8b --- /dev/null +++ b/tests/unit/test_search.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +from searx.testing import SearxTestCase + + +# TODO +class SearchTestCase(SearxTestCase): + + def test_(self): + pass diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py new file mode 100644 index 000000000..04480791d --- /dev/null +++ b/tests/unit/test_utils.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +import mock +from searx.testing import SearxTestCase +from searx import utils + + +class TestUtils(SearxTestCase): + + def test_gen_useragent(self): + self.assertIsInstance(utils.gen_useragent(), str) + self.assertIsNotNone(utils.gen_useragent()) + self.assertTrue(utils.gen_useragent().startswith('Mozilla')) + + def test_searx_useragent(self): + self.assertIsInstance(utils.searx_useragent(), str) + self.assertIsNotNone(utils.searx_useragent()) + self.assertTrue(utils.searx_useragent().startswith('searx')) + + def test_highlight_content(self): + self.assertEqual(utils.highlight_content(0, None), None) + self.assertEqual(utils.highlight_content(None, None), None) + self.assertEqual(utils.highlight_content('', None), None) + self.assertEqual(utils.highlight_content(False, None), None) + + contents = [ + '' + 'not<' + ] + for content in contents: + self.assertEqual(utils.highlight_content(content, None), content) + + content = 'a' + query = 'test' + self.assertEqual(utils.highlight_content(content, query), content) + query = 'a test' + self.assertEqual(utils.highlight_content(content, query), content) + + def test_html_to_text(self): + html = """ + + """ + self.assertIsInstance(utils.html_to_text(html), unicode) + self.assertIsNotNone(utils.html_to_text(html)) + self.assertEqual(utils.html_to_text(html), "Test text") + + def test_prettify_url(self): + data = (('https://searx.me/', 'https://searx.me/'), + (u'https://searx.me/ű', u'https://searx.me/ű'), + ('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'), + (u'https://searx.me/' + (100 * u'ű'), u'https://searx.me/[...]űűűűűűűűűűűűűűűűű')) + + for test_url, expected in data: + self.assertEqual(utils.prettify_url(test_url, max_length=32), expected) + + +class TestHTMLTextExtractor(SearxTestCase): + + def setUp(self): + self.html_text_extractor = utils.HTMLTextExtractor() + + def test__init__(self): + self.assertEqual(self.html_text_extractor.result, []) + + def test_handle_charref(self): + self.html_text_extractor.handle_charref('xF') + self.assertIn(u'\x0f', self.html_text_extractor.result) + self.html_text_extractor.handle_charref('XF') + self.assertIn(u'\x0f', self.html_text_extractor.result) + + self.html_text_extractor.handle_charref('97') + self.assertIn(u'a', self.html_text_extractor.result) + + def test_handle_entityref(self): + entity = 'test' + self.html_text_extractor.handle_entityref(entity) + self.assertIn(entity, self.html_text_extractor.result) + + +class TestUnicodeWriter(SearxTestCase): + + def setUp(self): + self.unicode_writer = utils.UnicodeWriter(mock.MagicMock()) + + def test_write_row(self): + row = [1, 2, 3] + self.assertEqual(self.unicode_writer.writerow(row), None) + + def test_write_rows(self): + self.unicode_writer.writerow = mock.MagicMock() + rows = [1, 2, 3] + self.unicode_writer.writerows(rows) + self.assertEqual(self.unicode_writer.writerow.call_count, len(rows)) diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py new file mode 100644 index 000000000..071c01df3 --- /dev/null +++ b/tests/unit/test_webapp.py @@ -0,0 +1,151 @@ +# -*- coding: utf-8 -*- + +import json +from mock import Mock +from urlparse import ParseResult +from searx import webapp +from searx.testing import SearxTestCase + + +class ViewsTestCase(SearxTestCase): + + def setUp(self): + webapp.app.config['TESTING'] = True # to get better error messages + self.app = webapp.app.test_client() + webapp.default_theme = 'default' + + # set some defaults + self.test_results = [ + { + 'content': 'first test content', + 'title': 'First Test', + 'url': 'http://first.test.xyz', + 'engines': ['youtube', 'startpage'], + 'engine': 'startpage', + 'parsed_url': ParseResult(scheme='http', netloc='first.test.xyz', path='/', params='', query='', fragment=''), # noqa + }, { + 'content': 'second test content', + 'title': 'Second Test', + 'url': 'http://second.test.xyz', + 'engines': ['youtube', 'startpage'], + 'engine': 'youtube', + 'parsed_url': ParseResult(scheme='http', netloc='second.test.xyz', path='/', params='', query='', fragment=''), # noqa + }, + ] + + def search_mock(search_self, *args): + search_self.result_container = Mock(get_ordered_results=lambda: self.test_results, + answers=set(), + suggestions=set(), + infoboxes=[], + results=self.test_results, + results_length=lambda: len(self.test_results)) + + webapp.Search.search = search_mock + + self.maxDiff = None # to see full diffs + + def test_index_empty(self): + result = self.app.post('/') + self.assertEqual(result.status_code, 200) + self.assertIn('

    searx

    ', result.data) + + def test_index_html(self): + result = self.app.post('/', data={'q': 'test'}) + self.assertIn( + '

    youtubeSecond Test

    ', # noqa + result.data + ) + self.assertIn( + '

    first test content

    ', # noqa + result.data + ) + + def test_index_json(self): + result = self.app.post('/', data={'q': 'test', 'format': 'json'}) + + result_dict = json.loads(result.data) + + self.assertEqual('test', result_dict['query']) + self.assertEqual( + result_dict['results'][0]['content'], 'first test content') + self.assertEqual( + result_dict['results'][0]['url'], 'http://first.test.xyz') + + def test_index_csv(self): + result = self.app.post('/', data={'q': 'test', 'format': 'csv'}) + + self.assertEqual( + 'title,url,content,host,engine,score\r\n' + 'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa + 'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa + result.data + ) + + def test_index_rss(self): + result = self.app.post('/', data={'q': 'test', 'format': 'rss'}) + + self.assertIn( + 'Search results for "test" - searx', + result.data + ) + + self.assertIn( + '2', + result.data + ) + + self.assertIn( + 'First Test', + result.data + ) + + self.assertIn( + 'http://first.test.xyz', + result.data + ) + + self.assertIn( + 'first test content', + result.data + ) + + def test_about(self): + result = self.app.get('/about') + self.assertEqual(result.status_code, 200) + self.assertIn('

    About searx

    ', result.data) + + def test_preferences(self): + result = self.app.get('/preferences') + self.assertEqual(result.status_code, 200) + self.assertIn( + '', + result.data + ) + self.assertIn( + 'Default categories', + result.data + ) + self.assertIn( + 'Interface language', + result.data + ) + + def test_stats(self): + result = self.app.get('/stats') + self.assertEqual(result.status_code, 200) + self.assertIn('

    Engine stats

    ', result.data) + + def test_robots_txt(self): + result = self.app.get('/robots.txt') + self.assertEqual(result.status_code, 200) + self.assertIn('Allow: /', result.data) + + def test_opensearch_xml(self): + result = self.app.get('/opensearch.xml') + self.assertEqual(result.status_code, 200) + self.assertIn('a privacy-respecting, hackable metasearch engine', result.data) + + def test_favicon(self): + result = self.app.get('/favicon.ico') + self.assertEqual(result.status_code, 200) diff --git a/versions.cfg b/versions.cfg deleted file mode 100644 index 2cb86aba1..000000000 --- a/versions.cfg +++ /dev/null @@ -1,122 +0,0 @@ -[versions] -Babel = 1.3 -Flask = 0.10.1 -Flask-Babel = 0.9 -Jinja2 = 2.7.3 -MarkupSafe = 0.23 -Pygments = 2.0.2 -WebOb = 1.4.1 -WebTest = 2.0.18 -Werkzeug = 0.10.4 -collective.recipe.omelette = 0.16 -coverage = 3.7.1 -decorator = 3.4.2 -docutils = 0.12 -flake8 = 2.4.1 -itsdangerous = 0.24 -mccabe = 0.3.1 -mock = 1.0.1 -pep8 = 1.5.7 -plone.testing = 4.0.13 -pyflakes = 0.8.1 -pytz = 2015.4 -pyyaml = 3.11 -requests = 2.7.0 -robotframework-debuglibrary = 0.3 -robotframework-httplibrary = 0.4.2 -robotframework-selenium2library = 1.7.1 -robotsuite = 1.6.1 -selenium = 2.46.0 -speaklater = 1.3 -unittest2 = 1.0.1 -waitress = 0.8.9 -zc.recipe.testrunner = 2.0.0 -pyopenssl = 0.15.1 -ndg-httpsclient = 0.4.0 -pyasn1 = 0.1.8 -pyasn1-modules = 0.0.6 -certifi = 2015.11.20.1 - -cffi = 1.1.2 -cryptography = 0.9.1 - -# Required by: -# robotsuite==1.6.1 -# searx==0.7.0 -lxml = 3.4.4 - -# Required by: -# searx==0.7.0 -python-dateutil = 2.4.2 - -# Required by: -# searx==0.7.0 -# zope.exceptions==4.0.7 -# zope.interface==4.1.2 -# zope.testrunner==4.4.9 -setuptools = 18.0.1 - -# Required by: -# WebTest==2.0.18 -beautifulsoup4 = 4.3.2 - -# Required by: -# cryptography==0.9.1 -enum34 = 1.0.4 - -# Required by: -# cryptography==0.9.1 -idna = 2.0 - -# Required by: -# cryptography==0.9.1 -ipaddress = 1.0.7 - -# Required by: -# robotframework-httplibrary==0.4.2 -jsonpatch = 1.11 - -# Required by: -# robotframework-httplibrary==0.4.2 -jsonpointer = 1.9 - -# Required by: -# traceback2==1.4.0 -linecache2 = 1.0.0 - -# Required by: -# cffi==1.1.2 -pycparser = 2.12 - -# Required by: -# robotframework-httplibrary==0.4.2 -robotframework = 2.8.7 - -# Required by: -# robotsuite==1.6.1 -# zope.testrunner==4.4.9 -six = 1.9.0 - -# Required by: -# unittest2==1.0.1 -traceback2 = 1.4.0 - -# Required by: -# collective.recipe.omelette==0.16 -zc.recipe.egg = 2.0.1 - -# Required by: -# zope.testrunner==4.4.9 -zope.exceptions = 4.0.7 - -# Required by: -# zope.testrunner==4.4.9 -zope.interface = 4.1.2 - -# Required by: -# plone.testing==4.0.13 -zope.testing = 4.2.0 - -# Required by: -# zc.recipe.testrunner==2.0.0 -zope.testrunner = 4.4.9 -- cgit v1.2.3