diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 3cb85d33..548ca6d5 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -16,6 +16,21 @@ jobs: build: runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + + steps: - uses: actions/checkout@v3 - name: Apt update @@ -44,8 +59,13 @@ jobs: - name: Statics checks run: ./manage.py collectstatic --noinput -v 0 - - name: pytest + - name: pytest with SQLite run: pytest -k "not unoconv" - - name: database checks + - name: pytest with PostgreSQL + run: pytest -k "not unoconv" -m postgresql + env: + DB_URL: postgres://postgres:postgres@localhost:5432/postgres + + - name: Check local dev initialization scripts run: make database diff --git a/search/tests/test_postgresql.py b/search/tests/test_postgresql.py new file mode 100644 index 00000000..a71c1d8f --- /dev/null +++ b/search/tests/test_postgresql.py @@ -0,0 +1,28 @@ +from django.db import connection + +import pytest + + +def needs_postgres(fn): + @pytest.mark.django_db + @pytest.mark.postgresql + @pytest.mark.skipif( + connection.vendor != "postgresql", + reason="This test requires a PostgreSQL database", + ) + def wrapper(*args, **kwargs): + return fn(*args, **kwargs) + + return wrapper + + +@needs_postgres +def test_running_with_postgres(): + """ + This is a dummy test to check if our logic of @needs_postgres is correct + and that the setup of GitHub actions is correct too. + """ + assert True + + +# FIXME: add more tests (see https://github.com/UrLab/DocHub/issues/257) diff --git a/setup.cfg b/setup.cfg index 04393f7b..46627d87 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,6 +8,7 @@ markers = unoconv: uses unoconv (underterministic) webtest: http queries against localhost celery: uses celery tasks + postgresql: needs a postgresql database to run [flake8] ignore = E261