0
0
Apache Airflowdevops~10 mins

Unit testing DAGs in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Airflow DAG class.

Apache Airflow
from airflow.models import [1]
Drag options to blanks, or click blank then click option'
ATaskInstance
BVariable
CBaseOperator
DDAG
Attempts:
3 left
💡 Hint
Common Mistakes
Importing TaskInstance instead of DAG
Using BaseOperator which is for tasks
2fill in blank
medium

Complete the code to create a DAG object with id 'test_dag'.

Apache Airflow
dag = [1](dag_id='test_dag', start_date=datetime(2024, 1, 1))
Drag options to blanks, or click blank then click option'
ATaskInstance
BBaseOperator
CDAG
DVariable
Attempts:
3 left
💡 Hint
Common Mistakes
Using BaseOperator instead of DAG
Forgetting to set dag_id
3fill in blank
hard

Fix the error in the test code to check if the DAG has the correct id.

Apache Airflow
assert dag.[1] == 'test_dag'
Drag options to blanks, or click blank then click option'
Adag_id
Bid
Cname
Ddag_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or name instead of dag_id
Trying to access dag_name which is invalid
4fill in blank
hard

Fill both blanks to create a task using PythonOperator with a simple callable.

Apache Airflow
task = PythonOperator(task_id='print_hello', python_callable=[1], dag=[2])
Drag options to blanks, or click blank then click option'
Aprint_hello
Bdag
Cprint
Dstart_date
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of a function name
Passing start_date instead of dag
5fill in blank
hard

Fill all three blanks to assert the task has the correct task_id and belongs to the DAG.

Apache Airflow
assert task.[1] == 'print_hello'
assert task.[2] == [3]
Drag options to blanks, or click blank then click option'
Atask_id
Bdag
Ddag_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using dag_id instead of dag for task's DAG
Mixing up attribute names