Skip to content

Commit 2d52f86

Browse files
committed
re-org tests
1 parent 002c6c5 commit 2d52f86

18 files changed

+605
-1
lines changed

test/integration/conftest.py

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

99
from airflow_python_sdk.api.dag_api import DAGApi # noqa: E501
10+
from airflow_python_sdk.api.dag_run_api import DAGRunApi # noqa: E501
1011
from airflow_python_sdk.api.config_api import ConfigApi # noqa: E501
1112
from airflow_python_sdk.api.monitoring_api import MonitoringApi # noqa: E501
1213
from airflow_python_sdk.api.connection_api import ConnectionApi # noqa: E501
14+
from airflow_python_sdk.api.event_log_api import EventLogApi
15+
from airflow_python_sdk.api.import_error_api import ImportErrorApi
16+
from airflow_python_sdk.api.pool_api import PoolApi
17+
from airflow_python_sdk.api.task_instance_api import TaskInstanceApi
18+
from airflow_python_sdk.api.variable_api import VariableApi
19+
from airflow_python_sdk.api.x_com_api import XComApi
1320
from airflow_python_sdk import Configuration, ApiClient
1421

1522
if "API_HOST" not in os.environ or \
@@ -52,6 +59,11 @@ def dag_api_setup():
5259
"""Instantiate api"""
5360
return DAGApi(API_CLIENT) # noqa: E501
5461

62+
@pytest.fixture
63+
def dag_run_api_setup():
64+
"""Instantiate api"""
65+
return DAGRunApi(API_CLIENT) # noqa: E501
66+
5567
@pytest.fixture
5668
def monitoring_api_setup():
5769
"""Instantiate api"""
@@ -61,3 +73,33 @@ def monitoring_api_setup():
6173
def connection_api_setup():
6274
"""Instantiate api"""
6375
return ConnectionApi(API_CLIENT) # noqa: E501
76+
77+
@pytest.fixture
78+
def event_log_api_setup():
79+
"""Instantiate api"""
80+
return EventLogApi(API_CLIENT) # noqa: E501
81+
82+
@pytest.fixture
83+
def import_error_api_setup():
84+
"""Instantiate api"""
85+
return ImportErrorApi(API_CLIENT) # noqa: E501
86+
87+
@pytest.fixture
88+
def pool_api_setup():
89+
"""Instantiate api"""
90+
return PoolApi(API_CLIENT) # noqa: E501
91+
92+
@pytest.fixture
93+
def task_instance_api_setup():
94+
"""Instantiate api"""
95+
return TaskInstanceApi(API_CLIENT) # noqa: E501
96+
97+
@pytest.fixture
98+
def variable_api_setup():
99+
"""Instantiate api"""
100+
return VariableApi(API_CLIENT) # noqa: E501
101+
102+
@pytest.fixture
103+
def xcom_api_setup():
104+
"""Instantiate api"""
105+
return XComApi(API_CLIENT) # noqa: E501

test/integration/test_get_dag_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(["test_glue_partitions_sensor"], None),
2929
],
3030
)
31-
def test_get_dag(dag_api_setup, test_input, expected):
31+
def test_get_dag_details(dag_api_setup, test_input, expected):
3232
"""Test the /dags/{dag_id} API EP"""
3333
dag_id, = test_input
3434
api_response = dag_api_setup.get_dag_details(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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_runs(dag_run_api_setup):
17+
"""Test the /dags/{dag_id}/dagRuns API EP"""
18+
api_response = dag_run_api_setup.get_dag_runs(
19+
dag_id="test_glue_partitions_sensor",
20+
)
21+
logging.getLogger().info("%s", api_response)
22+
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+
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_event_logs(event_log_api_setup):
17+
"""Test the /eventLogs API EP"""
18+
api_response = event_log_api_setup.get_event_logs(limit=100, offset=0)
19+
logging.getLogger().info("%s", api_response)
20+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
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+
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_import_errors(import_error_api_setup):
17+
"""Test the /eventLogs API EP"""
18+
api_response = import_error_api_setup.get_import_errors(
19+
limit=100,
20+
offset=0,
21+
)
22+
logging.getLogger().info("%s", api_response)
23+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")

test/integration/test_get_pools.py

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+
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_pools(pool_api_setup):
17+
"""Test the /pools API EP"""
18+
api_response = pool_api_setup.get_pools(
19+
limit=100,
20+
offset=0,
21+
)
22+
logging.getLogger().info("%s", api_response)
23+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
from test.integration.conftest import BCOLORS
12+
13+
import logging
14+
from dateutil.parser import parse
15+
16+
from airflow_python_sdk.model.list_task_instance_form import ListTaskInstanceForm
17+
18+
19+
def test_get_task_instances(task_instance_api_setup):
20+
"""Test the /dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances API EP"""
21+
api_response = task_instance_api_setup.get_task_instances(
22+
dag_id="test_glue_partitions_sensor",
23+
dag_run_id="scheduled__2020-04-13T00:00:00+00:00",
24+
)
25+
logging.getLogger().info("%s", api_response)
26+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
27+
28+
29+
def test_get_task_instances_batch(task_instance_api_setup):
30+
"""Test the /dags/~/dagRuns/~/taskInstances/list API EP"""
31+
list_task_instance_form = ListTaskInstanceForm(
32+
dag_ids=[
33+
"test_glue_partitions_sensor",
34+
],
35+
# ====================================================
36+
# Uncomment the following to add to the filter
37+
# ====================================================
38+
# execution_date_gte=parse('1970-01-01T00:00:00.00Z'),
39+
# execution_date_lte=parse('1970-01-01T00:00:00.00Z'),
40+
# start_date_gte=parse('1970-01-01T00:00:00.00Z'),
41+
# start_date_lte=parse('1970-01-01T00:00:00.00Z'),
42+
# end_date_gte=parse('1970-01-01T00:00:00.00Z'),
43+
# end_date_lte=parse('1970-01-01T00:00:00.00Z'),
44+
# duration_gte=3.14,
45+
# duration_lte=3.14,
46+
# state=[
47+
# "state_example",
48+
# ],
49+
# ====================================================
50+
pool=[
51+
"default_pool",
52+
],
53+
# queue=[
54+
# "queue_example",
55+
# ],
56+
) # ListTaskInstanceForm |
57+
api_response = task_instance_api_setup.get_task_instances_batch(
58+
list_task_instance_form
59+
)
60+
logging.getLogger().info("%s", api_response)
61+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
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+
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_variables(variable_api_setup):
17+
"""Test the /variables API EP"""
18+
api_response = variable_api_setup.get_variables(
19+
limit=100,
20+
offset=0,
21+
)
22+
logging.getLogger().info("%s", api_response)
23+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
import pytest
16+
17+
18+
@pytest.mark.parametrize(
19+
"test_input, expected",
20+
[
21+
(
22+
[
23+
"test_glue_partitions_sensor",
24+
"scheduled__2020-04-13T00:00:00+00:00",
25+
"task1",
26+
],
27+
None,
28+
),
29+
(
30+
[
31+
"test_glue_python_shell",
32+
"scheduled__2020-05-30T00:00:00+00:00",
33+
"python_task",
34+
],
35+
None
36+
),
37+
],
38+
)
39+
def test_get_xcom_entries(xcom_api_setup, test_input, expected):
40+
"""Test the /variables API EP"""
41+
dag_id, dag_run_id, task_id = test_input
42+
api_response = xcom_api_setup.get_xcom_entries(
43+
dag_id=dag_id,
44+
dag_run_id=dag_run_id,
45+
task_id=task_id,
46+
)
47+
logging.getLogger().info("%s", api_response)
48+
print(f"{BCOLORS.OKGREEN}OK{BCOLORS.ENDC}")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Airflow API (Stable)
3+
4+
# Overview To facilitate management, Apache Airflow supports a range of REST API endpoints across its objects. This section provides an overview of the API design, methods, and supported use cases. Most of the endpoints accept `JSON` as input and return `JSON` responses. This means that you must usually add the following headers to your request: ``` Content-type: application/json Accept: application/json ``` ## Resources The term `resource` refers to a single type of object in the Airflow metadata. An API is broken up by its endpoint's corresponding resource. The name of a resource is typically plural and expressed in camelCase. Example: `dagRuns`. Resource names are used as part of endpoint URLs, as well as in API parameters and responses. ## CRUD Operations The platform supports **C**reate, **R**ead, **U**pdate, and **D**elete operations on most resources. You can review the standards for these operations and their standard parameters below. Some endpoints have special behavior as exceptions. ### Create To create a resource, you typically submit an HTTP `POST` request with the resource's required metadata in the request body. The response returns a `201 Created` response code upon success with the resource's metadata, including its internal `id`, in the response body. ### Read The HTTP `GET` request can be used to read a resource or to list a number of resources. A resource's `id` can be submitted in the request parameters to read a specific resource. The response usually returns a `200 OK` response code upon success, with the resource's metadata in the response body. If a `GET` request does not include a specific resource `id`, it is treated as a list request. The response usually returns a `200 OK` response code upon success, with an object containing a list of resources' metadata in the response body. When reading resources, some common query parameters are usually available. e.g.: ``` v1/connections?limit=25&offset=25 ``` |Query Parameter|Type|Description| |---------------|----|-----------| |limit|integer|Maximum number of objects to fetch. Usually 25 by default| |offset|integer|Offset after which to start returning objects. For use with limit query parameter.| ### Update Updating a resource requires the resource `id`, and is typically done using an HTTP `PATCH` request, with the fields to modify in the request body. The response usually returns a `200 OK` response code upon success, with information about the modified resource in the response body. ### Delete Deleting a resource requires the resource `id` and is typically executing via an HTTP `DELETE` request. The response usually returns a `204 No Content` response code upon success. ## Conventions - Resource names are plural and expressed in camelCase. - Names are consistent between URL parameter name and field name. - Field names are in snake_case. ```json { \"name\": \"string\", \"slots\": 0, \"occupied_slots\": 0, \"used_slots\": 0, \"queued_slots\": 0, \"open_slots\": 0 } ``` ### Update Mask Update mask is available as a query parameter in patch endpoints. It is used to notify the API which fields you want to update. Using `update_mask` makes it easier to update objects by helping the server know which fields to update in an object instead of updating all fields. The update request ignores any fields that aren't specified in the field mask, leaving them with their current values. Example: ``` resource = request.get('/resource/my-id').json() resource['my_field'] = 'new-value' request.patch('/resource/my-id?update_mask=my_field', data=json.dumps(resource)) ``` ## Versioning and Endpoint Lifecycle - API versioning is not synchronized to specific releases of the Apache Airflow. - APIs are designed to be backward compatible. - Any changes to the API will first go through a deprecation phase. # Summary of Changes | Airflow version | Description | |-|-| | v2.0 | Initial release | # Trying the API You can use a third party client, such as [curl](https://curl.haxx.se/), [HTTPie](https://httpie.org/), [Postman](https://www.postman.com/) or [the Insomnia rest client](https://insomnia.rest/) to test the Apache Airflow API. Note that you will need to pass credentials data. For e.g., here is how to pause a DAG with [curl](https://curl.haxx.se/), when basic authorization is used: ```bash curl -X POST 'https://example.com/api/v1/dags/{dag_id}?update_mask=is_paused' \\ -H 'Content-Type: application/json' \\ --user \"username:password\" \\ -d '{ \"is_paused\": true }' ``` Using a graphical tool such as [Postman](https://www.postman.com/) or [Insomnia](https://insomnia.rest/), it is possible to import the API specifications directly: 1. Download the API specification by clicking the **Download** button at top of this document 2. Import the JSON specification in the graphical tool of your choice. - In *Postman*, you can click the **import** button at the top - With *Insomnia*, you can just drag-and-drop the file on the UI Note that with *Postman*, you can also generate code snippets by selecting a request and clicking on the **Code** button. # Authentication To be able to meet the requirements of many organizations, Airflow supports many authentication methods, and it is even possible to add your own method. If you want to check which auth backend is currently set, you can use `airflow config get-value api auth_backend` command as in the example below. ```bash $ airflow config get-value api auth_backend airflow.api.auth.backend.basic_auth ``` The default is to deny all requests. For details on configuring the authentication, see [API Authorization](https://airflow.apache.org/docs/apache-airflow/stable/security/api.html). # Errors We follow the error response format proposed in [RFC 7807](https://tools.ietf.org/html/rfc7807) also known as Problem Details for HTTP APIs. As with our normal API responses, your client must be prepared to gracefully handle additional members of the response. ## Unauthenticated This indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. Please check that you have valid credentials. ## PermissionDenied This response means that the server understood the request but refuses to authorize it because it lacks sufficient rights to the resource. It happens when you do not have the necessary permission to execute the action you performed. You need to get the appropriate permissions in other to resolve this error. ## BadRequest This response means that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). To resolve this, please ensure that your syntax is correct. ## NotFound This client error response indicates that the server cannot find the requested resource. ## MethodNotAllowed Indicates that the request method is known by the server but is not supported by the target resource. ## NotAcceptable The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation. ## AlreadyExists The request could not be completed due to a conflict with the current state of the target resource, meaning that the resource already exists ## Unknown This means that the server encountered an unexpected condition that prevented it from fulfilling the request. # noqa: E501
5+
6+
The version of the OpenAPI document: 1.0.0
7+
8+
Generated by: https://openapi-generator.tech
9+
"""
10+
11+
12+
import sys
13+
import unittest
14+
15+
import airflow_python_sdk
16+
from airflow_python_sdk.model.connection_collection_item import ConnectionCollectionItem
17+
globals()['ConnectionCollectionItem'] = ConnectionCollectionItem
18+
from airflow_python_sdk.model.connection_collection_all_of import ConnectionCollectionAllOf
19+
20+
21+
class TestConnectionCollectionAllOf(unittest.TestCase):
22+
"""ConnectionCollectionAllOf unit test stubs"""
23+
24+
def setUp(self):
25+
pass
26+
27+
def tearDown(self):
28+
pass
29+
30+
def testConnectionCollectionAllOf(self):
31+
"""Test ConnectionCollectionAllOf"""
32+
# FIXME: construct object with mandatory attributes with example values
33+
# model = ConnectionCollectionAllOf() # noqa: E501
34+
pass
35+
36+
37+
if __name__ == '__main__':
38+
unittest.main()

0 commit comments

Comments
 (0)