From ef19f2e99323427d486def9155986e900d37aa82 Mon Sep 17 00:00:00 2001 From: Chethan UK Date: Fri, 3 Jun 2022 01:04:57 +0100 Subject: [PATCH] Migrate Neo4j example DAGs to new design #22454 --- .../providers/neo4j/example_dags/__init__.py | 17 ---------- docs/apache-airflow-providers-neo4j/index.rst | 2 +- .../operators/neo4j.rst | 6 ++++ .../system/providers/neo4j}/example_neo4j.py | 32 ++++++++++++------- 4 files changed, 27 insertions(+), 30 deletions(-) delete mode 100644 airflow/providers/neo4j/example_dags/__init__.py rename {airflow/providers/neo4j/example_dags => tests/system/providers/neo4j}/example_neo4j.py (64%) diff --git a/airflow/providers/neo4j/example_dags/__init__.py b/airflow/providers/neo4j/example_dags/__init__.py deleted file mode 100644 index 217e5db960782..0000000000000 --- a/airflow/providers/neo4j/example_dags/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. diff --git a/docs/apache-airflow-providers-neo4j/index.rst b/docs/apache-airflow-providers-neo4j/index.rst index c803c6b20c6cb..c3a216a2d840b 100644 --- a/docs/apache-airflow-providers-neo4j/index.rst +++ b/docs/apache-airflow-providers-neo4j/index.rst @@ -39,7 +39,7 @@ Content :maxdepth: 1 :caption: Resources - Example DAGs + Example DAGs .. toctree:: :maxdepth: 1 diff --git a/docs/apache-airflow-providers-neo4j/operators/neo4j.rst b/docs/apache-airflow-providers-neo4j/operators/neo4j.rst index 411aa0c6698ce..5bc2362e91089 100644 --- a/docs/apache-airflow-providers-neo4j/operators/neo4j.rst +++ b/docs/apache-airflow-providers-neo4j/operators/neo4j.rst @@ -48,3 +48,9 @@ the connection metadata is structured as follows: - Neo4j user password * - Port: int - Neo4j port + +.. exampleinclude:: /../../tests/system/providers/neo4j/example_neo4j.py + :language: python + :dedent: 4 + :start-after: [START run_query_neo4j_operator] + :end-before: [END run_query_neo4j_operator] diff --git a/airflow/providers/neo4j/example_dags/example_neo4j.py b/tests/system/providers/neo4j/example_neo4j.py similarity index 64% rename from airflow/providers/neo4j/example_dags/example_neo4j.py rename to tests/system/providers/neo4j/example_neo4j.py index f1ebbb0011aa5..776a4e8577fa6 100644 --- a/airflow/providers/neo4j/example_dags/example_neo4j.py +++ b/tests/system/providers/neo4j/example_neo4j.py @@ -18,26 +18,34 @@ """ Example use of Neo4j related operators. """ - +import os from datetime import datetime from airflow import DAG from airflow.providers.neo4j.operators.neo4j import Neo4jOperator -dag = DAG( - 'example_neo4j', +ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") +DAG_ID = "example_neo4j" + +with DAG( + DAG_ID, start_date=datetime(2021, 1, 1), tags=['example'], catchup=False, -) +) as dag: + + # [START run_query_neo4j_operator] + + neo4j_task = Neo4jOperator( + task_id='run_neo4j_query', + neo4j_conn_id='neo4j_conn_id', + sql='MATCH (tom {name: "Tom Hanks", date: "{{ds}}"}) RETURN tom', + dag=dag, + ) -# [START run_query_neo4j_operator] + # [END run_query_neo4j_operator] -neo4j_task = Neo4jOperator( - task_id='run_neo4j_query', - neo4j_conn_id='neo4j_conn_id', - sql='MATCH (tom {name: "Tom Hanks", date: "{{ds}}"}) RETURN tom', - dag=dag, -) +from tests.system.utils import get_test_run # noqa: E402 -# [END run_query_neo4j_operator] +# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest) +test_run = get_test_run(dag)