pierrejeambrun commented on code in PR #43881:
URL: https://github.com/apache/airflow/pull/43881#discussion_r1840730250


##########
airflow/api_fastapi/core_api/datamodels/assets.py:
##########
@@ -64,3 +64,45 @@ class AssetCollectionResponse(BaseModel):
 
     assets: list[AssetResponse]
     total_entries: int
+
+
+class DagRunAssetReference(BaseModel):
+    """Serializable version of the DagRunAssetReference ORM SqlAlchemyModel."""

Review Comment:
   ```suggestion
       """DAGRun serializer for asset responses."""
   ```
   
   (We need to remove the ORM Sqlalchemy reference. This does not only 
serialize SQLAlchemy objects)



##########
tests/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -229,3 +303,94 @@ def test_should_respect_page_size_limit_default(self, 
test_client):
 
         assert response.status_code == 200
         assert len(response.json()["assets"]) == 100
+
+
+class TestGetAssetEvents(TestAssets):
+    def test_should_respond_200(self, test_client, session):
+        self.create_assets()
+        self.create_assets_events()
+        self.create_dag_run()
+        self.create_asset_dag_run()
+        assets = session.query(AssetEvent).all()
+        assert len(assets) == 2
+        response = test_client.get("/public/assets/events")
+        assert response.status_code == 200
+        response_data = response.json()
+        assert response_data == {
+            "asset_events": [
+                {
+                    "id": 1,
+                    "asset_id": 1,
+                    "asset_uri": "s3://bucket/key/1",
+                    "extra": {"foo": "bar"},
+                    "source_task_id": "source_task_id",
+                    "source_dag_id": "source_dag_id",
+                    "source_run_id": "source_run_id_1",
+                    "source_map_index": -1,
+                    "created_dagruns": [
+                        {
+                            "run_id": "source_run_id_1",
+                            "dag_id": "source_dag_id",
+                            "logical_date": "2020-06-11T18:00:00Z",
+                            "start_date": "2020-06-11T18:00:00Z",
+                            "end_date": "2020-06-11T18:00:00Z",
+                            "state": "success",
+                            "data_interval_start": "2020-06-11T18:00:00Z",
+                            "data_interval_end": "2020-06-11T18:00:00Z",
+                        }
+                    ],
+                    "timestamp": "2020-06-11T18:00:00Z",
+                },
+                {
+                    "id": 2,
+                    "asset_id": 2,
+                    "asset_uri": "s3://bucket/key/2",
+                    "extra": {"foo": "bar"},
+                    "source_task_id": "source_task_id",
+                    "source_dag_id": "source_dag_id",
+                    "source_run_id": "source_run_id_2",
+                    "source_map_index": -1,
+                    "created_dagruns": [
+                        {
+                            "run_id": "source_run_id_2",
+                            "dag_id": "source_dag_id",
+                            "logical_date": "2020-06-11T18:00:00Z",
+                            "start_date": "2020-06-11T18:00:00Z",
+                            "end_date": "2020-06-11T18:00:00Z",
+                            "state": "success",
+                            "data_interval_start": "2020-06-11T18:00:00Z",
+                            "data_interval_end": "2020-06-11T18:00:00Z",
+                        }
+                    ],
+                    "timestamp": "2020-06-11T18:00:00Z",
+                },
+            ],
+            "total_entries": 2,
+        }
+
+    @pytest.mark.parametrize(
+        "filter_type, filter_value, total_entries",
+        [
+            ("asset_id", "2", 1),
+            ("source_dag_id", "source_dag_id", 2),
+            ("source_task_id", "source_task_id", 2),
+            ("source_run_id", "source_run_id_1", 1),
+            ("source_map_index", "-1", 2),
+        ],
+    )
+    @provide_session
+    def test_filtering(self, test_client, filter_type, filter_value, 
total_entries, session):
+        self.create_assets()
+        self.create_assets_events()
+        self.create_dag_run()
+        self.create_asset_dag_run()
+        response = 
test_client.get(f"/public/assets/events?{filter_type}={filter_value}")

Review Comment:
   Don't format the URL manually, use `params={}` with a dict of paramater and 
leave that to the test_client. (Some values need encoding, etc...)



##########
tests/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -229,3 +303,94 @@ def test_should_respect_page_size_limit_default(self, 
test_client):
 
         assert response.status_code == 200
         assert len(response.json()["assets"]) == 100
+
+
+class TestGetAssetEvents(TestAssets):
+    def test_should_respond_200(self, test_client, session):
+        self.create_assets()
+        self.create_assets_events()
+        self.create_dag_run()
+        self.create_asset_dag_run()
+        assets = session.query(AssetEvent).all()
+        assert len(assets) == 2
+        response = test_client.get("/public/assets/events")
+        assert response.status_code == 200
+        response_data = response.json()
+        assert response_data == {
+            "asset_events": [
+                {
+                    "id": 1,
+                    "asset_id": 1,
+                    "asset_uri": "s3://bucket/key/1",
+                    "extra": {"foo": "bar"},
+                    "source_task_id": "source_task_id",
+                    "source_dag_id": "source_dag_id",
+                    "source_run_id": "source_run_id_1",
+                    "source_map_index": -1,
+                    "created_dagruns": [
+                        {
+                            "run_id": "source_run_id_1",
+                            "dag_id": "source_dag_id",
+                            "logical_date": "2020-06-11T18:00:00Z",
+                            "start_date": "2020-06-11T18:00:00Z",
+                            "end_date": "2020-06-11T18:00:00Z",
+                            "state": "success",
+                            "data_interval_start": "2020-06-11T18:00:00Z",
+                            "data_interval_end": "2020-06-11T18:00:00Z",
+                        }
+                    ],
+                    "timestamp": "2020-06-11T18:00:00Z",
+                },
+                {
+                    "id": 2,
+                    "asset_id": 2,
+                    "asset_uri": "s3://bucket/key/2",
+                    "extra": {"foo": "bar"},
+                    "source_task_id": "source_task_id",
+                    "source_dag_id": "source_dag_id",
+                    "source_run_id": "source_run_id_2",
+                    "source_map_index": -1,
+                    "created_dagruns": [
+                        {
+                            "run_id": "source_run_id_2",
+                            "dag_id": "source_dag_id",
+                            "logical_date": "2020-06-11T18:00:00Z",
+                            "start_date": "2020-06-11T18:00:00Z",
+                            "end_date": "2020-06-11T18:00:00Z",
+                            "state": "success",
+                            "data_interval_start": "2020-06-11T18:00:00Z",
+                            "data_interval_end": "2020-06-11T18:00:00Z",
+                        }
+                    ],
+                    "timestamp": "2020-06-11T18:00:00Z",
+                },
+            ],
+            "total_entries": 2,
+        }
+
+    @pytest.mark.parametrize(
+        "filter_type, filter_value, total_entries",
+        [
+            ("asset_id", "2", 1),
+            ("source_dag_id", "source_dag_id", 2),
+            ("source_task_id", "source_task_id", 2),
+            ("source_run_id", "source_run_id_1", 1),
+            ("source_map_index", "-1", 2),
+        ],
+    )
+    @provide_session
+    def test_filtering(self, test_client, filter_type, filter_value, 
total_entries, session):

Review Comment:
   `test_parameters` and you can also assert `offset` and `limit` as well



##########
tests/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -229,3 +303,94 @@ def test_should_respect_page_size_limit_default(self, 
test_client):
 
         assert response.status_code == 200
         assert len(response.json()["assets"]) == 100
+
+
+class TestGetAssetEvents(TestAssets):
+    def test_should_respond_200(self, test_client, session):
+        self.create_assets()
+        self.create_assets_events()
+        self.create_dag_run()
+        self.create_asset_dag_run()
+        assets = session.query(AssetEvent).all()
+        assert len(assets) == 2
+        response = test_client.get("/public/assets/events")
+        assert response.status_code == 200
+        response_data = response.json()
+        assert response_data == {
+            "asset_events": [
+                {
+                    "id": 1,
+                    "asset_id": 1,
+                    "asset_uri": "s3://bucket/key/1",
+                    "extra": {"foo": "bar"},
+                    "source_task_id": "source_task_id",
+                    "source_dag_id": "source_dag_id",
+                    "source_run_id": "source_run_id_1",
+                    "source_map_index": -1,
+                    "created_dagruns": [
+                        {
+                            "run_id": "source_run_id_1",
+                            "dag_id": "source_dag_id",
+                            "logical_date": "2020-06-11T18:00:00Z",
+                            "start_date": "2020-06-11T18:00:00Z",
+                            "end_date": "2020-06-11T18:00:00Z",
+                            "state": "success",
+                            "data_interval_start": "2020-06-11T18:00:00Z",
+                            "data_interval_end": "2020-06-11T18:00:00Z",
+                        }
+                    ],
+                    "timestamp": "2020-06-11T18:00:00Z",
+                },
+                {
+                    "id": 2,
+                    "asset_id": 2,
+                    "asset_uri": "s3://bucket/key/2",
+                    "extra": {"foo": "bar"},
+                    "source_task_id": "source_task_id",
+                    "source_dag_id": "source_dag_id",
+                    "source_run_id": "source_run_id_2",
+                    "source_map_index": -1,
+                    "created_dagruns": [
+                        {
+                            "run_id": "source_run_id_2",
+                            "dag_id": "source_dag_id",
+                            "logical_date": "2020-06-11T18:00:00Z",
+                            "start_date": "2020-06-11T18:00:00Z",
+                            "end_date": "2020-06-11T18:00:00Z",
+                            "state": "success",
+                            "data_interval_start": "2020-06-11T18:00:00Z",
+                            "data_interval_end": "2020-06-11T18:00:00Z",
+                        }
+                    ],
+                    "timestamp": "2020-06-11T18:00:00Z",
+                },
+            ],
+            "total_entries": 2,
+        }
+
+    @pytest.mark.parametrize(
+        "filter_type, filter_value, total_entries",
+        [
+            ("asset_id", "2", 1),
+            ("source_dag_id", "source_dag_id", 2),
+            ("source_task_id", "source_task_id", 2),
+            ("source_run_id", "source_run_id_1", 1),
+            ("source_map_index", "-1", 2),
+        ],
+    )

Review Comment:
   ```suggestion
           "params, total_entries",
           [
               ({"asset_id": "2"}, 1),
               ...
   
           ],
       )
   ```



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