Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions task_sdk/src/airflow/sdk/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def noop_handler(request: httpx.Request) -> httpx.Response:
"logical_date": "2021-01-01T00:00:00Z",
"start_date": "2021-01-01T00:00:00Z",
"run_type": DagRunType.MANUAL,
"run_after": "2021-01-01T00:00:00Z",
},
"max_tries": 0,
},
Expand Down
33 changes: 33 additions & 0 deletions task_sdk/tests/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def make_client(transport: httpx.MockTransport) -> Client:
return Client(base_url="test://server", token="", transport=transport)


def make_client_w_dry_run() -> Client:
"""Get a client with dry_run enabled"""
return Client(base_url=None, dry_run=True, token="")


def make_client_w_responses(responses: list[httpx.Response]) -> Client:
"""Helper fixture to create a mock client with custom responses."""

Expand All @@ -49,6 +54,34 @@ def handle_request(request: httpx.Request) -> httpx.Response:


class TestClient:
@pytest.mark.parametrize(
["path", "json_response"],
[
(
"/task-instances/1/run",
{
"dag_run": {
"dag_id": "test_dag",
"run_id": "test_run",
"logical_date": "2021-01-01T00:00:00Z",
"start_date": "2021-01-01T00:00:00Z",
"run_type": "manual",
"run_after": "2021-01-01T00:00:00Z",
},
"max_tries": 0,
},
),
],
)
def test_dry_run(self, path, json_response):
client = make_client_w_dry_run()
assert client.base_url == "dry-run://server"

resp = client.get(path)

assert resp.status_code == 200
assert resp.json() == json_response

def test_error_parsing(self):
responses = [
httpx.Response(422, json={"detail": [{"loc": ["#0"], "msg": "err", "type": "required"}]})
Expand Down