vatsrahul1001 commented on code in PR #43881:
URL: https://github.com/apache/airflow/pull/43881#discussion_r1840920332
##########
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:
added `test_limit_and_offset` test
##########
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:
Done
##########
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:
Done
--
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]