Skip to content

Commit 8007258

Browse files
committed
move integration tests to where they belong
1 parent b70d2b0 commit 8007258

14 files changed

+310
-99
lines changed

test/integration/__init__.py

Whitespace-only changes.

test/conftest.py renamed to test/integration/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import pytest
88

99
from airflow_python_sdk.api.dag_api import DAGApi # noqa: E501
10+
from airflow_python_sdk.api.config_api import ConfigApi # noqa: E501
11+
from airflow_python_sdk.api.monitoring_api import MonitoringApi # noqa: E501
12+
from airflow_python_sdk.api.connection_api import ConnectionApi # noqa: E501
1013
from airflow_python_sdk import Configuration, ApiClient
1114

1215
if "API_HOST" not in os.environ or \
@@ -28,7 +31,33 @@
2831
)
2932
)
3033

34+
class BCOLORS:
35+
"""Color constants"""
36+
HEADER = '\033[95m'
37+
OKBLUE = '\033[94m'
38+
OKGREEN = '\033[92m'
39+
WARNING = '\033[93m'
40+
FAIL = '\033[91m'
41+
ENDC = '\033[0m'
42+
BOLD = '\033[1m'
43+
UNDERLINE = '\033[4m'
44+
45+
@pytest.fixture
46+
def config_api_setup():
47+
"""Instantiate api"""
48+
return ConfigApi(API_CLIENT) # noqa: E501
49+
3150
@pytest.fixture
3251
def dag_api_setup():
3352
"""Instantiate api"""
3453
return DAGApi(API_CLIENT) # noqa: E501
54+
55+
@pytest.fixture
56+
def monitoring_api_setup():
57+
"""Instantiate api"""
58+
return MonitoringApi(API_CLIENT) # noqa: E501
59+
60+
@pytest.fixture
61+
def connection_api_setup():
62+
"""Instantiate api"""
63+
return ConnectionApi(API_CLIENT) # noqa: E501
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
Contact: zach.z.liu@gmail.com
8+
Generated by: https://openapi-generator.tech
9+
"""
10+
11+
from test.integration.conftest import BCOLORS
12+
13+
import pytest
14+
15+
from airflow_python_sdk.model.clear_task_instance import ClearTaskInstance
16+
from airflow_python_sdk.exceptions import ApiException
17+
18+
19+
@pytest.mark.parametrize(
20+
"test_input, expected",
21+
[
22+
([True, True], 400),
23+
([False, False], None),
24+
([True, False], None),
25+
([False, True], None),
26+
],
27+
)
28+
def test_post_clear_task_instance(dag_api_setup, test_input, expected):
29+
"""Test ClearTaskInstance
30+
"""
31+
dag_id = "test_glue_partitions_sensor"
32+
start_date = "2020-01-01T00:00:00.00Z"
33+
end_date = "2021-01-24T23:59:59.00Z"
34+
only_failed, only_running = test_input
35+
clear_task_instance = ClearTaskInstance(
36+
dry_run=True,
37+
start_date=start_date,
38+
end_date=end_date,
39+
include_parentdag=False,
40+
include_subdags=False,
41+
only_failed=only_failed,
42+
only_running=only_running,
43+
reset_dag_runs=True,
44+
)
45+
try:
46+
api_response = dag_api_setup.post_clear_task_instances(
47+
dag_id, clear_task_instance
48+
)
49+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
50+
except ApiException as error:
51+
assert str(expected) in str(error)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
Contact: zach.z.liu@gmail.com
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.config_section import ConfigSection
16+
globals()['ConfigSection'] = ConfigSection
17+
18+
19+
def test_get_config(config_api_setup):
20+
"""Test the /config API EP"""
21+
api_response = config_api_setup.get_config()
22+
logging.getLogger().info("%s", api_response)
23+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
Contact: zach.z.liu@gmail.com
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_connections(connection_api_setup):
17+
"""Test the /connections API EP"""
18+
api_response = connection_api_setup.get_connections(limit=100, offset=0)
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_dag.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
Contact: zach.z.liu@gmail.com
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="test_glue_partitions_sensor")
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_dags.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
Contact: zach.z.liu@gmail.com
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_dags(dag_api_setup):
17+
"""Test the /dags API EP"""
18+
api_response = dag_api_setup.get_dags(limit=100, offset=0)
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
Contact: zach.z.liu@gmail.com
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_health(monitoring_api_setup):
17+
"""Test the health/ API EP"""
18+
api_response = monitoring_api_setup.get_health()
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
Contact: zach.z.liu@gmail.com
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_version(monitoring_api_setup):
17+
"""Test /version API EP"""
18+
api_response = monitoring_api_setup.get_version()
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
Contact: zach.z.liu@gmail.com
8+
Generated by: https://openapi-generator.tech
9+
"""
10+
11+
12+
from test.integration.conftest import BCOLORS
13+
14+
import pytest
15+
16+
from airflow_python_sdk.model.update_task_instances_state import \
17+
UpdateTaskInstancesState
18+
19+
@pytest.mark.parametrize(
20+
"test_input, expected",
21+
[
22+
([False, False, False, True], None),
23+
([True, False, False, True], None),
24+
([True, True, False, True], None),
25+
([True, True, True, True], None),
26+
([True, False, True, True], None),
27+
],
28+
)
29+
def test_set_task_instances_state(dag_api_setup, test_input, expected):
30+
"""Test post_set_task_instances_state
31+
"""
32+
dag_id = "test_glue_partitions_sensor"
33+
execution_date = "2020-03-25T00:00:00+00:00"
34+
include_downstream, include_future, include_past, include_upstream = \
35+
test_input
36+
update_task_instances_state = UpdateTaskInstancesState(
37+
dry_run=True,
38+
execution_date=execution_date,
39+
include_downstream=include_downstream,
40+
include_future=include_future,
41+
include_past=include_past,
42+
include_upstream=include_upstream,
43+
new_state="success",
44+
task_id="task1",
45+
) # UpdateTaskInstancesState | Parameters of action
46+
47+
# Set a state of task instances
48+
api_response = dag_api_setup.post_set_task_instances_state(
49+
dag_id, update_task_instances_state
50+
)
51+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

0 commit comments

Comments
 (0)