amoghrajesh commented on code in PR #43874:
URL: https://github.com/apache/airflow/pull/43874#discussion_r1843910885


##########
tests/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -254,3 +257,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"),
+                            "data_interval_start": 
dr.data_interval_start.isoformat().replace("+00:00", "Z"),
+                            "end_date": None,
+                            "logical_date": 
dr.logical_date.isoformat().replace("+00:00", "Z"),
+                            "start_date": 
dr.start_date.isoformat().replace("+00:00", "Z"),
+                            "state": "running",
+                        }
+                    ],
+                }
+            ],
+            "total_entries": 1,
+        }
+        assert response.json() == expected_response
+
+    def test_should_respond_404(self, test_client):
+        response = test_client.get(
+            "public/dags/invalid-id/dagRuns/invalid-id/upstreamAssetEvents",

Review Comment:
   Got it, let me change that



-- 
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]

Reply via email to