Commit 33079423 authored by Nicolas Gelot's avatar Nicolas Gelot

Bootstrap functional test

Before to try to optimize spot engines we need to
have some tests to bench the search duration and that
performs some checks on the results
parent cc26dde7
......@@ -21,10 +21,24 @@ coding-rules:
script:
- ./manage.sh pep8_check
unittest:
unit-test:
stage: test
before_script:
- ./manage.sh update_dev_packages
script:
- ./manage.sh unit_tests
coverage: '/TOTAL.*\s+(\d+%)$/'
functional-test:
stage: test
image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
before_script:
- docker run -id --rm -v $(pwd):/ws -e DOCKER_HOST=tcp://$(cat /etc/hosts | grep docker | cut -f1):2375/ -w /ws --name spotenv $CI_REGISTRY_IMAGE/env:latest sh
- docker exec -i spotenv ./manage.sh update_dev_packages
script:
- docker exec -i spotenv ./manage.sh functional_tests
......@@ -6,6 +6,7 @@ RUN dnf install -y\
wget\
python2-pip\
npm\
docker \
&& dnf groupinstall -y "Development Tools" \
&& pip3 install ipdb ipython \
&& pip3 install -r /requirements.txt \
......
......@@ -41,13 +41,19 @@ pep8_check() {
unit_tests() {
echo '[!] Running unit tests'
PYTHONPATH="$BASE_DIR" pytest --cov=searx --disable-pytest-warnings "$BASE_DIR/tests/unit"
PYTHONPATH="$BASE_DIR" pytest --cov=searx "$BASE_DIR/tests/unit"
}
functional_tests() {
echo '[!] Running unit tests'
PYTHONPATH="$BASE_DIR" pytest "$BASE_DIR/tests/functional"
}
tests() {
set -e
pep8_check
unit_tests
functional_tests
set +e
}
......@@ -133,8 +139,9 @@ Commands
Tests
-----
unit_tests - Run unit tests
functional_tests - Run functional tests
pep8_check - Pep8 validation
tests - Run all python tests (pep8, unit, robot_tests)
tests - Run all python tests (pep8, unit, functional)
"
}
......
[pytest]
addopts = -s --dockerc-build --dockerc-attach-network --disable-pytest-warnings
......@@ -4,3 +4,4 @@ pycodestyle==2.4.0
mockredispy==2.9.3
pytest==4.1.0
pytest-cov==2.6.1
pytest-dockerc==1.0.5
import pytest
import redis
import requests
from pytest_dockerc import Wait, Context
class SpotContext(Context):
@property
def url(self):
addr = self.container_addr("spot")
port = self.container_port("spot")
return f"http://{addr}:{port}"
def wait_for_running_state(self):
Wait(ignored_exns=(requests.ConnectionError,))(lambda: requests.get(self.url))
@pytest.fixture(scope="session")
def ctx(dockerc, dockerc_logs):
context = SpotContext(dockerc)
context.wait_for_running_state()
yield context
@pytest.fixture
def redisdb(ctx):
""" purge the db
"""
db = redis.Redis(ctx.container_addr("redis"))
for key in db.keys():
db.delete(key)
yield db
import requests
class DataReq(dict):
def __init__(self, **kwargs):
self["category"] = kwargs.get("category", "general")
self["language"] = kwargs.get("language", "en-US")
self["q"] = kwargs.get("q", "lequipe.fr")
self["time_range"] = kwargs.get("time_range", "")
self["output"] = kwargs.get("output", "json")
def test_index(ctx, redisdb):
""" Test the main endpoint to ensure that some results are returned
"""
res = requests.post(ctx.url)
assert res.status_code == 200
res = requests.post(ctx.url, data={"output": "json"})
assert res.status_code == 204
data = DataReq()
res = requests.post(ctx.url, data=data)
assert res.status_code == 200
response = res.json()
assert len(response["results"]) > 5
assert len(response["image_results"]) == 5
assert len(response['videos_results']) == 5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment