jason810496 commented on code in PR #48524:
URL: https://github.com/apache/airflow/pull/48524#discussion_r2019797358
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -882,55 +883,72 @@ def test_invalid_state(self, test_client, post_body,
expected_response):
class TestPatchDagRun:
@pytest.mark.parametrize(
- "dag_id, run_id, patch_body, response_body",
+ "dag_id, run_id, patch_body, response_body, note_data",
[
(
DAG1_ID,
DAG1_RUN1_ID,
{"state": DagRunState.FAILED, "note": "new_note2"},
{"state": DagRunState.FAILED, "note": "new_note2"},
+ {"user_id": "test", "content": "new_note2"},
),
(
DAG1_ID,
DAG1_RUN2_ID,
{"state": DagRunState.SUCCESS},
{"state": DagRunState.SUCCESS, "note": None},
+ None,
),
(
DAG2_ID,
DAG2_RUN1_ID,
{"state": DagRunState.QUEUED},
{"state": DagRunState.QUEUED, "note": None},
+ None,
),
(
DAG1_ID,
DAG1_RUN1_ID,
{"note": "updated note"},
{"state": DagRunState.SUCCESS, "note": "updated note"},
+ {"user_id": "test", "content": "updated note"},
),
(
DAG1_ID,
DAG1_RUN2_ID,
{"note": "new note", "state": DagRunState.FAILED},
{"state": DagRunState.FAILED, "note": "new note"},
+ {"user_id": "test", "content": "new note"},
),
(
DAG1_ID,
DAG1_RUN2_ID,
{"note": None},
{"state": DagRunState.FAILED, "note": None},
+ {"user_id": "test", "content": None},
),
],
)
@pytest.mark.usefixtures("configure_git_connection_for_dag_bundle")
- def test_patch_dag_run(self, test_client, dag_id, run_id, patch_body,
response_body, session):
+ def test_patch_dag_run(self, test_client, dag_id, run_id, patch_body,
response_body, note_data, session):
response = test_client.patch(f"/dags/{dag_id}/dagRuns/{run_id}",
json=patch_body)
assert response.status_code == 200
body = response.json()
assert body["dag_id"] == dag_id
assert body["dag_run_id"] == run_id
assert body.get("state") == response_body.get("state")
assert body.get("note") == response_body.get("note")
+ dr_note = (
+ session.query(DagRunNote)
+ .join(DagRun, DagRunNote.dag_run_id == DagRun.id)
+ .filter(DagRun.run_id == run_id)
+ .one_or_none()
+ )
+ if note_data is None:
+ assert dr_note is None
+ else:
+ assert dr_note.user_id == note_data.get("user_id")
+ assert dr_note.content == note_data.get("content")
Review Comment:
Nit: The assert part could also modularize.
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -882,55 +883,72 @@ def test_invalid_state(self, test_client, post_body,
expected_response):
class TestPatchDagRun:
@pytest.mark.parametrize(
- "dag_id, run_id, patch_body, response_body",
+ "dag_id, run_id, patch_body, response_body, note_data",
[
(
DAG1_ID,
DAG1_RUN1_ID,
{"state": DagRunState.FAILED, "note": "new_note2"},
{"state": DagRunState.FAILED, "note": "new_note2"},
+ {"user_id": "test", "content": "new_note2"},
),
(
DAG1_ID,
DAG1_RUN2_ID,
{"state": DagRunState.SUCCESS},
{"state": DagRunState.SUCCESS, "note": None},
+ None,
),
(
DAG2_ID,
DAG2_RUN1_ID,
{"state": DagRunState.QUEUED},
{"state": DagRunState.QUEUED, "note": None},
+ None,
),
(
DAG1_ID,
DAG1_RUN1_ID,
{"note": "updated note"},
{"state": DagRunState.SUCCESS, "note": "updated note"},
+ {"user_id": "test", "content": "updated note"},
),
(
DAG1_ID,
DAG1_RUN2_ID,
{"note": "new note", "state": DagRunState.FAILED},
{"state": DagRunState.FAILED, "note": "new note"},
+ {"user_id": "test", "content": "new note"},
),
(
DAG1_ID,
DAG1_RUN2_ID,
{"note": None},
{"state": DagRunState.FAILED, "note": None},
+ {"user_id": "test", "content": None},
),
],
)
@pytest.mark.usefixtures("configure_git_connection_for_dag_bundle")
- def test_patch_dag_run(self, test_client, dag_id, run_id, patch_body,
response_body, session):
+ def test_patch_dag_run(self, test_client, dag_id, run_id, patch_body,
response_body, note_data, session):
response = test_client.patch(f"/dags/{dag_id}/dagRuns/{run_id}",
json=patch_body)
assert response.status_code == 200
body = response.json()
assert body["dag_id"] == dag_id
assert body["dag_run_id"] == run_id
assert body.get("state") == response_body.get("state")
assert body.get("note") == response_body.get("note")
+ dr_note = (
+ session.query(DagRunNote)
+ .join(DagRun, DagRunNote.dag_run_id == DagRun.id)
+ .filter(DagRun.run_id == run_id)
+ .one_or_none()
+ )
Review Comment:
Nit: How about refactor as `get_dr_note` method as common utils ?
--
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]