pierrejeambrun commented on code in PR #43875:
URL: https://github.com/apache/airflow/pull/43875#discussion_r1853765747
##########
tests/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -652,3 +657,72 @@ def test_clear_dag_run_unprocessable_entity(self,
test_client):
body = response.json()
assert body["detail"][0]["msg"] == "Field required"
assert body["detail"][0]["loc"][0] == "body"
+
+
+# @pytest.mark.no_setup
+class TestTriggerDagRun:
+ @time_machine.travel(timezone.utcnow(), tick=False)
+ @pytest.mark.parametrize(
+ "dag_run_id, logical_date, note, data_interval_start,
data_interval_end",
+ [
+ ("dag_run_5", LOGICAL_DATE1, "test_note", LOGICAL_DATE1,
LOGICAL_DATE2 + timedelta(days=1)),
+ ],
+ )
+ def test_should_respond_200(
+ self,
+ test_client,
+ session,
+ dag_run_id,
+ logical_date,
+ note,
+ data_interval_start,
+ data_interval_end,
+ ):
+ response = test_client.post(
+ f"/public/dags/{DAG1_ID}/dagRuns",
+ json={
+ "dag_run_id": dag_run_id,
+ "logical_date": logical_date.isoformat(),
+ "note": note,
+ "data_interval_start": data_interval_start.isoformat(),
+ "data_interval_end": data_interval_end.isoformat(),
+ },
+ )
+
+ assert response.status_code == 200
+ now = timezone.utcnow().isoformat().replace("+00:00", "Z")
+ if logical_date is None:
+ logical_date = now
+ else:
+ logical_date = logical_date.isoformat().replace("+00:00", "Z")
+
+ if dag_run_id is None:
+ dag_run_id = f"manual__{logical_date}"
+
+ if data_interval_end is None and data_interval_start is None:
+ data_interval_end = now
+ data_interval_start = now
+ else:
+ data_interval_end =
data_interval_end.isoformat().replace("+00:00", "Z")
+ data_interval_start =
data_interval_start.isoformat().replace("+00:00", "Z")
+
+ expected_response_json = {
+ "conf": {},
+ "dag_id": DAG1_ID,
+ "run_id": dag_run_id,
+ "end_date": None,
+ "logical_date": logical_date,
+ "external_trigger": True,
+ "start_date": None,
+ "state": "queued",
+ "data_interval_end": data_interval_end,
+ "data_interval_start": data_interval_start,
+ "queued_at": now,
+ "last_scheduling_decision": None,
+ "run_type": "manual",
+ "note": note,
+ "triggered_by": "rest_api",
+ }
+
+ assert response.json() == expected_response_json
+ # _check_last_log(session, dag_id=DAG1_ID, event="api.post_dag_run",
logical_date=None)
Review Comment:
The `_check_last_log` cannot be yet tested because we are not yet logging
user actions on the API.
There is a ticket open for that:
https://github.com/apache/airflow/issues/44057
Only when this is implemented, we can add back all the `_check_last_log` in
the FastAPI API.
For I suggest to just remove it and ignore these checks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]