Skip to content

Commit

Permalink
Run tests on github actions both for sqlite and postgresql (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
C4ptainCrunch authored Nov 21, 2022
1 parent 4dc384a commit 019de7e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
28 changes: 28 additions & 0 deletions search/tests/test_postgresql.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 019de7e

Please sign in to comment.