diff --git a/test/integration/test_create_update_get_delete_pool.py b/test/integration/test_create_update_get_delete_pool.py new file mode 100644 index 0000000..9524e28 --- /dev/null +++ b/test/integration/test_create_update_get_delete_pool.py @@ -0,0 +1,57 @@ +""" + Airflow API (Stable) + + Apache Airflow management API. # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Contact: zach.z.liu@gmail.com + Generated by: https://openapi-generator.tech +""" + +import logging + +from test.integration.conftest import BCOLORS + +from airflow_python_sdk.model.pool import Pool + +POOL_DICT = { + "name": "test_pool", + "slots": 1, +} + +INIT_POOL = Pool(**POOL_DICT) + +def test_create_pool(pool_api_setup): + """Test the post /pools API EP""" + api_response = pool_api_setup.post_pool(INIT_POOL) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_update_pool(pool_api_setup): + """Test the patch /pools/{pool_id} API EP""" + POOL_DICT["slots"] = 2 + updated_pool = Pool(**POOL_DICT) + api_response = pool_api_setup.patch_pool( + "test_pool", + updated_pool, + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_get_pool(pool_api_setup): + """Test the get /pools/{pool_id} API EP""" + POOL_DICT["occupied_slots"] = 0 + POOL_DICT["open_slots"] = POOL_DICT["slots"] + POOL_DICT["queued_slots"] = 0 + POOL_DICT["running_slots"] = 0 + updated_pool = Pool(**POOL_DICT) + api_response = pool_api_setup.get_pool("test_pool") + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + assert api_response == updated_pool + +def test_delete_pool(pool_api_setup): + """Test the delete /pools/{pool_id} API EP""" + api_response = pool_api_setup.delete_pool("test_pool") + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_create_update_get_delete_variable.py b/test/integration/test_create_update_get_delete_variable.py new file mode 100644 index 0000000..675229d --- /dev/null +++ b/test/integration/test_create_update_get_delete_variable.py @@ -0,0 +1,54 @@ +""" + Airflow API (Stable) + + Apache Airflow management API. # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Contact: zach.z.liu@gmail.com + Generated by: https://openapi-generator.tech +""" + +import logging + +from test.integration.conftest import BCOLORS + +from airflow_python_sdk.model.variable import Variable + +VARIABLE_DICT = { + "key": "test_variable", + "value": "{1:2, 3:4}", +} + +INIT_VARIABLE = Variable(**VARIABLE_DICT) + +def test_create_variable(variable_api_setup): + """Test the post /variables API EP""" + api_response = variable_api_setup.post_variables(INIT_VARIABLE) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_update_variable(variable_api_setup): + """Test the patch /variables/{variable_key} API EP""" + VARIABLE_DICT["value"] = "{1:2,5:6}" + updated_variable = Variable(**VARIABLE_DICT) + api_response = variable_api_setup.patch_variable( + "test_variable", + updated_variable, + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_get_variable(variable_api_setup): + """Test the get /variables/{variable_key} API EP""" + VARIABLE_DICT["value"] = "{1:2,5:6}" + updated_variable = Variable(**VARIABLE_DICT) + api_response = variable_api_setup.get_variable("test_variable") + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + assert api_response == updated_variable + +def test_delete_variable(variable_api_setup): + """Test the delete /variables/{variable_key} API EP""" + api_response = variable_api_setup.delete_variable("test_variable") + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_dag_and_code.py b/test/integration/test_get_dag_and_code.py new file mode 100644 index 0000000..efbba2c --- /dev/null +++ b/test/integration/test_get_dag_and_code.py @@ -0,0 +1,32 @@ +""" + Airflow API (Stable) + + Apache Airflow management API. # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Contact: zach.z.liu@gmail.com + Generated by: https://openapi-generator.tech +""" + +import logging + +from test.integration.conftest import BCOLORS + + +def test_get_dag(dag_api_setup): + """Test the /dags/{dag_id} API EP""" + api_response = dag_api_setup.get_dag(dag_id="example_bash_operator") + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_get_dag_code(dag_api_setup): + """Test the /dagSources/{file_token} API EP""" + api_response = dag_api_setup.get_dag(dag_id="example_bash_operator") + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + + file_token = api_response.file_token + + api_response = dag_api_setup.get_dag_source(file_token=file_token) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_dag_runs.py b/test/integration/test_get_dag_runs.py index f5b93d8..f95e119 100644 --- a/test/integration/test_get_dag_runs.py +++ b/test/integration/test_get_dag_runs.py @@ -9,14 +9,40 @@ """ import logging +from dateutil.parser import parse from test.integration.conftest import BCOLORS +from airflow_python_sdk.model.list_dag_runs_form import ListDagRunsForm def test_get_dag_runs(dag_run_api_setup): """Test the /dags/{dag_id}/dagRuns API EP""" api_response = dag_run_api_setup.get_dag_runs( - dag_id="test_glue_partitions_sensor", + dag_id="example_bash_operator", + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + + +def test_get_dag_runs_batch(dag_run_api_setup): + """Test the /dags/~/dagRuns/list API EP""" + list_dag_run_form = ListDagRunsForm( + dag_ids=[ + "example_bash_operator", + ], + # ==================================================== + # Uncomment the following to add to the filter + # ==================================================== + execution_date_gte=parse('2021-03-29T00:00:00.00Z'), + execution_date_lte=parse('2021-03-30T00:00:00.00Z'), + # start_date_gte=parse('1970-01-01T00:00:00.00Z'), + # start_date_lte=parse('1970-01-01T00:00:00.00Z'), + # end_date_gte=parse('1970-01-01T00:00:00.00Z'), + # end_date_lte=parse('1970-01-01T00:00:00.00Z'), + # ==================================================== + ) + api_response = dag_run_api_setup.get_dag_runs_batch( + list_dag_run_form ) logging.getLogger().info("%s", api_response) print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_event_logs.py b/test/integration/test_get_event_logs.py index 56c03b9..0689f38 100644 --- a/test/integration/test_get_event_logs.py +++ b/test/integration/test_get_event_logs.py @@ -18,3 +18,11 @@ def test_get_event_logs(event_log_api_setup): api_response = event_log_api_setup.get_event_logs(limit=100, offset=0) logging.getLogger().info("%s", api_response) print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_get_event_log(event_log_api_setup): + """Test the /eventLogs/{event_log_id} API EP""" + api_response = event_log_api_setup.get_event_log( + event_log_id=1, + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_import_errors.py b/test/integration/test_get_import_errors.py index 4079d66..464e30a 100644 --- a/test/integration/test_get_import_errors.py +++ b/test/integration/test_get_import_errors.py @@ -14,10 +14,17 @@ def test_get_import_errors(import_error_api_setup): - """Test the /eventLogs API EP""" + """Test the /importErrors and /importErrors/{import_error_id} API EP""" api_response = import_error_api_setup.get_import_errors( limit=100, offset=0, ) logging.getLogger().info("%s", api_response) print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + + if api_response.import_errors: + api_response = import_error_api_setup.get_import_errors( + import_error_id=api_response.import_errors[0].import_error_id, + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_dag.py b/test/integration/test_get_task.py similarity index 63% rename from test/integration/test_get_dag.py rename to test/integration/test_get_task.py index 5678549..f275bb7 100644 --- a/test/integration/test_get_dag.py +++ b/test/integration/test_get_task.py @@ -13,8 +13,11 @@ from test.integration.conftest import BCOLORS -def test_get_dag(dag_api_setup): - """Test the /dags/{dag_id} API EP""" - api_response = dag_api_setup.get_dag(dag_id="test_glue_partitions_sensor") +def test_get_task(dag_api_setup): + """Test the /dags/{dag_id}/tasks/{task_id} API EP""" + api_response = dag_api_setup.get_task( + dag_id="example_bash_operator", + task_id="run_after_loop", + ) logging.getLogger().info("%s", api_response) print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_task_instances.py b/test/integration/test_get_task_instances.py index b8c566c..51c1041 100644 --- a/test/integration/test_get_task_instances.py +++ b/test/integration/test_get_task_instances.py @@ -19,7 +19,7 @@ def test_get_task_instances(task_instance_api_setup): """Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances API EP""" api_response = task_instance_api_setup.get_task_instances( - dag_id="test_glue_partitions_sensor", + dag_id="example_bash_operator", dag_run_id="scheduled__2020-04-13T00:00:00+00:00", ) logging.getLogger().info("%s", api_response) @@ -30,7 +30,7 @@ def test_get_task_instances_batch(task_instance_api_setup): """Test the /dags/~/dagRuns/~/taskInstances/list API EP""" list_task_instance_form = ListTaskInstanceForm( dag_ids=[ - "test_glue_partitions_sensor", + "example_bash_operator", ], # ==================================================== # Uncomment the following to add to the filter @@ -59,3 +59,46 @@ def test_get_task_instances_batch(task_instance_api_setup): ) logging.getLogger().info("%s", api_response) print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + + +def test_get_task_instance(task_instance_api_setup): + """ + Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id} + API EP + """ + api_response = task_instance_api_setup.get_task_instance( + dag_id="example_bash_operator", + dag_run_id="scheduled__2021-03-20T00:00:00+00:00", + task_id="runme_0", + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_get_extra_links(task_instance_api_setup): + """ + Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/links + API EP + """ + api_response = task_instance_api_setup.get_extra_links( + dag_id="example_bash_operator", + dag_run_id="scheduled__2021-03-20T00:00:00+00:00", + task_id="runme_0", + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +def test_get_logs(task_instance_api_setup): + """ + Test the + /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/logs/ + {task_try_number} + API EP + """ + api_response = task_instance_api_setup.get_log( + dag_id="example_bash_operator", + dag_run_id="scheduled__2021-03-20T00:00:00+00:00", + task_id="runme_0", + task_try_number=1, + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_get_xcom_entries.py b/test/integration/test_get_xcom_entries.py index ec884b3..b5ce0ff 100644 --- a/test/integration/test_get_xcom_entries.py +++ b/test/integration/test_get_xcom_entries.py @@ -37,7 +37,10 @@ ], ) def test_get_xcom_entries(xcom_api_setup, test_input, expected): - """Test the /variables API EP""" + """Test the + /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/xcomEntries + API EP + """ dag_id, dag_run_id, task_id = test_input api_response = xcom_api_setup.get_xcom_entries( dag_id=dag_id, @@ -46,3 +49,32 @@ def test_get_xcom_entries(xcom_api_setup, test_input, expected): ) logging.getLogger().info("%s", api_response) print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + +@pytest.mark.parametrize( + "test_input, expected", + [ + ( + [ + "test_glue_python_shell", + "scheduled__2020-05-30T00:00:00+00:00", + "python_task", + ], + None + ), + ], +) +def test_get_xcom_entrie(xcom_api_setup, test_input, expected): + """Test the + /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/xcomEntries/ + {xcom_key} + API EP + """ + dag_id, dag_run_id, task_id = test_input + api_response = xcom_api_setup.get_xcom_entry( + dag_id=dag_id, + dag_run_id=dag_run_id, + task_id=task_id, + xcom_key="return_value", + ) + logging.getLogger().info("%s", api_response) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") diff --git a/test/integration/test_trigger_dag_run.py b/test/integration/test_trigger_dag_run.py index eeb4cbc..441cb61 100644 --- a/test/integration/test_trigger_dag_run.py +++ b/test/integration/test_trigger_dag_run.py @@ -20,7 +20,7 @@ def test_trigger_dag_run(dag_run_api_setup): """Test the /dags/{dag_id}/dagRuns API EP (post)""" time_now = datetime.now().strftime("%Y-%m-%dT%H:%M:%S+00:00") dag_run = DAGRun( - dag_run_id=f"test__{time_now}", + dag_run_id=f"test1__{time_now}", execution_date=parse(time_now), conf={}, ) diff --git a/test/integration/test_trigger_delete_dag_run.py b/test/integration/test_trigger_delete_dag_run.py new file mode 100644 index 0000000..e89fc3f --- /dev/null +++ b/test/integration/test_trigger_delete_dag_run.py @@ -0,0 +1,44 @@ +""" + Airflow API (Stable) + + Apache Airflow management API. # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Contact: zach.z.liu@gmail.com + Generated by: https://openapi-generator.tech +""" + +import logging +from datetime import datetime +from time import sleep + +from test.integration.conftest import BCOLORS + +from airflow_python_sdk.model.dag_run import DAGRun +from dateutil.parser import parse + +def test_trigger_delete_dag_run(dag_run_api_setup): + """Test the /dags/{dag_id}/dagRuns API EP (post) & + /dags/{dag_id}/dagRuns/{dag_run_id} API EP (delete)""" + time_now = datetime.now().strftime("%Y-%m-%dT%H:%M:%S+00:00") + dag_run_id = "test2__{}".format(time_now) + dag_run = DAGRun( + dag_run_id=dag_run_id, + execution_date=parse(time_now), + conf={}, + ) + trigger_resp = dag_run_api_setup.post_dag_run( + dag_id="example_bash_operator", + dag_run=dag_run, + ) + logging.getLogger().info("%s", trigger_resp) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}") + + sleep(5) + + delete_resp = dag_run_api_setup.delete_dag_run( + dag_id="example_bash_operator", + dag_run_id=dag_run_id, + ) + logging.getLogger().info("%s", delete_resp) + print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")