Skip to content

Commit

Permalink
all EPs tested!
Browse files Browse the repository at this point in the history
But haven't asserted the return object against the doc
  • Loading branch information
zachliu committed Apr 2, 2021
1 parent e31af24 commit 23fdbea
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 9 deletions.
57 changes: 57 additions & 0 deletions test/integration/test_create_update_get_delete_pool.py
Original file line number Diff line number Diff line change
@@ -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}")
54 changes: 54 additions & 0 deletions test/integration/test_create_update_get_delete_variable.py
Original file line number Diff line number Diff line change
@@ -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}")
32 changes: 32 additions & 0 deletions test/integration/test_get_dag_and_code.py
Original file line number Diff line number Diff line change
@@ -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}")
28 changes: 27 additions & 1 deletion test/integration/test_get_dag_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
8 changes: 8 additions & 0 deletions test/integration/test_get_event_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
9 changes: 8 additions & 1 deletion test/integration/test_get_import_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
47 changes: 45 additions & 2 deletions test/integration/test_get_task_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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}")
34 changes: 33 additions & 1 deletion test/integration/test_get_xcom_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}")
2 changes: 1 addition & 1 deletion test/integration/test_trigger_dag_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={},
)
Expand Down
44 changes: 44 additions & 0 deletions test/integration/test_trigger_delete_dag_run.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit 23fdbea

Please sign in to comment.