Skip to content

Commit

Permalink
feat(pipeline): Test DAGs
Browse files Browse the repository at this point in the history
TODO: Would be really nice to run SQLFluff, Black, Isort... in the CI as
well. But SQLFluff requires a database connection and deps to work.

TODO: Now that we test the loading of the DAGs, we should test running ours
with a mock behind it.
  • Loading branch information
vperron committed Nov 29, 2023
1 parent 249f904 commit 704191f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,54 @@ on:

jobs:
tests:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
env:
CI: 1
PYTHONPATH: .
PGPASSWORD: password
PGHOST: localhost
PGUSER: postgres
PGPORT: 5432
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: postgresql://postgres:password@localhost:5432/airflow

services:
postgres:
image: postgres:14
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Bootstrap PostgreSQL
run: |
psql <<SQL
ALTER SYSTEM SET fsync=off;
ALTER SYSTEM SET synchronous_commit=off;
ALTER SYSTEM SET full_page_writes=off;
CREATE DATABASE data-inclusion;
CREATE DATABASE airflow;
SQL
docker kill --signal=SIGHUP ${{ job.services.postgres.id }}
- name: Setup airflow database
run: |
airflow db reset -y
airflow db upgrade
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- run: pip install tox
- run: tox -- -vv

- name: Run tests
run: tox -- -vv
1 change: 1 addition & 0 deletions pipeline/requirements/dev/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
black
pre-commit
pytest
pytest-subtests
tox
requests-mock
5 changes: 5 additions & 0 deletions pipeline/requirements/dev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ attrs==23.1.0
# cattrs
# fiona
# jsonschema
# pytest-subtests
# referencing
babel==2.13.1
# via flask-babel
Expand Down Expand Up @@ -472,6 +473,10 @@ pyproj==3.6.1
pyproject-api==1.6.1
# via tox
pytest==7.4.3
# via
# -r requirements/dev/requirements.in
# pytest-subtests
pytest-subtests==0.11.0
# via -r requirements/dev/requirements.in
python-daemon==3.0.1
# via apache-airflow
Expand Down
11 changes: 11 additions & 0 deletions pipeline/tests/unit/test_dags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from airflow.models import DagBag


def test_dags_generic(subtests):
dagbag = DagBag()
for dag_id in dagbag.dag_ids:
with subtests.test(msg="DAG generic checks", dag_id=dag_id):
dag = dagbag.get_dag(dag_id=dag_id)
assert dagbag.import_errors == {}
assert dag is not None
assert len(dag.tasks) >= 1
7 changes: 7 additions & 0 deletions pipeline/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
deps = -r requirements/dev/requirements.txt
usedevelop = true
commands = pytest {posargs}
passenv = AIRFLOW_VAR_*
setenv =
AIRFLOW__CORE__DAGS_FOLDER=./dags
AIRFLOW__CORE__DEFAULT_TIMEZONE=Europe/Paris
AIRFLOW__CORE__EXECUTOR=LocalExecutor
AIRFLOW__CORE__LOAD_DEFAULT_CONNECTIONS=false
AIRFLOW__CORE__LOAD_EXAMPLES=false

0 comments on commit 704191f

Please sign in to comment.