diff --git a/.gitignore b/.gitignore index c1d50dfbcf7c777ae0bcb7157b35b88353d33e31..069866285d7ac3590f58e6798612ea51b37a0734 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ backend/public # Jupyter notebook notebooks/ .ipynb_checkpoints/ + +# Tests files +.coverage diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..040d5bec22338b42a044db2a1580488fa52263f9 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,33 @@ +image: python:3.7 + +stages: + - lint_test_coverage_backend + +# Pick zero or more services to be used on all builds. +# Only needed when using a docker container to run your tests in. +# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service +services: + - postgres:latest + +variables: + POSTGRES_DB: postgres + +# This folder is cached between builds +# http://docs.gitlab.com/ce/ci/yaml/README.html#cache +cache: + paths: + - ~/.cache/pip/ + +before_script: + - cd backend + - pip install -r requirements_dev.txt + - pip install . + +test-backend: + stage: lint_test_coverage_backend + variables: + DATABASE_HOST: postgres + DJANGO_SETTINGS_MODULE: "metagenedb.settings-gitlab-ci" + script: + - flake8 --max-line-length 120 + - coverage run --source='.' scripts/manage.py test metagenedb/tests diff --git a/backend/.coveragerc b/backend/.coveragerc new file mode 100644 index 0000000000000000000000000000000000000000..1cdb108a15bc2881fb78793e291e1647ff83a93c --- /dev/null +++ b/backend/.coveragerc @@ -0,0 +1,5 @@ +[run] +omit = + metagenedb/wsgi.py + scripts/manage.py + setup.py diff --git a/backend/metagenedb/settings-gitlab-ci.py b/backend/metagenedb/settings-gitlab-ci.py new file mode 100644 index 0000000000000000000000000000000000000000..7316881b0c2bd436a0b212e76b032828e5ee63e8 --- /dev/null +++ b/backend/metagenedb/settings-gitlab-ci.py @@ -0,0 +1,12 @@ +from metagenedb.settings import * # noqa + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'ci', + 'USER': 'postgres', + 'PASSWORD': 'postgres', + 'HOST': 'postgres', + 'PORT': '5432', + }, +} diff --git a/backend/metagenedb/settings/django.py b/backend/metagenedb/settings/django.py index d238600d067cb8bcb054f8bbc51c44b3c8ba5f9b..61fc6d83144dec6dc6f61fa59b60e25ab38567f0 100644 --- a/backend/metagenedb/settings/django.py +++ b/backend/metagenedb/settings/django.py @@ -107,7 +107,7 @@ DATABASES = { 'NAME': 'postgres', 'USER': 'postgres', 'HOST': env.str('DATABASES_HOST', default='db'), - 'PORT': env.str('POSTGRES_PORT', default=5432), + 'PORT': env.int('POSTGRES_PORT', default=5432), } } @@ -118,5 +118,3 @@ STATIC_ROOT = public_root('static') STATIC_URL = env.str('STATIC_URL', default='/static/') SECRET_KEY = env.str('SECRET_KEY') - - diff --git a/backend/pytest.ini b/backend/pytest.ini new file mode 100644 index 0000000000000000000000000000000000000000..f1501096465f6d57d207ed3dbc900ad4e6569476 --- /dev/null +++ b/backend/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE = backend.settings +python_files = tests.py test_*.py *_tests.py \ No newline at end of file diff --git a/backend/requirements_dev.txt b/backend/requirements_dev.txt index ee46230ab129e2674f1665e132c28b03d3a8b82a..5e56a93721a88b4246815297e4a931470d446324 100644 --- a/backend/requirements_dev.txt +++ b/backend/requirements_dev.txt @@ -1,52 +1,27 @@ +atomicwrites==1.3.0 attrs==19.1.0 -backcall==0.1.0 -bleach==3.1.0 -decorator==4.4.0 -defusedxml==0.6.0 +coverage==4.5.3 Django==2.2.1 django-cors-headers==3.0.2 +django-environ==0.4.5 django-extensions==2.1.7 djangorestframework==3.9.4 entrypoints==0.3 -ipykernel==5.1.1 -ipython==7.5.0 -ipython-genutils==0.2.0 -ipywidgets==7.4.2 -jedi==0.13.3 -Jinja2==2.10.1 -jsonschema==3.0.1 -jupyter==1.0.0 -jupyter-client==5.2.4 -jupyter-console==6.0.0 -jupyter-core==4.4.0 -MarkupSafe==1.1.1 -mistune==0.8.4 -nbconvert==5.5.0 -nbformat==4.4.0 -notebook==5.7.8 -pandocfilters==1.4.2 -parso==0.4.0 -pexpect==4.7.0 -pickleshare==0.7.5 -pkg-resources==0.0.0 -prometheus-client==0.6.0 -prompt-toolkit==2.0.9 +flake8==3.7.7 +importlib-metadata==0.18 +mccabe==0.6.1 +more-itertools==7.0.0 +packaging==19.0 +pluggy==0.12.0 psycopg2==2.8.2 -ptyprocess==0.6.0 -Pygments==2.4.0 -pyrsistent==0.15.2 -python-dateutil==2.8.0 +py==1.8.0 +pycodestyle==2.5.0 +pyflakes==2.1.1 +pyparsing==2.4.0 +pytest==4.6.3 +pytest-cov==2.7.1 pytz==2019.1 -pyzmq==18.0.1 -qtconsole==4.5.0 -Send2Trash==1.5.0 six==1.12.0 sqlparse==0.3.0 -terminado==0.8.2 -testpath==0.4.2 -tornado==6.0.2 -traitlets==4.3.2 wcwidth==0.1.7 -webencodings==0.5.1 -widgetsnbextension==3.4.2 -flake8 +zipp==0.5.1