server/tests: integrate testing into Docker
This commit is contained in:
parent
edf9083552
commit
1231469a35
5 changed files with 38 additions and 17 deletions
|
@ -1,7 +1,13 @@
|
||||||
**/.gitignore
|
# Linter configs
|
||||||
.dockerignore
|
|
||||||
.pylintrc
|
.pylintrc
|
||||||
Dockerfile
|
|
||||||
config.yaml
|
|
||||||
mypy.ini
|
mypy.ini
|
||||||
setup.cfg
|
|
||||||
|
dev-requirements.txt
|
||||||
|
|
||||||
|
# Docker build files
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
hooks/
|
||||||
|
|
||||||
|
# User configured config file
|
||||||
|
config.yaml
|
|
@ -9,8 +9,6 @@ domain: # example: http://example.com
|
||||||
user_agent:
|
user_agent:
|
||||||
# used to salt the users' password hashes and generate filenames for static content
|
# used to salt the users' password hashes and generate filenames for static content
|
||||||
secret: change
|
secret: change
|
||||||
# required for running the test suite
|
|
||||||
test_database: 'sqlite:///:memory:'
|
|
||||||
|
|
||||||
# Delete thumbnails and source files on post delete
|
# Delete thumbnails and source files on post delete
|
||||||
# Original functionality is no, to mitigate the impacts of admins going
|
# Original functionality is no, to mitigate the impacts of admins going
|
||||||
|
|
23
server/hooks/test
Executable file
23
server/hooks/test
Executable file
|
@ -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
|
|
@ -1,3 +0,0 @@
|
||||||
[tool:pytest]
|
|
||||||
testpaths=szurubooru
|
|
||||||
addopts=--cov-report=term-missing --cov=szurubooru --tb=short
|
|
|
@ -32,11 +32,8 @@ class QueryCounter:
|
||||||
return self._statements
|
return self._statements
|
||||||
|
|
||||||
|
|
||||||
if not config.config['test_database']:
|
|
||||||
raise RuntimeError('Test database not configured.')
|
|
||||||
|
|
||||||
_query_counter = QueryCounter()
|
_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.drop_all(bind=_engine)
|
||||||
model.Base.metadata.create_all(bind=_engine)
|
model.Base.metadata.create_all(bind=_engine)
|
||||||
sa.event.listen(
|
sa.event.listen(
|
||||||
|
@ -66,9 +63,9 @@ def query_counter():
|
||||||
return _query_counter
|
return _query_counter
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(scope='session')
|
||||||
def query_logger():
|
def query_logger(pytestconfig):
|
||||||
if pytest.config.option.verbose > 0:
|
if pytestconfig.option.verbose > 0:
|
||||||
import logging
|
import logging
|
||||||
import coloredlogs
|
import coloredlogs
|
||||||
coloredlogs.install(
|
coloredlogs.install(
|
||||||
|
|
Loading…
Reference in a new issue