From 1231469a3513685263bf77f16ee81026c39b389b Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Fri, 27 Sep 2019 23:18:28 -0400 Subject: [PATCH] server/tests: integrate testing into Docker --- server/.dockerignore | 16 +++++++++++----- server/config.yaml.dist | 2 -- server/hooks/test | 23 +++++++++++++++++++++++ server/setup.cfg | 3 --- server/szurubooru/tests/conftest.py | 11 ++++------- 5 files changed, 38 insertions(+), 17 deletions(-) create mode 100755 server/hooks/test delete mode 100644 server/setup.cfg diff --git a/server/.dockerignore b/server/.dockerignore index 539365f..bdbf1d6 100644 --- a/server/.dockerignore +++ b/server/.dockerignore @@ -1,7 +1,13 @@ -**/.gitignore -.dockerignore +# Linter configs .pylintrc -Dockerfile -config.yaml mypy.ini -setup.cfg + +dev-requirements.txt + +# Docker build files +Dockerfile +.dockerignore +hooks/ + +# User configured config file +config.yaml \ No newline at end of file diff --git a/server/config.yaml.dist b/server/config.yaml.dist index 465e11a..236630d 100644 --- a/server/config.yaml.dist +++ b/server/config.yaml.dist @@ -9,8 +9,6 @@ domain: # example: http://example.com user_agent: # used to salt the users' password hashes and generate filenames for static content secret: change -# required for running the test suite -test_database: 'sqlite:///:memory:' # Delete thumbnails and source files on post delete # Original functionality is no, to mitigate the impacts of admins going diff --git a/server/hooks/test b/server/hooks/test new file mode 100755 index 0000000..e10a759 --- /dev/null +++ b/server/hooks/test @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +docker build \ + --build-arg BASE_IMAGE=${IMAGE_NAME} \ + --file - \ + --tag ${IMAGE_NAME}-test \ + . <<'EOF' +ARG BASE_IMAGE +FROM ${BASE_IMAGE} +WORKDIR /opt/app +USER root +RUN pip3 install --no-cache-dir pytest-cov freezegun +USER app +ENV POSTGRES_HOST=x \ + POSTGRES_USER=x \ + POSTGRES_PASSWORD=x \ + ESEARCH_HOST=x +CMD ["pytest", "szurubooru/", \ + "--cov-report=term-missing", "--cov=szurubooru", "--tb=short"] +EOF + +docker run --rm -t ${IMAGE_NAME}-test \ No newline at end of file diff --git a/server/setup.cfg b/server/setup.cfg deleted file mode 100644 index 7e835b4..0000000 --- a/server/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[tool:pytest] -testpaths=szurubooru -addopts=--cov-report=term-missing --cov=szurubooru --tb=short diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 27a107a..45ce88e 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -32,11 +32,8 @@ class QueryCounter: return self._statements -if not config.config['test_database']: - raise RuntimeError('Test database not configured.') - _query_counter = QueryCounter() -_engine = sa.create_engine(config.config['test_database']) +_engine = sa.create_engine('sqlite:///:memory:') model.Base.metadata.drop_all(bind=_engine) model.Base.metadata.create_all(bind=_engine) sa.event.listen( @@ -66,9 +63,9 @@ def query_counter(): return _query_counter -@pytest.fixture -def query_logger(): - if pytest.config.option.verbose > 0: +@pytest.fixture(scope='session') +def query_logger(pytestconfig): + if pytestconfig.option.verbose > 0: import logging import coloredlogs coloredlogs.install(