Skip to content

Commit 23fdbea

Browse files
committed
all EPs tested!
But haven't asserted the return object against the doc
1 parent e31af24 commit 23fdbea

11 files changed

+315
-9
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Airflow API (Stable)
3+
4+
Apache Airflow management API. # noqa: E501
5+
6+
The version of the OpenAPI document: 1.0.0
7+
8+
Generated by: https://openapi-generator.tech
9+
"""
10+
11+
import logging
12+
13+
from test.integration.conftest import BCOLORS
14+
15+
from airflow_python_sdk.model.pool import Pool
16+
17+
POOL_DICT = {
18+
"name": "test_pool",
19+
"slots": 1,
20+
}
21+
22+
INIT_POOL = Pool(**POOL_DICT)
23+
24+
def test_create_pool(pool_api_setup):
25+
"""Test the post /pools API EP"""
26+
api_response = pool_api_setup.post_pool(INIT_POOL)
27+
logging.getLogger().info("%s", api_response)
28+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
29+
30+
def test_update_pool(pool_api_setup):
31+
"""Test the patch /pools/{pool_id} API EP"""
32+
POOL_DICT["slots"] = 2
33+
updated_pool = Pool(**POOL_DICT)
34+
api_response = pool_api_setup.patch_pool(
35+
"test_pool",
36+
updated_pool,
37+
)
38+
logging.getLogger().info("%s", api_response)
39+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
40+
41+
def test_get_pool(pool_api_setup):
42+
"""Test the get /pools/{pool_id} API EP"""
43+
POOL_DICT["occupied_slots"] = 0
44+
POOL_DICT["open_slots"] = POOL_DICT["slots"]
45+
POOL_DICT["queued_slots"] = 0
46+
POOL_DICT["running_slots"] = 0
47+
updated_pool = Pool(**POOL_DICT)
48+
api_response = pool_api_setup.get_pool("test_pool")
49+
logging.getLogger().info("%s", api_response)
50+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
51+
assert api_response == updated_pool
52+
53+
def test_delete_pool(pool_api_setup):
54+
"""Test the delete /pools/{pool_id} API EP"""
55+
api_response = pool_api_setup.delete_pool("test_pool")
56+
logging.getLogger().info("%s", api_response)
57+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Airflow API (Stable)
3+
4+
Apache Airflow management API. # noqa: E501
5+
6+
The version of the OpenAPI document: 1.0.0
7+
8+
Generated by: https://openapi-generator.tech
9+
"""
10+
11+
import logging
12+
13+
from test.integration.conftest import BCOLORS
14+
15+
from airflow_python_sdk.model.variable import Variable
16+
17+
VARIABLE_DICT = {
18+
"key": "test_variable",
19+
"value": "{1:2, 3:4}",
20+
}
21+
22+
INIT_VARIABLE = Variable(**VARIABLE_DICT)
23+
24+
def test_create_variable(variable_api_setup):
25+
"""Test the post /variables API EP"""
26+
api_response = variable_api_setup.post_variables(INIT_VARIABLE)
27+
logging.getLogger().info("%s", api_response)
28+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
29+
30+
def test_update_variable(variable_api_setup):
31+
"""Test the patch /variables/{variable_key} API EP"""
32+
VARIABLE_DICT["value"] = "{1:2,5:6}"
33+
updated_variable = Variable(**VARIABLE_DICT)
34+
api_response = variable_api_setup.patch_variable(
35+
"test_variable",
36+
updated_variable,
37+
)
38+
logging.getLogger().info("%s", api_response)
39+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
40+
41+
def test_get_variable(variable_api_setup):
42+
"""Test the get /variables/{variable_key} API EP"""
43+
VARIABLE_DICT["value"] = "{1:2,5:6}"
44+
updated_variable = Variable(**VARIABLE_DICT)
45+
api_response = variable_api_setup.get_variable("test_variable")
46+
logging.getLogger().info("%s", api_response)
47+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
48+
assert api_response == updated_variable
49+
50+
def test_delete_variable(variable_api_setup):
51+
"""Test the delete /variables/{variable_key} API EP"""
52+
api_response = variable_api_setup.delete_variable("test_variable")
53+
logging.getLogger().info("%s", api_response)
54+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Airflow API (Stable)
3+
4+
Apache Airflow management API. # noqa: E501
5+
6+
The version of the OpenAPI document: 1.0.0
7+
8+
Generated by: https://openapi-generator.tech
9+
"""
10+
11+
import logging
12+
13+
from test.integration.conftest import BCOLORS
14+
15+
16+
def test_get_dag(dag_api_setup):
17+
"""Test the /dags/{dag_id} API EP"""
18+
api_response = dag_api_setup.get_dag(dag_id="example_bash_operator")
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
21+
22+
def test_get_dag_code(dag_api_setup):
23+
"""Test the /dagSources/{file_token} API EP"""
24+
api_response = dag_api_setup.get_dag(dag_id="example_bash_operator")
25+
logging.getLogger().info("%s", api_response)
26+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
27+
28+
file_token = api_response.file_token
29+
30+
api_response = dag_api_setup.get_dag_source(file_token=file_token)
31+
logging.getLogger().info("%s", api_response)
32+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_dag_runs.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,40 @@
99
"""
1010

1111
import logging
12+
from dateutil.parser import parse
1213

1314
from test.integration.conftest import BCOLORS
1415

16+
from airflow_python_sdk.model.list_dag_runs_form import ListDagRunsForm
1517

1618
def test_get_dag_runs(dag_run_api_setup):
1719
"""Test the /dags/{dag_id}/dagRuns API EP"""
1820
api_response = dag_run_api_setup.get_dag_runs(
19-
dag_id="test_glue_partitions_sensor",
21+
dag_id="example_bash_operator",
22+
)
23+
logging.getLogger().info("%s", api_response)
24+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
25+
26+
27+
def test_get_dag_runs_batch(dag_run_api_setup):
28+
"""Test the /dags/~/dagRuns/list API EP"""
29+
list_dag_run_form = ListDagRunsForm(
30+
dag_ids=[
31+
"example_bash_operator",
32+
],
33+
# ====================================================
34+
# Uncomment the following to add to the filter
35+
# ====================================================
36+
execution_date_gte=parse('2021-03-29T00:00:00.00Z'),
37+
execution_date_lte=parse('2021-03-30T00:00:00.00Z'),
38+
# start_date_gte=parse('1970-01-01T00:00:00.00Z'),
39+
# start_date_lte=parse('1970-01-01T00:00:00.00Z'),
40+
# end_date_gte=parse('1970-01-01T00:00:00.00Z'),
41+
# end_date_lte=parse('1970-01-01T00:00:00.00Z'),
42+
# ====================================================
43+
)
44+
api_response = dag_run_api_setup.get_dag_runs_batch(
45+
list_dag_run_form
2046
)
2147
logging.getLogger().info("%s", api_response)
2248
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_event_logs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ def test_get_event_logs(event_log_api_setup):
1818
api_response = event_log_api_setup.get_event_logs(limit=100, offset=0)
1919
logging.getLogger().info("%s", api_response)
2020
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
21+
22+
def test_get_event_log(event_log_api_setup):
23+
"""Test the /eventLogs/{event_log_id} API EP"""
24+
api_response = event_log_api_setup.get_event_log(
25+
event_log_id=1,
26+
)
27+
logging.getLogger().info("%s", api_response)
28+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_import_errors.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414

1515

1616
def test_get_import_errors(import_error_api_setup):
17-
"""Test the /eventLogs API EP"""
17+
"""Test the /importErrors and /importErrors/{import_error_id} API EP"""
1818
api_response = import_error_api_setup.get_import_errors(
1919
limit=100,
2020
offset=0,
2121
)
2222
logging.getLogger().info("%s", api_response)
2323
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
24+
25+
if api_response.import_errors:
26+
api_response = import_error_api_setup.get_import_errors(
27+
import_error_id=api_response.import_errors[0].import_error_id,
28+
)
29+
logging.getLogger().info("%s", api_response)
30+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
from test.integration.conftest import BCOLORS
1414

1515

16-
def test_get_dag(dag_api_setup):
17-
"""Test the /dags/{dag_id} API EP"""
18-
api_response = dag_api_setup.get_dag(dag_id="test_glue_partitions_sensor")
16+
def test_get_task(dag_api_setup):
17+
"""Test the /dags/{dag_id}/tasks/{task_id} API EP"""
18+
api_response = dag_api_setup.get_task(
19+
dag_id="example_bash_operator",
20+
task_id="run_after_loop",
21+
)
1922
logging.getLogger().info("%s", api_response)
2023
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_task_instances.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def test_get_task_instances(task_instance_api_setup):
2020
"""Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances API EP"""
2121
api_response = task_instance_api_setup.get_task_instances(
22-
dag_id="test_glue_partitions_sensor",
22+
dag_id="example_bash_operator",
2323
dag_run_id="scheduled__2020-04-13T00:00:00+00:00",
2424
)
2525
logging.getLogger().info("%s", api_response)
@@ -30,7 +30,7 @@ def test_get_task_instances_batch(task_instance_api_setup):
3030
"""Test the /dags/~/dagRuns/~/taskInstances/list API EP"""
3131
list_task_instance_form = ListTaskInstanceForm(
3232
dag_ids=[
33-
"test_glue_partitions_sensor",
33+
"example_bash_operator",
3434
],
3535
# ====================================================
3636
# Uncomment the following to add to the filter
@@ -59,3 +59,46 @@ def test_get_task_instances_batch(task_instance_api_setup):
5959
)
6060
logging.getLogger().info("%s", api_response)
6161
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
62+
63+
64+
def test_get_task_instance(task_instance_api_setup):
65+
"""
66+
Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}
67+
API EP
68+
"""
69+
api_response = task_instance_api_setup.get_task_instance(
70+
dag_id="example_bash_operator",
71+
dag_run_id="scheduled__2021-03-20T00:00:00+00:00",
72+
task_id="runme_0",
73+
)
74+
logging.getLogger().info("%s", api_response)
75+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
76+
77+
def test_get_extra_links(task_instance_api_setup):
78+
"""
79+
Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/links
80+
API EP
81+
"""
82+
api_response = task_instance_api_setup.get_extra_links(
83+
dag_id="example_bash_operator",
84+
dag_run_id="scheduled__2021-03-20T00:00:00+00:00",
85+
task_id="runme_0",
86+
)
87+
logging.getLogger().info("%s", api_response)
88+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
89+
90+
def test_get_logs(task_instance_api_setup):
91+
"""
92+
Test the
93+
/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/logs/
94+
{task_try_number}
95+
API EP
96+
"""
97+
api_response = task_instance_api_setup.get_log(
98+
dag_id="example_bash_operator",
99+
dag_run_id="scheduled__2021-03-20T00:00:00+00:00",
100+
task_id="runme_0",
101+
task_try_number=1,
102+
)
103+
logging.getLogger().info("%s", api_response)
104+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_xcom_entries.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
],
3838
)
3939
def test_get_xcom_entries(xcom_api_setup, test_input, expected):
40-
"""Test the /variables API EP"""
40+
"""Test the
41+
/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/xcomEntries
42+
API EP
43+
"""
4144
dag_id, dag_run_id, task_id = test_input
4245
api_response = xcom_api_setup.get_xcom_entries(
4346
dag_id=dag_id,
@@ -46,3 +49,32 @@ def test_get_xcom_entries(xcom_api_setup, test_input, expected):
4649
)
4750
logging.getLogger().info("%s", api_response)
4851
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
52+
53+
@pytest.mark.parametrize(
54+
"test_input, expected",
55+
[
56+
(
57+
[
58+
"test_glue_python_shell",
59+
"scheduled__2020-05-30T00:00:00+00:00",
60+
"python_task",
61+
],
62+
None
63+
),
64+
],
65+
)
66+
def test_get_xcom_entrie(xcom_api_setup, test_input, expected):
67+
"""Test the
68+
/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/xcomEntries/
69+
{xcom_key}
70+
API EP
71+
"""
72+
dag_id, dag_run_id, task_id = test_input
73+
api_response = xcom_api_setup.get_xcom_entry(
74+
dag_id=dag_id,
75+
dag_run_id=dag_run_id,
76+
task_id=task_id,
77+
xcom_key="return_value",
78+
)
79+
logging.getLogger().info("%s", api_response)
80+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_trigger_dag_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_trigger_dag_run(dag_run_api_setup):
2020
"""Test the /dags/{dag_id}/dagRuns API EP (post)"""
2121
time_now = datetime.now().strftime("%Y-%m-%dT%H:%M:%S+00:00")
2222
dag_run = DAGRun(
23-
dag_run_id=f"test__{time_now}",
23+
dag_run_id=f"test1__{time_now}",
2424
execution_date=parse(time_now),
2525
conf={},
2626
)

0 commit comments

Comments
 (0)