Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestaP committed Feb 23, 2024
1 parent d1ce962 commit 7f9ad2b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python application test with pytest
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build_test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Python 3
uses: actions/setup-python@v4
with:
python-version: 3.10.11

- name: Build Docker image
run: docker build -t test .

- name: Run tests with pytest and generate report
run: >
docker run
--name biproject
--network=host
-v "$(pwd)"/tests:/opt/airflow/tests
--entrypoint pytest test /opt/airflow/tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Airflow
logs
airflow.db
airflow.cfg
standalone_admin_password.txt
webserver_config.py

Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ ENV AIRFLOW__LOGGING__LOGGING_LEVEL=INFO

# install your pip packages
COPY requirements.txt ./requirements.txt
COPY requirements-test.txt ./requirements-test.txt

COPY dags ./dags
COPY airflow.cfg ./airflow.cfg

RUN pip install --upgrade pip &&\
pip install --no-cache-dir --upgrade setuptools==59.1.1 &&\
pip install --no-cache-dir --upgrade wheel &&\
pip install --no-cache-dir --user -r requirements.txt

RUN pip install --no-cache-dir --user -r requirements-test.txt -r requirements.txt
12 changes: 6 additions & 6 deletions airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# The folder where your airflow pipelines live, most likely a
# subfolder in a code repository. This path must be absolute.
#
# Variable: AIRFLOW__CORE__DAGS_FOLDER
# Variable: AIRFLOW_HOME
#
dags_folder = /Users/ernesta/work/projects/sis_workflows/monitoring/bi-dags/dags
#dags_folder = /Users/ernesta/work/projects/sis_workflows/monitoring/bi-dags/dags

# Hostname by providing a path to a callable, which will resolve the hostname.
# The format is "package.function".
Expand Down Expand Up @@ -543,7 +543,7 @@ check_migrations = True
#
# Variable: AIRFLOW__LOGGING__BASE_LOG_FOLDER
#
base_log_folder = /Users/ernesta/work/projects/sis_workflows/monitoring/bi-dags/logs
base_log_folder = {AIRFLOW_HOME}/logs

# Airflow can store logs remotely in AWS S3, Google Cloud Storage or Elastic Search.
# Set this to True if you want to enable remote logging.
Expand Down Expand Up @@ -725,7 +725,7 @@ log_processor_filename_template = {{ filename }}.log
#
# Variable: AIRFLOW__LOGGING__DAG_PROCESSOR_MANAGER_LOG_LOCATION
#
dag_processor_manager_log_location = /Users/ernesta/work/projects/sis_workflows/monitoring/bi-dags/logs/dag_processor_manager/dag_processor_manager.log
dag_processor_manager_log_location = {AIRFLOW_HOME}/logs/dag_processor_manager/dag_processor_manager.log

# Name of handler to read task instance logs.
# Defaults to use ``task`` handler.
Expand Down Expand Up @@ -1192,7 +1192,7 @@ access_denied_message = Access is Denied
#
# Variable: AIRFLOW__WEBSERVER__CONFIG_FILE
#
config_file = /Users/ernesta/work/projects/sis_workflows/monitoring/bi-dags/webserver_config.py
config_file = {AIRFLOW_HOME}/webserver_config.py

# The base url of your website as airflow cannot guess what domain or
# cname you are using. This is used in automated emails that
Expand Down Expand Up @@ -1918,7 +1918,7 @@ orphaned_tasks_check_interval = 300.0
#
# Variable: AIRFLOW__SCHEDULER__CHILD_PROCESS_LOG_DIRECTORY
#
child_process_log_directory = /Users/ernesta/work/projects/sis_workflows/monitoring/bi-dags/logs/scheduler
child_process_log_directory = {AIRFLOW_HOME}/logs/scheduler

# Local task jobs periodically heartbeat to the DB. If the job has
# not heartbeat in this many seconds, the scheduler will mark the
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pre-commit==3.6.0
pytest==7.4.4
coverage==7.4.0
pytest-cov==4.1.0
9 changes: 9 additions & 0 deletions tests/unit/test_test_dag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dags.example_dag.example_dag import fetch, pull


def test_test_dag_fetch():
assert fetch() == "Test String"


def test_test_dag_pull():
assert pull("Test String") == "Test String"

0 comments on commit 7f9ad2b

Please sign in to comment.