pierrejeambrun commented on code in PR #43874:
URL: https://github.com/apache/airflow/pull/43874#discussion_r1842333308
##########
tests/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -254,3 +256,75 @@ def test_delete_dag_run_not_found(self, test_client):
assert response.status_code == 404
body = response.json()
assert body["detail"] == "The DagRun with dag_id: `test_dag1` and
run_id: `invalid` was not found"
+
+
+class TestGetDagRunAssetTriggerEvents:
+ def test_should_respond_200(self, test_client, dag_maker, session):
+ asset1 = Asset(uri="ds1")
+
+ with dag_maker(dag_id="source_dag", start_date=START_DATE,
session=session):
+ EmptyOperator(task_id="task", outlets=[asset1])
+ dr = dag_maker.create_dagrun()
+ ti = dr.task_instances[0]
+
+ asset1_id =
session.query(AssetModel.id).filter_by(uri=asset1.uri).scalar()
+ event = AssetEvent(
+ asset_id=asset1_id,
+ source_task_id=ti.task_id,
+ source_dag_id=ti.dag_id,
+ source_run_id=ti.run_id,
+ source_map_index=ti.map_index,
+ )
+ session.add(event)
+
+ with dag_maker(dag_id="TEST_DAG_ID", start_date=START_DATE,
session=session):
+ pass
+ dr = dag_maker.create_dagrun(run_id="TEST_DAG_RUN_ID",
run_type=DagRunType.ASSET_TRIGGERED)
+ dr.consumed_asset_events.append(event)
+
+ session.commit()
+ assert event.timestamp
+
+ response = test_client.get(
+
"/public/dags/TEST_DAG_ID/dagRuns/TEST_DAG_RUN_ID/upstreamAssetEvents",
+ )
+ assert response.status_code == 200
+ expected_response = {
+ "asset_events": [
+ {
+ "timestamp": event.timestamp.isoformat().replace("+00:00",
"Z"),
+ "asset_id": asset1_id,
+ "uri": asset1.uri,
+ "extra": {},
+ "id": event.id,
+ "source_dag_id": ti.dag_id,
+ "source_map_index": ti.map_index,
+ "source_run_id": ti.run_id,
+ "source_task_id": ti.task_id,
+ "created_dagruns": [
+ {
+ "dag_id": "TEST_DAG_ID",
+ "run_id": "TEST_DAG_RUN_ID",
+ "data_interval_end":
dr.data_interval_end.isoformat().replace("+00:00", "Z"),
Review Comment:
We need a date formatter instead of having to use `replace` all over the
test code. That is not specific to this particular PR, a few of them are also
doing that.
In a follow up PR, we can instead use something like
`dr.data_interval_end.strftime(ZULU_STR_FORMAT)`, and format could look like
`'%Y-%m-%d %H:%M:%S %Z'`
But in a follow up.
--
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]