Skip to content

Commit

Permalink
👷 Hook up oidc-enabled CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed May 28, 2024
1 parent a914579 commit e6a0213
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ on:

jobs:
tests:
name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }})
name: "Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }}, OIDC: ${{ matrix.oidc_enabled }})"
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.10', '3.11', '3.12']
django: ['4.2']
oidc_enabled: ['no', 'yes']

services:
postgres:
image: postgres:15
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4
Expand All @@ -34,10 +45,19 @@ jobs:
run: pip install tox tox-gh-actions

- name: Run tests
run: tox
run: |
extra_opts=''
if [ "$OIDC_ENABLED" != "yes" ]; then
extra_opts=' --ignore=tests/oidc '
fi
tox -- "$extra_opts"
env:
PYTHON_VERSION: ${{ matrix.python }}
DJANGO: ${{ matrix.django }}
OIDC_ENABLED: ${{ matrix.oidc_enabled }}
PGUSER: postgres
PGHOST: localhost

- name: Publish coverage report
uses: codecov/codecov-action@v3
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

[tool:pytest]
testpaths = tests
python_classes = test_*
DJANGO_SETTINGS_MODULE=tests.project.settings

[pep8]
Expand Down
Empty file added tests/oidc/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions tests/oidc/test_oidc_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_oidc_enabled(settings):
assert settings.OIDC_ENABLED is True
22 changes: 17 additions & 5 deletions tests/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"digid_eherkenning",
"tests.project",
]
if os.environ.get("OIDC_ENABLED", False):
OIDC_ENABLED = os.environ.get("OIDC_ENABLED", "no") == "yes"
if OIDC_ENABLED:
INSTALLED_APPS += _OIDC_APPS


Expand Down Expand Up @@ -97,10 +98,21 @@
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
"default": (
{
"ENGINE": "django.db.backends.postgresql",
"NAME": os.getenv("PGDATABASE", "django_digid_eherkenning"),
"USER": os.getenv("PGUSER", "django_digid_eherkenning"),
"PASSWORD": os.getenv("PGPASSWORD", "django_digid_eherkenning"),
"HOST": os.getenv("DB_HOST", "localhost"),
"PORT": os.getenv("DB_PORT", 5432),
}
if OIDC_ENABLED
else {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
)
}

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
Expand Down
17 changes: 16 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{310,311,312}-django{42}
py{310,311,312}-django{42}-oidc{enabled,disabled}
isort
black
docs
Expand All @@ -15,15 +15,27 @@ python =
[gh-actions:env]
DJANGO =
4.2: django42
OIDC_ENABLED =
yes: oidcenabled
no: oidcdisabled

[testenv]
setenv =
PYTHONPATH={toxinidir}
passenv =
OIDC_ENABLED
PGUSER
PGDATABASE
PGPASSWORD
PGPORT
PGHOST
extras =
tests
coverage
oidcenabled: oidc
deps =
django42: Django~=4.2
oidcenabled: psycopg
commands =
py.test tests \
--cov --cov-report xml:reports/coverage-{envname}.xml \
Expand All @@ -44,8 +56,11 @@ basepython=python
changedir=docs
skipsdist=true
extras =
oidc
tests
docs
deps =
psycopg
commands=
py.test check_sphinx.py -v \
--tb=auto \
Expand Down

0 comments on commit e6a0213

Please sign in to comment.